From 11f86715c3a2f627340babf44fc537d9c63b122b Mon Sep 17 00:00:00 2001 From: Marcos Antonio Maceo Reyes Date: Sat, 5 Aug 2023 11:58:05 +0400 Subject: [PATCH] [feat] add failing test to test pipeline --- .../engine/suites/withdrawals/tests.go | 306 +++++++++--------- 1 file changed, 153 insertions(+), 153 deletions(-) diff --git a/simulators/ethereum/engine/suites/withdrawals/tests.go b/simulators/ethereum/engine/suites/withdrawals/tests.go index 8e4dfd27ba..e50cafbd7b 100644 --- a/simulators/ethereum/engine/suites/withdrawals/tests.go +++ b/simulators/ethereum/engine/suites/withdrawals/tests.go @@ -133,21 +133,21 @@ var Tests = []test.SpecInterface{ }, // // TODO: Fix this test. It's reverting the block, which is the expected behavior. - // &WithdrawalsBaseSpec{ - // Spec: test.Spec{ - // Name: "Withdrawals Fork on Block 3", - // About: ` - // Tests the transition to the withdrawals fork after two blocks - // have happened. - // Block 2 is sent with invalid non-null withdrawals payload and - // client is expected to respond with the appropriate error. - // `, - // }, - // WithdrawalsForkHeight: 3, // Genesis, Block 1 and 2 are Pre-Withdrawals - // WithdrawalsBlockCount: 1, - // WithdrawalsPerBlock: 16, - // TimeIncrements: 5, - // }, + &WithdrawalsBaseSpec{ + Spec: test.Spec{ + Name: "Withdrawals Fork on Block 3", + About: ` + Tests the transition to the withdrawals fork after two blocks + have happened. + Block 2 is sent with invalid non-null withdrawals payload and + client is expected to respond with the appropriate error. + `, + }, + WithdrawalsForkHeight: 3, // Genesis, Block 1 and 2 are Pre-Withdrawals + WithdrawalsBlockCount: 1, + WithdrawalsPerBlock: 16, + TimeIncrements: 5, + }, &WithdrawalsBaseSpec{ Spec: test.Spec{ @@ -255,12 +255,12 @@ var Tests = []test.SpecInterface{ Spec: test.Spec{ Name: "Sync after 2 blocks - Withdrawals on Block 1 - Single Withdrawal Account - No Transactions", About: ` - - Spawn a first client - - Go through withdrawals fork on Block 1 - - Withdraw to a single account 16 times each block for 2 blocks - - Spawn a secondary client and send FCUV2(head) - - Wait for sync and verify withdrawn account's balance - `, + - Spawn a first client + - Go through withdrawals fork on Block 1 + - Withdraw to a single account 16 times each block for 2 blocks + - Spawn a secondary client and send FCUV2(head) + - Wait for sync and verify withdrawn account's balance + `, //TimeoutSeconds: 6000, }, WithdrawalsForkHeight: 1, @@ -276,12 +276,12 @@ var Tests = []test.SpecInterface{ Spec: test.Spec{ Name: "Sync after 2 blocks - Withdrawals on Block 1 - Single Withdrawal Account", About: ` - - Spawn a first client - - Go through withdrawals fork on Block 1 - - Withdraw to a single account 16 times each block for 2 blocks - - Spawn a secondary client and send FCUV2(head) - - Wait for sync and verify withdrawn account's balance - `, + - Spawn a first client + - Go through withdrawals fork on Block 1 + - Withdraw to a single account 16 times each block for 2 blocks + - Spawn a secondary client and send FCUV2(head) + - Wait for sync and verify withdrawn account's balance + `, }, WithdrawalsForkHeight: 1, WithdrawalsBlockCount: 2, @@ -296,11 +296,11 @@ var Tests = []test.SpecInterface{ Spec: test.Spec{ Name: "Sync after 2 blocks - Withdrawals on Genesis - Single Withdrawal Account", About: ` - - Spawn a first client, with Withdrawals since genesis - - Withdraw to a single account 16 times each block for 2 blocks - - Spawn a secondary client and send FCUV2(head) - - Wait for sync and verify withdrawn account's balance - `, + - Spawn a first client, with Withdrawals since genesis + - Withdraw to a single account 16 times each block for 2 blocks + - Spawn a secondary client and send FCUV2(head) + - Wait for sync and verify withdrawn account's balance + `, }, WithdrawalsForkHeight: 0, WithdrawalsBlockCount: 2, @@ -612,8 +612,8 @@ var Tests = []test.SpecInterface{ - 2 blocks with withdrawals - Claim accumulated withdrawals - Produce 1 additional pair (A, B) of blocks: - A: block with withdrawals - B: block with claim Tx + A: block with withdrawals + B: block with claim Tx - Compares balances and events values with withdrawals from CL `, }, @@ -633,8 +633,8 @@ var Tests = []test.SpecInterface{ - 2 blocks with withdrawals - Claim accumulated withdrawals - Produce 1 additional pair (A, B) of blocks: - A: block with withdrawals - B: block with claim Tx + A: block with withdrawals + B: block with claim Tx - Compares balances and events values with withdrawals from CL `, }, @@ -690,8 +690,8 @@ var Tests = []test.SpecInterface{ - 8 blocks with withdrawals - Claim accumulated withdrawals - Produce 1 additional pair (A, B) of blocks: - A: block with withdrawals - B: block with claim Tx + A: block with withdrawals + B: block with claim Tx - Compares balances and events values with withdrawals from CL `, }, @@ -711,8 +711,8 @@ var Tests = []test.SpecInterface{ - 3 blocks with withdrawals - Claim accumulated withdrawals - Produce 3 additional pairs (A, B) of blocks: - A: block with withdrawals - B: block with claim Tx + A: block with withdrawals + B: block with claim Tx - Compares balances and events values with withdrawals from CL `, }, @@ -1041,9 +1041,9 @@ func (ws *WithdrawalsBaseSpec) Execute(t *test.Env) { r := t.TestEngine.TestBlockByNumber(nil) r.ExpectationDescription = ` - Requested "latest" block expecting genesis to contain - withdrawalRoot=nil, because genesis.timestamp < shanghaiTime - ` + Requested "latest" block expecting genesis to contain + withdrawalRoot=nil, because genesis.timestamp < shanghaiTime + ` r.ExpectWithdrawalsRoot(nil) // Produce any blocks necessary to reach withdrawals fork @@ -1092,127 +1092,127 @@ func (ws *WithdrawalsBaseSpec) Execute(t *test.Env) { Requested "latest" block expecting block to contain withdrawalRoot=nil, because (block %d).timestamp < shanghaiTime `, - t.CLMock.LatestPayloadBuilt.Number, - ) - r.ExpectWithdrawalsRoot(nil) - } - }, - OnForkchoiceBroadcast: func() { - if !ws.SkipBaseVerifications { - ws.VerifyContractsStorage(t) - } - }, - }) + t.CLMock.LatestPayloadBuilt.Number, + ) + r.ExpectWithdrawalsRoot(nil) + } + }, + OnForkchoiceBroadcast: func() { + if !ws.SkipBaseVerifications { + ws.VerifyContractsStorage(t) + } + }, +}) - ws.waitForShaghai(t) +ws.waitForShaghai(t) - var ( - startAccount = ws.GetWithdrawalsStartAccount() - nextIndex = uint64(0) - ) +var ( + startAccount = ws.GetWithdrawalsStartAccount() + nextIndex = uint64(0) +) - // start client - client := getClient(t) - if client == nil { - t.Fatalf("Couldn't connect to client") - return - } - defer client.Close() +// start client +client := getClient(t) +if client == nil { + t.Fatalf("Couldn't connect to client") + return +} +defer client.Close() - // Produce requested post-shanghai blocks: - // 1. Send some withdrawals and transactions - // 2. Check that contract withdrawable amount matches the expectations - for i := 0; i < int(ws.WithdrawalsBlockCount); i++ { - t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{ - OnPayloadProducerSelected: func() { - // Send some withdrawals - t.CLMock.NextWithdrawals, nextIndex = ws.GenerateWithdrawalsForBlock(nextIndex, startAccount) - ws.WithdrawalsHistory[t.CLMock.CurrentPayloadNumber] = t.CLMock.NextWithdrawals +// Produce requested post-shanghai blocks: +// 1. Send some withdrawals and transactions +// 2. Check that contract withdrawable amount matches the expectations +for i := 0; i < int(ws.WithdrawalsBlockCount); i++ { + t.CLMock.ProduceSingleBlock(clmock.BlockProcessCallbacks{ + OnPayloadProducerSelected: func() { + // Send some withdrawals + t.CLMock.NextWithdrawals, nextIndex = ws.GenerateWithdrawalsForBlock(nextIndex, startAccount) + ws.WithdrawalsHistory[t.CLMock.CurrentPayloadNumber] = t.CLMock.NextWithdrawals - ws.sendPayloadTransactions(t) - }, - OnGetPayload: func() { - if !ws.SkipBaseVerifications { - - // Verify the list of withdrawals returned on the payload built - // completely matches the list provided in the - // engine_forkchoiceUpdatedV2 method call - if sentList, ok := ws.WithdrawalsHistory[t.CLMock.CurrentPayloadNumber]; !ok { - t.Fatalf("FAIL (%s): Withdrawals sent list was not saved", t.TestName) - } else { - if len(sentList) != len(t.CLMock.LatestPayloadBuilt.Withdrawals) { - t.Fatalf( - "FAIL (%s): Incorrect list of withdrawals on built payload: want=%d, got=%d", - t.TestName, - len(sentList), - len(t.CLMock.LatestPayloadBuilt.Withdrawals), - ) - } - for i := 0; i < len(sentList); i++ { - if err := test.CompareWithdrawal(sentList[i], t.CLMock.LatestPayloadBuilt.Withdrawals[i]); err != nil { - t.Fatalf("FAIL (%s): Incorrect withdrawal on index %d: %v", t.TestName, i, err) - } + ws.sendPayloadTransactions(t) + }, + OnGetPayload: func() { + if !ws.SkipBaseVerifications { + + // Verify the list of withdrawals returned on the payload built + // completely matches the list provided in the + // engine_forkchoiceUpdatedV2 method call + if sentList, ok := ws.WithdrawalsHistory[t.CLMock.CurrentPayloadNumber]; !ok { + t.Fatalf("FAIL (%s): Withdrawals sent list was not saved", t.TestName) + } else { + if len(sentList) != len(t.CLMock.LatestPayloadBuilt.Withdrawals) { + t.Fatalf( + "FAIL (%s): Incorrect list of withdrawals on built payload: want=%d, got=%d", + t.TestName, + len(sentList), + len(t.CLMock.LatestPayloadBuilt.Withdrawals), + ) + } + for i := 0; i < len(sentList); i++ { + if err := test.CompareWithdrawal(sentList[i], t.CLMock.LatestPayloadBuilt.Withdrawals[i]); err != nil { + t.Fatalf("FAIL (%s): Incorrect withdrawal on index %d: %v", t.TestName, i, err) } } } - }, - OnForkchoiceBroadcast: func() { - if !ws.SkipBaseVerifications { - for _, addr := range ws.WithdrawalsHistory.GetAddressesWithdrawnOnBlock(t.CLMock.LatestExecutedPayload.Number) { - // Test balance at `latest`, which should have the withdrawal applied. - withdrawableAmount, err := getWithdrawableAmount(client, addr, big.NewInt(int64(t.CLMock.LatestExecutedPayload.Number))) - if err != nil { - t.Fatalf("FAIL (%s): Error trying to get balance of token: %v, address: %v", t.TestName, err, addr.Hex()) - } + } + }, + OnForkchoiceBroadcast: func() { + if !ws.SkipBaseVerifications { + for _, addr := range ws.WithdrawalsHistory.GetAddressesWithdrawnOnBlock(t.CLMock.LatestExecutedPayload.Number) { + // Test balance at `latest`, which should have the withdrawal applied. + withdrawableAmount, err := getWithdrawableAmount(client, addr, big.NewInt(int64(t.CLMock.LatestExecutedPayload.Number))) + if err != nil { + t.Fatalf("FAIL (%s): Error trying to get balance of token: %v, address: %v", t.TestName, err, addr.Hex()) + } - expectBalanceMGNO := ws.WithdrawalsHistory.GetExpectedAccumulatedBalance(addr, t.CLMock.LatestExecutedPayload.Number) - expectBalance := libgno.UnwrapToGNO(expectBalanceMGNO) - - if withdrawableAmount.Cmp(expectBalance) != 0 { - t.Fatalf( - "FAIL (%s): Incorrect balance on account %s after withdrawals applied: want=%d, got=%d", - t.TestName, - addr, - expectBalance, - withdrawableAmount, - ) - } + expectBalanceMGNO := ws.WithdrawalsHistory.GetExpectedAccumulatedBalance(addr, t.CLMock.LatestExecutedPayload.Number) + expectBalance := libgno.UnwrapToGNO(expectBalanceMGNO) + + if withdrawableAmount.Cmp(expectBalance) != 0 { + t.Fatalf( + "FAIL (%s): Incorrect balance on account %s after withdrawals applied: want=%d, got=%d", + t.TestName, + addr, + expectBalance, + withdrawableAmount, + ) } } - }, - }) - } - - // Iterate over balance history of withdrawn accounts using RPC and - // check that the balances match expected values. - // Also check one block before the withdrawal took place, verify that - // withdrawal has not been updated. - if !ws.SkipBaseVerifications { - for block := uint64(0); block <= t.CLMock.LatestExecutedPayload.Number; block++ { - ws.WithdrawalsHistory.VerifyWithdrawals(block, big.NewInt(int64(block)), t.TestEngine) - - // Check the correct withdrawal root on past blocks - r := t.TestEngine.TestBlockByNumber(big.NewInt(int64(block))) - var expectedWithdrawalsRoot *common.Hash = nil - if block >= ws.WithdrawalsForkHeight { - calcWithdrawalsRoot := helper.ComputeWithdrawalsRoot( - ws.WithdrawalsHistory.GetWithdrawals(block), - ) - expectedWithdrawalsRoot = &calcWithdrawalsRoot } - jsWithdrawals, _ := json.MarshalIndent(ws.WithdrawalsHistory.GetWithdrawals(block), "", " ") - r.ExpectationDescription = fmt.Sprintf(` - Requested block %d to verify withdrawalsRoot with the - following withdrawals: - %s`, block, jsWithdrawals) - - r.ExpectWithdrawalsRoot(expectedWithdrawalsRoot) + }, + }) +} +// Iterate over balance history of withdrawn accounts using RPC and +// check that the balances match expected values. +// Also check one block before the withdrawal took place, verify that +// withdrawal has not been updated. +if !ws.SkipBaseVerifications { + for block := uint64(0); block <= t.CLMock.LatestExecutedPayload.Number; block++ { + ws.WithdrawalsHistory.VerifyWithdrawals(block, big.NewInt(int64(block)), t.TestEngine) + + // Check the correct withdrawal root on past blocks + r := t.TestEngine.TestBlockByNumber(big.NewInt(int64(block))) + var expectedWithdrawalsRoot *common.Hash = nil + if block >= ws.WithdrawalsForkHeight { + calcWithdrawalsRoot := helper.ComputeWithdrawalsRoot( + ws.WithdrawalsHistory.GetWithdrawals(block), + ) + expectedWithdrawalsRoot = &calcWithdrawalsRoot } + jsWithdrawals, _ := json.MarshalIndent(ws.WithdrawalsHistory.GetWithdrawals(block), "", " ") + r.ExpectationDescription = fmt.Sprintf(` + Requested block %d to verify withdrawalsRoot with the + following withdrawals: + %s`, block, jsWithdrawals) + + r.ExpectWithdrawalsRoot(expectedWithdrawalsRoot) - // Verify on `latest` - ws.WithdrawalsHistory.VerifyWithdrawals(t.CLMock.LatestExecutedPayload.Number, nil, t.TestEngine) } + + // Verify on `latest` + ws.WithdrawalsHistory.VerifyWithdrawals(t.CLMock.LatestExecutedPayload.Number, nil, t.TestEngine) +} } func getClient(t *test.Env) *ethclient.Client { @@ -1314,7 +1314,7 @@ func (ws *WithdrawalsSyncSpec) Execute(t *test.Env) { // TODO } else { // Send the FCU to trigger sync on the secondary client - loop: + loop: for { select { case <-t.TimeoutContext.Done(): @@ -1595,7 +1595,7 @@ func (ws *WithdrawalsReorgSpec) Execute(t *test.Env) { if ws.ReOrgViaSync { // Send latest sidechain payload as NewPayload + FCU and wait for sync - loop: + loop: for { r := t.TestEngine.TestEngineNewPayloadV2(sidechain[sidechainHeight]) r.ExpectNoError() @@ -1784,9 +1784,9 @@ func (ws *WithdrawalsExecutionLayerSpec) Execute(t *test.Env) { r := t.TestEngine.TestBlockByNumber(nil) r.ExpectationDescription = ` - Requested "latest" block expecting genesis to contain - withdrawalRoot=nil, because genesis.timestamp < shanghaiTime - ` + Requested "latest" block expecting genesis to contain + withdrawalRoot=nil, because genesis.timestamp < shanghaiTime + ` r.ExpectWithdrawalsRoot(nil) // Produce any blocks necessary to reach withdrawals fork