From 507ea5bbb386092690e3207c5f694da8ff1cfabe Mon Sep 17 00:00:00 2001 From: corver Date: Fri, 16 Feb 2024 19:24:21 +0200 Subject: [PATCH] fix(e2e/test): fetch all aggregates even if more than limit (#318) Fixes flapping e2e test if submissions were slow and halo has more than 200 blocks. In which case we only fetch 100 and the test fails. Now we fetch all blocks. task: none --- test/e2e/tests/attestations_test.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/test/e2e/tests/attestations_test.go b/test/e2e/tests/attestations_test.go index 560cc7612..9efc32408 100644 --- a/test/e2e/tests/attestations_test.go +++ b/test/e2e/tests/attestations_test.go @@ -4,7 +4,9 @@ import ( "context" "testing" + "github.com/omni-network/omni/lib/cchain" "github.com/omni-network/omni/lib/cchain/provider" + "github.com/omni-network/omni/lib/xchain" e2e "github.com/cometbft/cometbft/test/e2e/pkg" @@ -26,12 +28,30 @@ func TestApprovedAttestations(t *testing.T) { height, err := portal.Client.BlockNumber(ctx) require.NoError(t, err) - totalBlocks := height - portal.Chain.DeployHeight - - aggs, err := cprov.ApprovedFrom(ctx, portal.Chain.ID, portal.Chain.DeployHeight) + aggs, err := fetchAllAggs(ctx, cprov, portal.Chain.ID, portal.Chain.DeployHeight) require.NoError(t, err) + totalBlocks := height - portal.Chain.DeployHeight require.GreaterOrEqual(t, len(aggs), int(totalBlocks/2)) // Assert that at least half of the blocks are approved } }, nil) } + +func fetchAllAggs(ctx context.Context, cprov cchain.Provider, chainID, from uint64) ([]xchain.AggAttestation, error) { + var resp []xchain.AggAttestation + for { + aggs, err := cprov.ApprovedFrom(ctx, chainID, from) + if err != nil { + return nil, err + } + if len(aggs) == 0 { // No more attestation to fetch + break + } + resp = append(resp, aggs...) + + // Update the from height to fetch the next batch of attestation + from = aggs[len(aggs)-1].BlockHeight + 1 + } + + return resp, nil +}