Skip to content

Commit

Permalink
fix(e2e/test): fetch all aggregates even if more than limit (#318)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
corverroos authored Feb 16, 2024
1 parent 110378a commit 507ea5b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/e2e/tests/attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}

0 comments on commit 507ea5b

Please sign in to comment.