Skip to content

Commit

Permalink
Merge branch 'params-upgrade' into cosmos-v0.47-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Apr 22, 2024
2 parents eb76373 + 309745d commit 3b4d35c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
14 changes: 7 additions & 7 deletions testutil/keeper/mocks/emissions/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func DistributeObserverRewards(
return err
}

maturityBlocks := params.BallotMaturityBlocks
list, found := keeper.GetObserverKeeper().GetBallotList(ctx, ctx.BlockHeight()-maturityBlocks)
list, found := keeper.GetObserverKeeper().GetMaturedBallots(ctx, params.BallotMaturityBlocks)
ballotIdentifiers := []string{}
if found {
ballotIdentifiers = list.BallotsIndexList
Expand Down
2 changes: 1 addition & 1 deletion x/emissions/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AccountKeeper interface {

type ObserverKeeper interface {
GetBallot(ctx sdk.Context, index string) (val observertypes.Ballot, found bool)
GetBallotList(ctx sdk.Context, height int64) (val observertypes.BallotListForHeight, found bool)
GetMaturedBallots(ctx sdk.Context, maturityBlocks int64) (val observertypes.BallotListForHeight, found bool)
}

// BankKeeper defines the expected interface needed to retrieve account balances.
Expand Down
4 changes: 4 additions & 0 deletions x/observer/keeper/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (k Keeper) GetBallotList(ctx sdk.Context, height int64) (val types.BallotLi
return val, true
}

func (k Keeper) GetMaturedBallots(ctx sdk.Context, maturityBlocks int64) (val types.BallotListForHeight, found bool) {
return k.GetBallotList(ctx, ctx.BlockHeight()-maturityBlocks)
}

func (k Keeper) GetAllBallots(ctx sdk.Context) (voters []*types.Ballot) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VoterKey))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
Expand Down
23 changes: 23 additions & 0 deletions x/observer/keeper/ballot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ func TestKeeper_GetBallotList(t *testing.T) {
require.Equal(t, identifier, list.BallotsIndexList[0])
}

func TestKeeper_GetMaturedBallots(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)
identifier := sample.ZetaIndex(t)
b := &types.Ballot{
Index: "",
BallotIdentifier: identifier,
VoterList: nil,
ObservationType: 0,
BallotThreshold: sdk.Dec{},
BallotStatus: 0,
BallotCreationHeight: 1,
}
ctx = ctx.WithBlockHeight(2)
_, found := k.GetMaturedBallots(ctx, 1)
require.False(t, found)

k.AddBallotToList(ctx, *b)
list, found := k.GetMaturedBallots(ctx, 1)
require.True(t, found)
require.Equal(t, 1, len(list.BallotsIndexList))
require.Equal(t, identifier, list.BallotsIndexList[0])
}

func TestKeeper_GetAllBallots(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)
identifier := sample.ZetaIndex(t)
Expand Down

0 comments on commit 3b4d35c

Please sign in to comment.