|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "os/exec" |
| 6 | + "regexp" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygondatacommittee" |
| 10 | + "github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm" |
| 11 | + "github.com/0xPolygonHermez/zkevm-node/test/operations" |
| 12 | + "github.com/ethereum/go-ethereum/accounts/abi/bind" |
| 13 | + "github.com/ethereum/go-ethereum/common" |
| 14 | + "github.com/ethereum/go-ethereum/core/types" |
| 15 | + "github.com/ethereum/go-ethereum/ethclient" |
| 16 | + "github.com/stretchr/testify/require" |
| 17 | +) |
| 18 | + |
| 19 | +func TestSetDataAvailabilityProtocol(t *testing.T) { |
| 20 | + if testing.Short() { |
| 21 | + t.Skip() |
| 22 | + } |
| 23 | + |
| 24 | + ctx := context.Background() |
| 25 | + defer func() { |
| 26 | + require.NoError(t, operations.Teardown()) |
| 27 | + }() |
| 28 | + |
| 29 | + err := operations.Teardown() |
| 30 | + require.NoError(t, err) |
| 31 | + |
| 32 | + opsCfg := operations.GetDefaultOperationsConfig() |
| 33 | + |
| 34 | + opsman, err := operations.NewManager(ctx, opsCfg) |
| 35 | + require.NoError(t, err) |
| 36 | + |
| 37 | + err = opsman.Setup() |
| 38 | + require.NoError(t, err) |
| 39 | + |
| 40 | + clientL1, err := ethclient.Dial(operations.DefaultL1NetworkURL) |
| 41 | + require.NoError(t, err) |
| 42 | + |
| 43 | + auth, err := operations.GetAuth(operations.DefaultSequencerPrivateKey, operations.DefaultL1ChainID) |
| 44 | + require.NoError(t, err) |
| 45 | + |
| 46 | + zkEVM, err := polygonzkevm.NewPolygonzkevm( |
| 47 | + common.HexToAddress(operations.DefaultL1ZkEVMSmartContract), |
| 48 | + clientL1, |
| 49 | + ) |
| 50 | + require.NoError(t, err) |
| 51 | + |
| 52 | + currentDAPAddr, err := zkEVM.DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) |
| 53 | + require.NoError(t, err) |
| 54 | + require.Equal(t, common.HexToAddress(operations.DefaultL1DataCommitteeContract), currentDAPAddr) |
| 55 | + |
| 56 | + // New DAC Setup |
| 57 | + newDAPAddr, tx, newDA, err := polygondatacommittee.DeployPolygondatacommittee(auth, clientL1) |
| 58 | + require.NoError(t, err) |
| 59 | + require.NotEqual(t, newDAPAddr, currentDAPAddr) |
| 60 | + require.NoError(t, operations.WaitTxToBeMined(ctx, clientL1, tx, operations.DefaultTimeoutTxToBeMined)) |
| 61 | + |
| 62 | + tx, err = newDA.Initialize(auth) |
| 63 | + require.NoError(t, err) |
| 64 | + require.NoError(t, operations.WaitTxToBeMined(ctx, clientL1, tx, operations.DefaultTimeoutTxToBeMined)) |
| 65 | + |
| 66 | + cmd := exec.Command("docker", "exec", "zkevm-sequence-sender", |
| 67 | + "/app/zkevm-node", "set-dap", |
| 68 | + "--da-addr", newDAPAddr.String(), |
| 69 | + "--network", "custom", |
| 70 | + "--custom-network-file", "/app/genesis.json", |
| 71 | + "--key-store-path", "/pk/sequencer.keystore", |
| 72 | + "--pw", "testonly", |
| 73 | + "--cfg", "/app/config.toml") |
| 74 | + |
| 75 | + output, err := cmd.CombinedOutput() |
| 76 | + require.NoError(t, err) |
| 77 | + |
| 78 | + txHash := common.HexToHash(extractHexFromString(string(output))) |
| 79 | + receipt, err := operations.WaitTxReceipt(ctx, txHash, operations.DefaultTimeoutTxToBeMined, clientL1) |
| 80 | + require.NoError(t, err) |
| 81 | + require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status) |
| 82 | + |
| 83 | + currentDAPAddr, err = zkEVM.DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) |
| 84 | + require.NoError(t, err) |
| 85 | + require.Equal(t, newDAPAddr, currentDAPAddr) |
| 86 | +} |
| 87 | + |
| 88 | +func extractHexFromString(output string) string { |
| 89 | + re := regexp.MustCompile(`Transaction to set new data availability protocol sent. Hash: (0x[0-9a-fA-F]+)`) |
| 90 | + match := re.FindStringSubmatch(output) |
| 91 | + if len(match) > 1 { |
| 92 | + return match[1] |
| 93 | + } |
| 94 | + return "" |
| 95 | +} |
0 commit comments