Skip to content

Commit

Permalink
feat(ct): DeployDelayedWETH script (#12662)
Browse files Browse the repository at this point in the history
* feat(ct): DeployDelayedWETH script

Adds a new deployment script for deploying a new DelayedWETH
proxy contract.

* fix tests

* lint

* delete letter o

* move testdata

---------

Co-authored-by: Matthew Slipper <me@matthewslipper.com>
  • Loading branch information
smartcontracts and mslipper authored Oct 31, 2024
1 parent 1f335f1 commit 2c5f6ed
Show file tree
Hide file tree
Showing 21 changed files with 708 additions and 98 deletions.
10 changes: 7 additions & 3 deletions op-deployer/pkg/deployer/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"math/big"
"strings"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"

"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -146,7 +150,7 @@ func Apply(ctx context.Context, cfg ApplyConfig) error {
cfg.Logger.Info("artifacts download progress", "current", curr, "total", total)
}

l1ArtifactsFS, cleanupL1, err := pipeline.DownloadArtifacts(ctx, intent.L1ContractsLocator, progressor)
l1ArtifactsFS, cleanupL1, err := artifacts.Download(ctx, intent.L1ContractsLocator, progressor)
if err != nil {
return fmt.Errorf("failed to download L1 artifacts: %w", err)
}
Expand All @@ -156,7 +160,7 @@ func Apply(ctx context.Context, cfg ApplyConfig) error {
}
}()

l2ArtifactsFS, cleanupL2, err := pipeline.DownloadArtifacts(ctx, intent.L2ContractsLocator, progressor)
l2ArtifactsFS, cleanupL2, err := artifacts.Download(ctx, intent.L2ContractsLocator, progressor)
if err != nil {
return fmt.Errorf("failed to download L2 artifacts: %w", err)
}
Expand All @@ -171,7 +175,7 @@ func Apply(ctx context.Context, cfg ApplyConfig) error {
L2: l2ArtifactsFS,
}

l1Host, err := pipeline.DefaultScriptHost(bcaster, cfg.Logger, deployer, bundle.L1, startingNonce)
l1Host, err := env.DefaultScriptHost(bcaster, cfg.Logger, deployer, bundle.L1, startingNonce)
if err != nil {
return fmt.Errorf("failed to create L1 script host: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipeline
package artifacts

import (
"archive/tar"
Expand All @@ -19,8 +19,6 @@ import (

"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm"

"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
)

Expand All @@ -40,7 +38,7 @@ func LogProgressor(lgr log.Logger) DownloadProgressor {
}
}

func DownloadArtifacts(ctx context.Context, loc *opcm.ArtifactsLocator, progress DownloadProgressor) (foundry.StatDirFs, CleanupFunc, error) {
func Download(ctx context.Context, loc *Locator, progress DownloadProgressor) (foundry.StatDirFs, CleanupFunc, error) {
var u *url.URL
var err error
if loc.IsTag() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pipeline
package artifacts

import (
"context"
Expand All @@ -9,8 +9,6 @@ import (
"os"
"testing"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/opcm"

"github.com/stretchr/testify/require"
)

Expand All @@ -29,11 +27,11 @@ func TestDownloadArtifacts(t *testing.T) {
ctx := context.Background()
artifactsURL, err := url.Parse(ts.URL)
require.NoError(t, err)
loc := &opcm.ArtifactsLocator{
loc := &Locator{
URL: artifactsURL,
}

fs, cleanup, err := DownloadArtifacts(ctx, loc, nil)
fs, cleanup, err := Download(ctx, loc, nil)
require.NoError(t, err)
require.NotNil(t, fs)
defer func() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package opcm
package artifacts

import (
"fmt"
Expand All @@ -8,28 +8,28 @@ import (
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/standard"
)

type schemeUnmarshaler func(string) (*ArtifactsLocator, error)
type schemeUnmarshaler func(string) (*Locator, error)

var schemeUnmarshalerDispatch = map[string]schemeUnmarshaler{
"tag": unmarshalTag,
"file": unmarshalURL,
"https": unmarshalURL,
}

var DefaultL1ContractsLocator = &ArtifactsLocator{
var DefaultL1ContractsLocator = &Locator{
Tag: standard.DefaultL1ContractsTag,
}

var DefaultL2ContractsLocator = &ArtifactsLocator{
var DefaultL2ContractsLocator = &Locator{
Tag: standard.DefaultL2ContractsTag,
}

type ArtifactsLocator struct {
type Locator struct {
URL *url.URL
Tag string
}

func (a *ArtifactsLocator) UnmarshalText(text []byte) error {
func (a *Locator) UnmarshalText(text []byte) error {
str := string(text)

for scheme, unmarshaler := range schemeUnmarshalerDispatch {
Expand All @@ -49,7 +49,7 @@ func (a *ArtifactsLocator) UnmarshalText(text []byte) error {
return fmt.Errorf("unsupported scheme")
}

func (a *ArtifactsLocator) MarshalText() ([]byte, error) {
func (a *Locator) MarshalText() ([]byte, error) {
if a.URL != nil {
return []byte(a.URL.String()), nil
}
Expand All @@ -61,11 +61,11 @@ func (a *ArtifactsLocator) MarshalText() ([]byte, error) {
return nil, fmt.Errorf("no URL, path or tag set")
}

func (a *ArtifactsLocator) IsTag() bool {
func (a *Locator) IsTag() bool {
return a.Tag != ""
}

func unmarshalTag(tag string) (*ArtifactsLocator, error) {
func unmarshalTag(tag string) (*Locator, error) {
tag = strings.TrimPrefix(tag, "tag://")
if !strings.HasPrefix(tag, "op-contracts/") {
return nil, fmt.Errorf("invalid tag: %s", tag)
Expand All @@ -75,14 +75,14 @@ func unmarshalTag(tag string) (*ArtifactsLocator, error) {
return nil, err
}

return &ArtifactsLocator{Tag: tag}, nil
return &Locator{Tag: tag}, nil
}

func unmarshalURL(text string) (*ArtifactsLocator, error) {
func unmarshalURL(text string) (*Locator, error) {
u, err := url.Parse(text)
if err != nil {
return nil, err
}

return &ArtifactsLocator{URL: u}, nil
return &Locator{URL: u}, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package opcm
package artifacts

import (
"net/url"
Expand All @@ -7,17 +7,17 @@ import (
"github.com/stretchr/testify/require"
)

func TestArtifactsLocator_Marshaling(t *testing.T) {
func TestLocator_Marshaling(t *testing.T) {
tests := []struct {
name string
in string
out *ArtifactsLocator
out *Locator
err bool
}{
{
name: "valid tag",
in: "tag://op-contracts/v1.6.0",
out: &ArtifactsLocator{
out: &Locator{
Tag: "op-contracts/v1.6.0",
},
err: false,
Expand All @@ -37,15 +37,15 @@ func TestArtifactsLocator_Marshaling(t *testing.T) {
{
name: "valid HTTPS URL",
in: "https://example.com",
out: &ArtifactsLocator{
out: &Locator{
URL: parseUrl(t, "https://example.com"),
},
err: false,
},
{
name: "valid file URL",
in: "file:///tmp/artifacts",
out: &ArtifactsLocator{
out: &Locator{
URL: parseUrl(t, "file:///tmp/artifacts"),
},
err: false,
Expand All @@ -71,7 +71,7 @@ func TestArtifactsLocator_Marshaling(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var a ArtifactsLocator
var a Locator
err := a.UnmarshalText([]byte(tt.in))
if tt.err {
require.Error(t, err)
Expand Down
Loading

0 comments on commit 2c5f6ed

Please sign in to comment.