-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathmigrate_test.go
More file actions
319 lines (278 loc) · 13.9 KB
/
migrate_test.go
File metadata and controls
319 lines (278 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
package cli
import (
"context"
"encoding/json"
"math/big"
"path/filepath"
"strings"
"testing"
"time"
"log/slog"
"github.com/ethereum-optimism/optimism/op-chain-ops/addresses"
"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/bootstrap"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/integration_test/shared"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/manage"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/pipeline"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/standard"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum-optimism/optimism/op-service/testutils/devnet"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"
)
// TestCLIMigrateRequiredFlags tests that required flags are validated for both OPCM v1 and v2
func TestCLIMigrateRequiredFlags(t *testing.T) {
// Test common required flags (apply to both v1 and v2)
t.Run("missing l1-rpc-url", func(t *testing.T) {
runner := NewCLITestRunner(t)
runner.ExpectErrorContains(t, []string{
"manage", "migrate",
"--private-key", "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"--opcm-impl-address", common.Address{0x02}.Hex(),
// Intentionally omit --l1-rpc-url
}, nil, "missing required flag: l1-rpc-url")
})
t.Run("missing private-key", func(t *testing.T) {
runner := NewCLITestRunner(t)
runner.ExpectErrorContains(t, []string{
"manage", "migrate",
"--l1-rpc-url", "http://localhost:8545",
"--opcm-impl-address", common.Address{0x02}.Hex(),
// Intentionally omit --private-key
}, nil, "missing required flag: private-key")
})
t.Run("missing opcm-impl-address", func(t *testing.T) {
runner := NewCLITestRunner(t)
runner.ExpectErrorContains(t, []string{
"manage", "migrate",
"--l1-rpc-url", "http://localhost:8545",
"--private-key", "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
// Intentionally omit --opcm-impl-address
}, nil, "missing required flag: opcm-impl-address")
})
t.Run("missing system-config-proxy-address", func(t *testing.T) {
runner := NewCLITestRunner(t)
runner.ExpectErrorContains(t, []string{
"manage", "migrate",
"--l1-rpc-url", "http://localhost:8545",
"--private-key", "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"--opcm-impl-address", common.Address{0x02}.Hex(),
// Intentionally omit --system-config-proxy-address
}, nil, "missing required flag: system-config-proxy-address")
})
t.Run("missing starting-anchor-root", func(t *testing.T) {
runner := NewCLITestRunner(t)
runner.ExpectErrorContains(t, []string{
"manage", "migrate",
"--l1-rpc-url", "http://localhost:8545",
"--private-key", "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"--opcm-impl-address", common.Address{0x02}.Hex(),
"--system-config-proxy-address", common.Address{0x03}.Hex(),
// Intentionally omit --starting-anchor-root
}, nil, "missing required flag: starting-anchor-root")
})
}
// TestCLIMigrateV2 tests the migrate-v2 CLI command for OPCM v2
func TestCLIMigrateV2(t *testing.T) {
lgr := testlog.Logger(t, slog.LevelDebug)
forkedL1, stopL1, err := devnet.NewForkedSepolia(lgr)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, stopL1())
})
l1RPC := forkedL1.RPCUrl()
testCacheDir := testutils.IsolatedTestDirWithAutoCleanup(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
pkHex, _, _ := shared.DefaultPrivkey(t)
privateKeyECDSA, err := crypto.HexToECDSA(strings.TrimPrefix(pkHex, "0x"))
require.NoError(t, err)
prank := crypto.PubkeyToAddress(privateKeyECDSA.PublicKey)
// Deploy superchain contracts first (required for OPCM deployment)
superchainProxyAdminOwner := prank
// Deploy superchain contracts first
superchainOut, err := bootstrap.Superchain(ctx, bootstrap.SuperchainConfig{
L1RPCUrl: l1RPC,
PrivateKey: pkHex,
ArtifactsLocator: artifacts.EmbeddedLocator,
Logger: lgr,
SuperchainProxyAdminOwner: superchainProxyAdminOwner,
ProtocolVersionsOwner: common.Address{'P'},
Guardian: common.Address{'G'},
Paused: false,
RequiredProtocolVersion: params.ProtocolVersionV0{Major: 1}.Encode(),
RecommendedProtocolVersion: params.ProtocolVersionV0{Major: 2}.Encode(),
CacheDir: testCacheDir,
})
require.NoError(t, err, "Failed to deploy superchain contracts")
devFeatureBitmap := deployer.EnableDevFeature(deployer.OPCMV2DevFlag, deployer.OptimismPortalInteropDevFlag)
// Deploy OPCM V2 implementations (with OPCMV2DevFlag)
cfg := bootstrap.ImplementationsConfig{
L1RPCUrl: l1RPC,
PrivateKey: pkHex,
ArtifactsLocator: artifacts.EmbeddedLocator,
Logger: lgr,
MIPSVersion: int(standard.MIPSVersion),
WithdrawalDelaySeconds: standard.WithdrawalDelaySeconds,
MinProposalSizeBytes: standard.MinProposalSizeBytes,
ChallengePeriodSeconds: standard.ChallengePeriodSeconds,
ProofMaturityDelaySeconds: standard.ProofMaturityDelaySeconds,
DisputeGameFinalityDelaySeconds: standard.DisputeGameFinalityDelaySeconds,
DevFeatureBitmap: devFeatureBitmap,
SuperchainConfigProxy: superchainOut.SuperchainConfigProxy,
ProtocolVersionsProxy: superchainOut.ProtocolVersionsProxy,
SuperchainProxyAdmin: superchainOut.SuperchainProxyAdmin,
L1ProxyAdminOwner: superchainProxyAdminOwner,
Challenger: common.Address{'C'},
CacheDir: testCacheDir,
FaultGameMaxGameDepth: standard.DisputeMaxGameDepth,
FaultGameSplitDepth: standard.DisputeSplitDepth,
FaultGameClockExtension: standard.DisputeClockExtension,
FaultGameMaxClockDuration: standard.DisputeMaxClockDuration,
}
impls, err := bootstrap.Implementations(ctx, cfg)
require.NoError(t, err, "Failed to deploy implementations")
require.NotEqual(t, common.Address{}, impls.OpcmV2, "OPCM V2 address should be set")
// Set up a test chain
l1ChainID := uint64(11155111) // Sepolia chain ID
l2ChainID := uint256.NewInt(1)
dk, err := devkeys.NewMnemonicDevKeys(devkeys.TestMnemonic)
require.NoError(t, err)
// Create a runner with network setup
runner := NewCLITestRunnerWithNetwork(t, WithL1RPC(l1RPC), WithPrivateKey(pkHex))
workDir := runner.GetWorkDir()
// Initialize intent and deploy chain
intent, _ := cliInitIntent(t, runner, l1ChainID, []common.Hash{l2ChainID.Bytes32()})
if intent.SuperchainRoles == nil {
intent.SuperchainRoles = &addresses.SuperchainRoles{}
}
l1ChainIDBig := big.NewInt(int64(l1ChainID))
intent.SuperchainRoles.SuperchainProxyAdminOwner = superchainProxyAdminOwner
intent.SuperchainRoles.SuperchainGuardian = shared.AddrFor(t, dk, devkeys.SuperchainConfigGuardianKey.Key(l1ChainIDBig))
intent.SuperchainRoles.ProtocolVersionsOwner = superchainProxyAdminOwner
intent.SuperchainRoles.Challenger = shared.AddrFor(t, dk, devkeys.ChallengerRole.Key(l1ChainIDBig))
for _, chain := range intent.Chains {
chain.Roles.L1ProxyAdminOwner = superchainProxyAdminOwner
chain.Roles.L2ProxyAdminOwner = shared.AddrFor(t, dk, devkeys.L2ProxyAdminOwnerRole.Key(l1ChainIDBig))
chain.Roles.SystemConfigOwner = superchainProxyAdminOwner
chain.Roles.UnsafeBlockSigner = shared.AddrFor(t, dk, devkeys.SequencerP2PRole.Key(l1ChainIDBig))
chain.Roles.Batcher = shared.AddrFor(t, dk, devkeys.BatcherRole.Key(l1ChainIDBig))
chain.Roles.Proposer = shared.AddrFor(t, dk, devkeys.ProposerRole.Key(l1ChainIDBig))
chain.Roles.Challenger = shared.AddrFor(t, dk, devkeys.ChallengerRole.Key(l1ChainIDBig))
chain.BaseFeeVaultRecipient = shared.AddrFor(t, dk, devkeys.BaseFeeVaultRecipientRole.Key(l1ChainIDBig))
chain.L1FeeVaultRecipient = shared.AddrFor(t, dk, devkeys.L1FeeVaultRecipientRole.Key(l1ChainIDBig))
chain.SequencerFeeVaultRecipient = shared.AddrFor(t, dk, devkeys.SequencerFeeVaultRecipientRole.Key(l1ChainIDBig))
chain.OperatorFeeVaultRecipient = shared.AddrFor(t, dk, devkeys.OperatorFeeVaultRecipientRole.Key(l1ChainIDBig))
chain.Eip1559DenominatorCanyon = standard.Eip1559DenominatorCanyon
chain.Eip1559Denominator = standard.Eip1559Denominator
chain.Eip1559Elasticity = standard.Eip1559Elasticity
}
// Populate the state with predeployed superchain and implementations
// so the pipeline knows about them
st, err := pipeline.ReadState(workDir)
require.NoError(t, err)
// Set superchain deployment addresses
if st.SuperchainDeployment == nil {
st.SuperchainDeployment = &addresses.SuperchainContracts{
SuperchainConfigProxy: superchainOut.SuperchainConfigProxy,
SuperchainConfigImpl: superchainOut.SuperchainConfigImpl,
ProtocolVersionsProxy: superchainOut.ProtocolVersionsProxy,
ProtocolVersionsImpl: superchainOut.ProtocolVersionsImpl,
SuperchainProxyAdminImpl: superchainOut.SuperchainProxyAdmin,
}
}
// Set implementations deployment addresses
if st.ImplementationsDeployment == nil {
st.ImplementationsDeployment = &addresses.ImplementationsContracts{
OpcmV2Impl: impls.OpcmV2,
OpcmContainerImpl: impls.OpcmContainer,
OpcmUtilsImpl: impls.OpcmUtils,
OpcmMigratorImpl: impls.OpcmMigrator,
OptimismPortalImpl: impls.OptimismPortalImpl,
DelayedWethImpl: impls.DelayedWETHImpl,
EthLockboxImpl: impls.ETHLockboxImpl,
SystemConfigImpl: impls.SystemConfigImpl,
L1CrossDomainMessengerImpl: impls.L1CrossDomainMessengerImpl,
L1Erc721BridgeImpl: impls.L1ERC721BridgeImpl,
L1StandardBridgeImpl: impls.L1StandardBridgeImpl,
OptimismMintableErc20FactoryImpl: impls.OptimismMintableERC20FactoryImpl,
DisputeGameFactoryImpl: impls.DisputeGameFactoryImpl,
AnchorStateRegistryImpl: impls.AnchorStateRegistryImpl,
PreimageOracleImpl: impls.PreimageOracleSingleton,
MipsImpl: impls.MipsSingleton,
FaultDisputeGameImpl: impls.FaultDisputeGameImpl,
PermissionedDisputeGameImpl: impls.PermissionedDisputeGameImpl,
OpcmStandardValidatorImpl: impls.OpcmStandardValidator,
}
}
require.NoError(t, pipeline.WriteState(workDir, st))
// Set global deploy overrides with devFeatureBitmap for OPCM V2
intent.GlobalDeployOverrides = map[string]any{
"devFeatureBitmap": devFeatureBitmap,
}
// Since we are enabling Interop in the bitmap we enable the UseInterop flag
intent.UseInterop = true
require.NoError(t, intent.WriteToFile(filepath.Join(workDir, "intent.toml")))
// Apply deployment
// Note: Validation will run automatically but may find expected errors for migration test deployments
// (e.g., custom dev features, non-standard configurations). We verify deployment succeeded despite validation errors.
applyCtx, applyCancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer applyCancel()
output, runErr := runner.RunWithNetwork(applyCtx, []string{
"apply",
"--deployment-target", "live",
"--workdir", workDir,
"--validate", "auto",
}, nil)
// Verify deployment succeeded regardless of validation errors
st, err = pipeline.ReadState(workDir)
require.NoError(t, err, "State should be readable after apply")
require.NotNil(t, st.AppliedIntent, "Applied intent should exist")
require.Len(t, st.Chains, 1, "Should have one chain deployed")
// If there was an error, it should be validation-related, not a deployment failure
if runErr != nil {
require.Contains(t, output, "validation", "Error should be validation-related, not deployment failure")
require.Contains(t, runErr.Error(), "validation", "Error should mention validation")
}
systemConfigProxy := st.Chains[0].SystemConfigProxy
// Run migrate-v2 command
// Note: dispute-game-type should be 0 (Cannon), not 4 (SuperCannon)
// Game type 4 is only for starting-respected-game-type
migrateOutput := runner.ExpectSuccessWithNetwork(t, []string{
"manage",
"migrate",
"--l1-proxy-admin-owner-address", superchainProxyAdminOwner.Hex(),
"--l1-rpc-url", l1RPC,
"--private-key", pkHex,
"--opcm-impl-address", impls.OpcmV2.Hex(),
"--system-config-proxy-address", systemConfigProxy.Hex(),
"--dispute-game-enabled",
"--dispute-game-type", "0", // GameTypeCannon (0), not SuperCannon (4)
"--dispute-absolute-prestate", "0x0000000000000000000000000000000000000000000000000000000000000abc",
"--starting-anchor-root", "0x0000000000000000000000000000000000000000000000000000000000000def",
"--starting-anchor-l2-sequence-number", "1",
"--starting-respected-game-type", "5", // GameTypeSuperPermissionedCannon (5)
"--initial-bond", "1000000000000000000",
}, nil)
// Parse output to verify DisputeGameFactory was deployed
// Find the JSON output by looking for the opening brace
var migrationOutput manage.InteropMigrationOutput
jsonStart := strings.Index(migrateOutput, "{")
if jsonStart == -1 {
t.Logf("Full output length: %d", len(migrateOutput))
t.Logf("Full output: %q", migrateOutput)
t.Fatalf("No JSON output found in output")
}
// Find the end of the JSON object
jsonEnd := strings.Index(migrateOutput[jsonStart:], "}") + jsonStart + 1
jsonOutput := migrateOutput[jsonStart:jsonEnd]
err = json.Unmarshal([]byte(jsonOutput), &migrationOutput)
require.NoError(t, err, "Failed to parse migration output: %s", jsonOutput)
require.NotEqual(t, common.Address{}, migrationOutput.DisputeGameFactory, "DisputeGameFactory should be deployed")
}