Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add check in e2e test to ensure deletion of stale ballots #3503

Merged
merged 12 commits into from
Feb 11, 2025
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Tests

* [3430](https://github.com/zeta-chain/node/pull/3430) - add simulation test for MsgWithDrawEmission
* [3503](https://github.com/zeta-chain/node/pull/3503) - add check in e2e test to ensure deletion of stale ballots

## v27.0.1

Expand Down
2 changes: 2 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {

// Verify that the balance of restricted address is zero
deployerRunner.EnsureZeroBalanceOnRestrictedAddressZEVM()
// Verify that there are no stale ballots left over after tests complete
deployerRunner.EnsureNoStaleBallots()

// print and validate report
networkReport, err := deployerRunner.GenerateNetworkReport()
Expand Down
6 changes: 6 additions & 0 deletions docs/cli/zetacored/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -6826,12 +6826,18 @@ zetacored query observer list-ballots [flags]
### Options

```
--count-total count total number of records in list-ballots to query for
--grpc-addr string the gRPC endpoint to use for this chain
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for list-ballots
--limit uint pagination limit of list-ballots to query for (default 100)
--node string [host]:[port] to CometBFT RPC interface for this chain
--offset uint pagination offset of list-ballots to query for
-o, --output string Output format (text|json)
--page uint pagination page of list-ballots to query for. This sets offset to a multiple of limit (default 1)
--page-key string pagination page-key of list-ballots to query for
--reverse results are sorted in descending order
```

### Options inherited from parent commands
Expand Down
16 changes: 16 additions & 0 deletions e2e/runner/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/zeta-chain/node/testutil/sample"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
emissionstypes "github.com/zeta-chain/node/x/emissions/types"
"github.com/zeta-chain/node/x/observer/types"
)

// EnsureNoTrackers ensures that there are no trackers left on zetacore
Expand Down Expand Up @@ -59,3 +61,17 @@ func ensureZRC20ZeroBalance(r *E2ERunner, zrc20 *zrc20.ZRC20, address ethcommon.
fmt.Sprintf("the balance of address %s should be zero on ZRC20: %s", address, zrc20Name),
)
}

// EnsureNoStaleBallots ensures that there are no stale ballots left on the chain.
func (r *E2ERunner) EnsureNoStaleBallots() {
ballotsRes, err := r.ObserverClient.Ballots(r.Ctx, &types.QueryBallotsRequest{})
require.NoError(r, err)
currentBlockHeight, err := r.Clients.Zetacore.GetBlockHeight(r.Ctx)
require.NoError(r, err)
emissionsParams, err := r.EmissionsClient.Params(r.Ctx, &emissionstypes.QueryParamsRequest{})
require.NoError(r, err)
staleBlockStart := currentBlockHeight - emissionsParams.Params.BallotMaturityBlocks
firstBallotCreationHeight := ballotsRes.Ballots[0].BallotCreationHeight

require.Greater(r, firstBallotCreationHeight, staleBlockStart, "there should be no stale ballots")
}
1 change: 1 addition & 0 deletions x/observer/client/cli/query_ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ func CmdAllBallots() *cobra.Command {
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
return cmd
}
5 changes: 5 additions & 0 deletions x/observer/keeper/grpc_query_ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"sort"

"cosmossdk.io/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -83,6 +84,10 @@ func (k Keeper) Ballots(goCtx context.Context, req *types.QueryBallotsRequest) (
return nil
})

sort.Slice(ballots, func(i, j int) bool {
return ballots[i].BallotCreationHeight < ballots[j].BallotCreationHeight
})

if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
7 changes: 6 additions & 1 deletion x/observer/keeper/grpc_query_ballot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestKeeper_Ballots(t *testing.T) {
VoterList: []string{sample.AccAddress()},
Votes: []types.VoteType{types.VoteType_SuccessObservation},
BallotStatus: types.BallotStatus_BallotInProgress,
BallotCreationHeight: 1,
BallotCreationHeight: 1 + int64(i),
BallotThreshold: sdkmath.LegacyMustNewDecFromStr("0.5"),
}
k.SetBallot(ctx, &ballot)
Expand All @@ -234,5 +234,10 @@ func TestKeeper_Ballots(t *testing.T) {
res, err := k.Ballots(wctx, &types.QueryBallotsRequest{})
require.NoError(t, err)
require.ElementsMatch(t, ballots, res.Ballots)

firstBallotCreationHeight := res.Ballots[0].BallotCreationHeight
for _, ballot := range res.Ballots {
require.GreaterOrEqual(t, ballot.BallotCreationHeight, firstBallotCreationHeight)
}
})
}
Loading