Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion op-chain-ops/deployer/broadcaster/keyed.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (t *KeyedBroadcaster) Broadcast(ctx context.Context) ([]BroadcastResult, er
)
}

results = append(results, outRes)
results[i] = outRes
}
return results, txErr.ErrorOrNil()
}
Expand Down
7 changes: 4 additions & 3 deletions op-chain-ops/deployer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ func Init(cfg InitConfig) error {
}

intent := &state.Intent{
L1ChainID: cfg.L1ChainID,
UseFaultProofs: true,
FundDevAccounts: true,
L1ChainID: cfg.L1ChainID,
UseFaultProofs: true,
FundDevAccounts: true,
ContractsRelease: "dev",
}

l1ChainIDBig := intent.L1ChainIDBig()
Expand Down
141 changes: 97 additions & 44 deletions op-chain-ops/deployer/integration_test/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,104 @@ func TestEndToEndApply(t *testing.T) {

id := uint256.NewInt(1)

addrFor := func(key devkeys.Key) common.Address {
addr, err := dk.Address(key)
require.NoError(t, err)
return addr
}
deployerAddr, err := dk.Address(depKey)
require.NoError(t, err)

env := &pipeline.Env{
Workdir: t.TempDir(),
L1Client: l1Client,
Signer: signer,
Deployer: addrFor(depKey),
Deployer: deployerAddr,
Logger: lgr,
}

t.Run("initial chain", func(t *testing.T) {
intent, st := makeIntent(t, l1ChainID, artifactsURL, dk, id)

require.NoError(t, deployer.ApplyPipeline(
ctx,
env,
intent,
st,
))

addrs := []struct {
name string
addr common.Address
}{
{"SuperchainProxyAdmin", st.SuperchainDeployment.ProxyAdminAddress},
{"SuperchainConfigProxy", st.SuperchainDeployment.SuperchainConfigProxyAddress},
{"SuperchainConfigImpl", st.SuperchainDeployment.SuperchainConfigImplAddress},
{"ProtocolVersionsProxy", st.SuperchainDeployment.ProtocolVersionsProxyAddress},
{"ProtocolVersionsImpl", st.SuperchainDeployment.ProtocolVersionsImplAddress},
{"OpcmProxy", st.ImplementationsDeployment.OpcmProxyAddress},
{"DelayedWETHImpl", st.ImplementationsDeployment.DelayedWETHImplAddress},
{"OptimismPortalImpl", st.ImplementationsDeployment.OptimismPortalImplAddress},
{"PreimageOracleSingleton", st.ImplementationsDeployment.PreimageOracleSingletonAddress},
{"MipsSingleton", st.ImplementationsDeployment.MipsSingletonAddress},
{"SystemConfigImpl", st.ImplementationsDeployment.SystemConfigImplAddress},
{"L1CrossDomainMessengerImpl", st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress},
{"L1ERC721BridgeImpl", st.ImplementationsDeployment.L1ERC721BridgeImplAddress},
{"L1StandardBridgeImpl", st.ImplementationsDeployment.L1StandardBridgeImplAddress},
{"OptimismMintableERC20FactoryImpl", st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress},
{"DisputeGameFactoryImpl", st.ImplementationsDeployment.DisputeGameFactoryImplAddress},
}
for _, addr := range addrs {
t.Run(addr.name, func(t *testing.T) {
code, err := l1Client.CodeAt(ctx, addr.addr, nil)
require.NoError(t, err)
require.NotEmpty(t, code, "contracts %s at %s has no code", addr.name, addr.addr)
})
}

validateOPChainDeployment(t, ctx, l1Client, st)
})

t.Run("subsequent chain", func(t *testing.T) {
newID := uint256.NewInt(2)
intent, st := makeIntent(t, l1ChainID, artifactsURL, dk, newID)
env.Workdir = t.TempDir()

require.NoError(t, deployer.ApplyPipeline(
ctx,
env,
intent,
st,
))

addrs := []struct {
name string
addr common.Address
}{
{"SuperchainConfigProxy", st.SuperchainDeployment.SuperchainConfigProxyAddress},
{"ProtocolVersionsProxy", st.SuperchainDeployment.ProtocolVersionsProxyAddress},
{"OpcmProxy", st.ImplementationsDeployment.OpcmProxyAddress},
}
for _, addr := range addrs {
t.Run(addr.name, func(t *testing.T) {
code, err := l1Client.CodeAt(ctx, addr.addr, nil)
require.NoError(t, err)
require.NotEmpty(t, code, "contracts %s at %s has no code", addr.name, addr.addr)
})
}

validateOPChainDeployment(t, ctx, l1Client, st)
})
}

