From 18d70dfa64e5f4b8858a83abbf522cb9c9464958 Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Fri, 3 May 2024 01:16:07 -0600 Subject: [PATCH] fix waitForSequencer usage --- system_tests/program_norace_test.go | 30 +++++++++++++++++++++++------ system_tests/program_test.go | 6 ++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/system_tests/program_norace_test.go b/system_tests/program_norace_test.go index 8e95596b2..56b204671 100644 --- a/system_tests/program_norace_test.go +++ b/system_tests/program_norace_test.go @@ -25,6 +25,26 @@ import ( "github.com/offchainlabs/nitro/util/testhelpers" ) +func blockIsEmpty(block *types.Block) bool { + for _, tx := range block.Transactions() { + if tx.Type() != types.ArbitrumInternalTxType { + return false + } + } + return true +} + +func nonEmptyBlockHeight(t *testing.T, builder *NodeBuilder) uint64 { + latestBlock, err := builder.L2.Client.BlockByNumber(builder.ctx, nil) + Require(t, err) + for blockIsEmpty(latestBlock) { + prior := arbmath.BigSubByUint(latestBlock.Number(), 1) + latestBlock, err = builder.L2.Client.BlockByNumber(builder.ctx, prior) + Require(t, err) + } + return latestBlock.NumberU64() +} + // used in program test func validateBlocks( t *testing.T, start uint64, jit bool, builder *NodeBuilder, @@ -34,9 +54,7 @@ func validateBlocks( start = 1 } - blockHeight, err := builder.L2.Client.BlockNumber(builder.ctx) - Require(t, err) - + blockHeight := nonEmptyBlockHeight(t, builder) blocks := []uint64{} for i := start; i <= blockHeight; i++ { blocks = append(blocks, i) @@ -50,18 +68,18 @@ func validateBlockRange( builder *NodeBuilder, ) { ctx := builder.ctx - waitForSequencer(t, builder, arbmath.MaxInt(blocks...)) - blockHeight, err := builder.L2.Client.BlockNumber(ctx) - Require(t, err) // validate everything if jit { + blockHeight := nonEmptyBlockHeight(t, builder) blocks = []uint64{} for i := uint64(1); i <= blockHeight; i++ { blocks = append(blocks, i) } } + waitForSequencer(t, builder, arbmath.MaxInt(blocks...)) + success := true wasmModuleRoot := currentRootModule(t) for _, block := range blocks { diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 319e0bda8..1e033cecf 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -930,7 +930,7 @@ func testMemory(t *testing.T, jit bool) { validateBlocks(t, 3, jit, builder) t.Skip("Succeeded up to here. Diagnose tests with larger numbers of blocks later.") } - /*// check edge case where memory doesn't require `pay_for_memory_grow` + // check edge case where memory doesn't require `pay_for_memory_grow` tx = l2info.PrepareTxTo("Owner", &growFixed, 1e9, nil, args) ensure(tx, l2client.SendTransaction(ctx, tx)) @@ -965,9 +965,7 @@ func testMemory(t *testing.T, jit bool) { } else { expectFailure(memWrite, args, nil) } - }*/ - _ = memWrite - _ = growFixed + } validateBlocks(t, 3, jit, builder) }