|
| 1 | +package pipeline |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log/slog" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts" |
| 11 | + "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/standard" |
| 12 | + "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state" |
| 13 | + "github.com/ethereum-optimism/optimism/op-service/testlog" |
| 14 | + "github.com/ethereum-optimism/optimism/op-service/testutils/devnet" |
| 15 | + "github.com/ethereum/go-ethereum/common" |
| 16 | + "github.com/ethereum/go-ethereum/ethclient" |
| 17 | + "github.com/stretchr/testify/require" |
| 18 | +) |
| 19 | + |
| 20 | +func TestInitLiveStrategy_OPCMReuseLogicSepolia(t *testing.T) { |
| 21 | + rpcURL := os.Getenv("SEPOLIA_RPC_URL") |
| 22 | + require.NotEmpty(t, rpcURL, "SEPOLIA_RPC_URL must be set") |
| 23 | + |
| 24 | + lgr := testlog.Logger(t, slog.LevelInfo) |
| 25 | + retryProxy := devnet.NewRetryProxy(lgr, rpcURL) |
| 26 | + require.NoError(t, retryProxy.Start()) |
| 27 | + t.Cleanup(func() { |
| 28 | + require.NoError(t, retryProxy.Stop()) |
| 29 | + }) |
| 30 | + |
| 31 | + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 32 | + defer cancel() |
| 33 | + |
| 34 | + client, err := ethclient.Dial(retryProxy.Endpoint()) |
| 35 | + require.NoError(t, err) |
| 36 | + |
| 37 | + l1ChainID := uint64(11155111) |
| 38 | + t.Run("untagged L1 locator", func(t *testing.T) { |
| 39 | + st := &state.State{ |
| 40 | + Version: 1, |
| 41 | + } |
| 42 | + require.NoError(t, InitLiveStrategy( |
| 43 | + ctx, |
| 44 | + &Env{ |
| 45 | + L1Client: client, |
| 46 | + Logger: lgr, |
| 47 | + }, |
| 48 | + &state.Intent{ |
| 49 | + L1ChainID: l1ChainID, |
| 50 | + L1ContractsLocator: artifacts.MustNewLocatorFromURL("file:///not-a-path"), |
| 51 | + L2ContractsLocator: artifacts.MustNewLocatorFromURL("file:///not-a-path"), |
| 52 | + }, |
| 53 | + st, |
| 54 | + )) |
| 55 | + |
| 56 | + // Defining a file locator will always deploy a new superchain and OPCM |
| 57 | + require.Nil(t, st.SuperchainDeployment) |
| 58 | + require.Nil(t, st.ImplementationsDeployment) |
| 59 | + }) |
| 60 | + |
| 61 | + t.Run("tagged L1 locator with standard intent types and standard roles", func(t *testing.T) { |
| 62 | + runTest := func(configType state.IntentType) { |
| 63 | + stdSuperchainRoles, err := state.GetStandardSuperchainRoles(l1ChainID) |
| 64 | + require.NoError(t, err) |
| 65 | + |
| 66 | + intent := &state.Intent{ |
| 67 | + ConfigType: configType, |
| 68 | + L1ChainID: l1ChainID, |
| 69 | + L1ContractsLocator: artifacts.DefaultL1ContractsLocator, |
| 70 | + L2ContractsLocator: artifacts.DefaultL2ContractsLocator, |
| 71 | + SuperchainRoles: stdSuperchainRoles, |
| 72 | + } |
| 73 | + st := &state.State{ |
| 74 | + Version: 1, |
| 75 | + } |
| 76 | + require.NoError(t, InitLiveStrategy( |
| 77 | + ctx, |
| 78 | + &Env{ |
| 79 | + L1Client: client, |
| 80 | + Logger: lgr, |
| 81 | + }, |
| 82 | + intent, |
| 83 | + st, |
| 84 | + )) |
| 85 | + |
| 86 | + // Defining a file locator will always deploy a new superchain and OPCM |
| 87 | + superCfg, err := standard.SuperchainFor(l1ChainID) |
| 88 | + require.NoError(t, err) |
| 89 | + proxyAdmin, err := standard.SuperchainProxyAdminAddrFor(l1ChainID) |
| 90 | + require.NoError(t, err) |
| 91 | + opcmAddr, err := standard.ManagerImplementationAddrFor(l1ChainID, intent.L1ContractsLocator.Tag) |
| 92 | + require.NoError(t, err) |
| 93 | + |
| 94 | + expDeployment := &state.SuperchainDeployment{ |
| 95 | + ProxyAdminAddress: proxyAdmin, |
| 96 | + ProtocolVersionsProxyAddress: superCfg.ProtocolVersionsAddr, |
| 97 | + SuperchainConfigProxyAddress: superCfg.SuperchainConfigAddr, |
| 98 | + } |
| 99 | + |
| 100 | + // Tagged locator will reuse the existing superchain and OPCM |
| 101 | + require.NotNil(t, st.SuperchainDeployment) |
| 102 | + require.NotNil(t, st.ImplementationsDeployment) |
| 103 | + require.Equal(t, *expDeployment, *st.SuperchainDeployment) |
| 104 | + require.Equal(t, opcmAddr, st.ImplementationsDeployment.OpcmAddress) |
| 105 | + } |
| 106 | + |
| 107 | + runTest(state.IntentTypeStandard) |
| 108 | + runTest(state.IntentTypeStandardOverrides) |
| 109 | + }) |
| 110 | + |
| 111 | + t.Run("tagged L1 locator with standard intent types and modified roles", func(t *testing.T) { |
| 112 | + runTest := func(configType state.IntentType) { |
| 113 | + intent := &state.Intent{ |
| 114 | + ConfigType: configType, |
| 115 | + L1ChainID: l1ChainID, |
| 116 | + L1ContractsLocator: artifacts.DefaultL1ContractsLocator, |
| 117 | + L2ContractsLocator: artifacts.DefaultL2ContractsLocator, |
| 118 | + SuperchainRoles: &state.SuperchainRoles{ |
| 119 | + Guardian: common.Address{0: 99}, |
| 120 | + }, |
| 121 | + } |
| 122 | + st := &state.State{ |
| 123 | + Version: 1, |
| 124 | + } |
| 125 | + require.NoError(t, InitLiveStrategy( |
| 126 | + ctx, |
| 127 | + &Env{ |
| 128 | + L1Client: client, |
| 129 | + Logger: lgr, |
| 130 | + }, |
| 131 | + intent, |
| 132 | + st, |
| 133 | + )) |
| 134 | + |
| 135 | + // Modified roles will cause a new superchain and OPCM to be deployed |
| 136 | + require.Nil(t, st.SuperchainDeployment) |
| 137 | + require.Nil(t, st.ImplementationsDeployment) |
| 138 | + } |
| 139 | + |
| 140 | + runTest(state.IntentTypeStandard) |
| 141 | + runTest(state.IntentTypeStandardOverrides) |
| 142 | + }) |
| 143 | + |
| 144 | + t.Run("tagged locator with custom intent type", func(t *testing.T) { |
| 145 | + intent := &state.Intent{ |
| 146 | + ConfigType: state.IntentTypeCustom, |
| 147 | + L1ChainID: l1ChainID, |
| 148 | + L1ContractsLocator: artifacts.DefaultL1ContractsLocator, |
| 149 | + L2ContractsLocator: artifacts.DefaultL2ContractsLocator, |
| 150 | + SuperchainRoles: &state.SuperchainRoles{ |
| 151 | + Guardian: common.Address{0: 99}, |
| 152 | + }, |
| 153 | + } |
| 154 | + st := &state.State{ |
| 155 | + Version: 1, |
| 156 | + } |
| 157 | + require.NoError(t, InitLiveStrategy( |
| 158 | + ctx, |
| 159 | + &Env{ |
| 160 | + L1Client: client, |
| 161 | + Logger: lgr, |
| 162 | + }, |
| 163 | + intent, |
| 164 | + st, |
| 165 | + )) |
| 166 | + |
| 167 | + // Custom intent types always deploy a new superchain and OPCM |
| 168 | + require.Nil(t, st.SuperchainDeployment) |
| 169 | + require.Nil(t, st.ImplementationsDeployment) |
| 170 | + }) |
| 171 | +} |
0 commit comments