Skip to content

Commit

Permalink
add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 20, 2024
1 parent 3c38438 commit 5171ebd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

* [3170](https://github.com/zeta-chain/node/pull/3170) - revamp TSS package in zetaclient
* [3291](https://github.com/zeta-chain/node/pull/3291) - revamp zetaclient initialization (+ graceful shutdown)
* [2863](https://github.com/zeta-chain/node/pull/2863) - refactor zetacore to delete matured ballots and add a migration script to remove all old ballots.

### Fixes

Expand Down
6 changes: 4 additions & 2 deletions x/observer/keeper/grpc_query_ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ func (k Keeper) Ballots(goCtx context.Context, req *types.QueryBallotsRequest) (
if req.Pagination == nil {
req.Pagination = &query.PageRequest{}
}
if req.Pagination.Limit == 0 || req.Pagination.Limit > 100 {

if req.Pagination.Limit > 100 {
req.Pagination.Limit = 100
}

// The ballots are not sorted in any particular order therefore this query only has limited usefulness
// if the number of ballots is too large
pageRes, err := query.Paginate(ballotStore, req.Pagination, func(_ []byte, value []byte) error {
var ballot types.Ballot
if err := k.cdc.Unmarshal(value, &ballot); err != nil {
Expand Down
59 changes: 56 additions & 3 deletions x/observer/keeper/grpc_query_ballot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

keepertest "github.com/zeta-chain/node/testutil/keeper"
Expand Down Expand Up @@ -135,6 +136,60 @@ func TestKeeper_BallotByIdentifier(t *testing.T) {
BallotStatus: ballot.BallotStatus,
}, res)
})

t.Run("should return 100 ballots if more exist and limit is not provided", func(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
numOfBallots := 1000

ballots := make([]types.Ballot, numOfBallots)
for i := 0; i < numOfBallots; i++ {
ballot := types.Ballot{
Index: "",
BallotIdentifier: fmt.Sprintf("index-%d", i),
VoterList: []string{sample.AccAddress()},
Votes: []types.VoteType{types.VoteType_SuccessObservation},
BallotStatus: types.BallotStatus_BallotInProgress,
BallotCreationHeight: 1,
BallotThreshold: sdk.MustNewDecFromStr("0.5"),
}
k.SetBallot(ctx, &ballot)
ballots[i] = ballot
}

res, err := k.Ballots(wctx, &types.QueryBallotsRequest{})
require.NoError(t, err)
require.Len(t, res.Ballots, 100)
})

t.Run("should return limit number of ballots if limit is provided", func(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
numOfBallots := 1000

ballots := make([]types.Ballot, numOfBallots)
for i := 0; i < numOfBallots; i++ {
ballot := types.Ballot{
Index: "",
BallotIdentifier: fmt.Sprintf("index-%d", i),
VoterList: []string{sample.AccAddress()},
Votes: []types.VoteType{types.VoteType_SuccessObservation},
BallotStatus: types.BallotStatus_BallotInProgress,
BallotCreationHeight: 1,
BallotThreshold: sdk.MustNewDecFromStr("0.5"),
}
k.SetBallot(ctx, &ballot)
ballots[i] = ballot
}

res, err := k.Ballots(wctx, &types.QueryBallotsRequest{
Pagination: &query.PageRequest{
Limit: 10,
},
})
require.NoError(t, err)
require.Len(t, res.Ballots, 10)
})
}

func TestKeeper_Ballots(t *testing.T) {
Expand All @@ -153,9 +208,7 @@ func TestKeeper_Ballots(t *testing.T) {

res, err := k.Ballots(wctx, &types.QueryBallotsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryBallotsResponse{
Ballots: []types.Ballot{},
}, res)
require.Empty(t, res.Ballots)
})

t.Run("should return all ballots", func(t *testing.T) {
Expand Down

0 comments on commit 5171ebd

Please sign in to comment.