Skip to content

Commit 06e66fb

Browse files
authored
test: improve check for EnsureNoStaleBallots to ignore Pending Ballots (#3627)
* improve check for EnsureNoStaleBallots to ignore Pending Ballots * break loop when ballot is found * ignore if no ballots are found * format code
1 parent 099f8df commit 06e66fb

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

e2e/runner/require.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/zeta-chain/node/testutil/sample"
1313
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
14+
emissionstypes "github.com/zeta-chain/node/x/emissions/types"
15+
"github.com/zeta-chain/node/x/observer/types"
1416
)
1517

1618
// EnsureNoTrackers ensures that there are no trackers left on zetacore
@@ -62,18 +64,27 @@ func ensureZRC20ZeroBalance(r *E2ERunner, zrc20 *zrc20.ZRC20, address ethcommon.
6264

6365
// EnsureNoStaleBallots ensures that there are no stale ballots left on the chain.
6466
func (r *E2ERunner) EnsureNoStaleBallots() {
65-
// TODO: fix
66-
//https://github.com/zeta-chain/node/issues/3626
67-
//ballotsRes, err := r.ObserverClient.Ballots(r.Ctx, &types.QueryBallotsRequest{})
68-
//require.NoError(r, err)
69-
//currentBlockHeight, err := r.Clients.Zetacore.GetBlockHeight(r.Ctx)
70-
//require.NoError(r, err)
71-
//emissionsParams, err := r.EmissionsClient.Params(r.Ctx, &emissionstypes.QueryParamsRequest{})
72-
//require.NoError(r, err)
73-
//staleBlockStart := currentBlockHeight - emissionsParams.Params.BallotMaturityBlocks
74-
//if len(ballotsRes.Ballots) < 1 {
75-
// return
76-
//}
77-
//firstBallotCreationHeight := ballotsRes.Ballots[0].BallotCreationHeight
78-
//require.GreaterOrEqual(r, firstBallotCreationHeight, staleBlockStart, "there should be no stale ballots")
67+
ballotsRes, err := r.ObserverClient.Ballots(r.Ctx, &types.QueryBallotsRequest{})
68+
require.NoError(r, err)
69+
currentBlockHeight, err := r.Clients.Zetacore.GetBlockHeight(r.Ctx)
70+
require.NoError(r, err)
71+
emissionsParams, err := r.EmissionsClient.Params(r.Ctx, &emissionstypes.QueryParamsRequest{})
72+
require.NoError(r, err)
73+
staleBlockStart := currentBlockHeight - emissionsParams.Params.BallotMaturityBlocks
74+
if len(ballotsRes.Ballots) < 1 {
75+
return
76+
}
77+
firstBallotCreationHeight := int64(0)
78+
79+
for _, ballot := range ballotsRes.Ballots {
80+
if ballot.IsFinalized() {
81+
firstBallotCreationHeight = ballot.BallotCreationHeight
82+
break
83+
}
84+
}
85+
86+
if firstBallotCreationHeight == 0 {
87+
return
88+
}
89+
require.GreaterOrEqual(r, firstBallotCreationHeight, staleBlockStart, "there should be no stale ballots")
7990
}

0 commit comments

Comments
 (0)