func makeIntent(
t *testing.T,
l1ChainID *big.Int,
artifactsURL *url.URL,
dk *devkeys.MnemonicDevKeys,
l2ChainID *uint256.Int,
) (*state.Intent, *state.State) {
addrFor := func(key devkeys.Key) common.Address {
addr, err := dk.Address(key)
require.NoError(t, err)
return addr
}

intent := &state.Intent{
L1ChainID: l1ChainID.Uint64(),
SuperchainRoles: state.SuperchainRoles{
Expand All @@ -118,7 +204,7 @@ func TestEndToEndApply(t *testing.T) {
ContractsRelease: "dev",
Chains: []*state.ChainIntent{
{
ID: id.Bytes32(),
ID: l2ChainID.Bytes32(),
Roles: state.ChainRoles{
ProxyAdminOwner: addrFor(devkeys.L2ProxyAdminOwnerRole.Key(l1ChainID)),
SystemConfigOwner: addrFor(devkeys.SystemConfigOwner.Key(l1ChainID)),
Expand All @@ -134,43 +220,10 @@ func TestEndToEndApply(t *testing.T) {
st := &state.State{
Version: 1,
}
return intent, st
}

require.NoError(t, deployer.ApplyPipeline(
ctx,
env,
intent,
st,
))

addrs := []struct {
name string
addr common.Address
}{
{"SuperchainProxyAdmin", st.SuperchainDeployment.ProxyAdminAddress},
{"SuperchainConfigProxy", st.SuperchainDeployment.SuperchainConfigProxyAddress},
{"SuperchainConfigImpl", st.SuperchainDeployment.SuperchainConfigImplAddress},
{"ProtocolVersionsProxy", st.SuperchainDeployment.ProtocolVersionsProxyAddress},
{"ProtocolVersionsImpl", st.SuperchainDeployment.ProtocolVersionsImplAddress},
{"OpcmProxy", st.ImplementationsDeployment.OpcmProxyAddress},
{"DelayedWETHImpl", st.ImplementationsDeployment.DelayedWETHImplAddress},
{"OptimismPortalImpl", st.ImplementationsDeployment.OptimismPortalImplAddress},
{"PreimageOracleSingleton", st.ImplementationsDeployment.PreimageOracleSingletonAddress},
{"MipsSingleton", st.ImplementationsDeployment.MipsSingletonAddress},
{"SystemConfigImpl", st.ImplementationsDeployment.SystemConfigImplAddress},
{"L1CrossDomainMessengerImpl", st.ImplementationsDeployment.L1CrossDomainMessengerImplAddress},
{"L1ERC721BridgeImpl", st.ImplementationsDeployment.L1ERC721BridgeImplAddress},
{"L1StandardBridgeImpl", st.ImplementationsDeployment.L1StandardBridgeImplAddress},
{"OptimismMintableERC20FactoryImpl", st.ImplementationsDeployment.OptimismMintableERC20FactoryImplAddress},
{"DisputeGameFactoryImpl", st.ImplementationsDeployment.DisputeGameFactoryImplAddress},
}
for _, addr := range addrs {
t.Run(addr.name, func(t *testing.T) {
code, err := l1Client.CodeAt(ctx, addr.addr, nil)
require.NoError(t, err)
require.NotEmpty(t, code, "contracts %s at %s has no code", addr.name, addr.addr)
})
}

func validateOPChainDeployment(t *testing.T, ctx context.Context, l1Client *ethclient.Client, st *state.State) {
for _, chainState := range st.Chains {
chainAddrs := []struct {
name string
Expand All @@ -197,7 +250,7 @@ func TestEndToEndApply(t *testing.T) {
if addr.name == "FaultDisputeGameAddress" {
continue
}
t.Run(fmt.Sprintf("chain %s - %s", chainState.ID, addr.name), func(t *testing.T) {
t.Run(addr.name, func(t *testing.T) {
code, err := l1Client.CodeAt(ctx, addr.addr, nil)
require.NoError(t, err)
require.NotEmpty(t, code, "contracts %s at %s for chain %s has no code", addr.name, addr.addr, chainState.ID)
Expand Down
83 changes: 83 additions & 0 deletions op-chain-ops/deployer/opcm/contract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package opcm

import (
"bytes"
"context"
"fmt"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)

type Contract struct {
addr common.Address
client *ethclient.Client
}

func NewContract(addr common.Address, client *ethclient.Client) *Contract {
return &Contract{addr: addr, client: client}
}

func (c *Contract) SuperchainConfig(ctx context.Context) (common.Address, error) {
return c.getAddress(ctx, "superchainConfig")
}

func (c *Contract) ProtocolVersions(ctx context.Context) (common.Address, error) {
return c.getAddress(ctx, "protocolVersions")
}

func (c *Contract) getAddress(ctx context.Context, name string) (common.Address, error) {
method := abi.NewMethod(
name,
name,
abi.Function,
"view",
true,
false,
abi.Arguments{},
abi.Arguments{
abi.Argument{
Name: "address",
Type: mustType("address"),
Indexed: false,
},
},
)

calldata, err := method.Inputs.Pack()
if err != nil {
return common.Address{}, fmt.Errorf("failed to pack inputs: %w", err)
}

msg := ethereum.CallMsg{
To: &c.addr,
Data: append(bytes.Clone(method.ID), calldata...),
}
result, err := c.client.CallContract(ctx, msg, nil)
if err != nil {
return common.Address{}, fmt.Errorf("failed to call contract: %w", err)
}

out, err := method.Outputs.Unpack(result)
if err != nil {
return common.Address{}, fmt.Errorf("failed to unpack result: %w", err)
}
if len(out) != 1 {
return common.Address{}, fmt.Errorf("unexpected output length: %d", len(out))
}
addr, ok := out[0].(common.Address)
if !ok {
return common.Address{}, fmt.Errorf("unexpected type: %T", out[0])
}
return addr, nil
}

func mustType(t string) abi.Type {
typ, err := abi.NewType(t, "", nil)
if err != nil {
panic(err)
}
return typ
}
Loading