From 309745d52aac9fdd4c3e4961b42fb428be963f12 Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 22 Apr 2024 17:24:31 +0200 Subject: [PATCH] PR comment --- testutil/keeper/mocks/emissions/observer.go | 14 ++++++------- x/emissions/abci.go | 3 +-- x/emissions/types/expected_keepers.go | 2 +- x/observer/keeper/ballot.go | 4 ++++ x/observer/keeper/ballot_test.go | 23 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/testutil/keeper/mocks/emissions/observer.go b/testutil/keeper/mocks/emissions/observer.go index f1c40046f2..594f090907 100644 --- a/testutil/keeper/mocks/emissions/observer.go +++ b/testutil/keeper/mocks/emissions/observer.go @@ -43,27 +43,27 @@ func (_m *EmissionObserverKeeper) GetBallot(ctx types.Context, index string) (ob return r0, r1 } -// GetBallotList provides a mock function with given fields: ctx, height -func (_m *EmissionObserverKeeper) GetBallotList(ctx types.Context, height int64) (observertypes.BallotListForHeight, bool) { - ret := _m.Called(ctx, height) +// GetMaturedBallots provides a mock function with given fields: ctx, maturityBlocks +func (_m *EmissionObserverKeeper) GetMaturedBallots(ctx types.Context, maturityBlocks int64) (observertypes.BallotListForHeight, bool) { + ret := _m.Called(ctx, maturityBlocks) if len(ret) == 0 { - panic("no return value specified for GetBallotList") + panic("no return value specified for GetMaturedBallots") } var r0 observertypes.BallotListForHeight var r1 bool if rf, ok := ret.Get(0).(func(types.Context, int64) (observertypes.BallotListForHeight, bool)); ok { - return rf(ctx, height) + return rf(ctx, maturityBlocks) } if rf, ok := ret.Get(0).(func(types.Context, int64) observertypes.BallotListForHeight); ok { - r0 = rf(ctx, height) + r0 = rf(ctx, maturityBlocks) } else { r0 = ret.Get(0).(observertypes.BallotListForHeight) } if rf, ok := ret.Get(1).(func(types.Context, int64) bool); ok { - r1 = rf(ctx, height) + r1 = rf(ctx, maturityBlocks) } else { r1 = ret.Get(1).(bool) } diff --git a/x/emissions/abci.go b/x/emissions/abci.go index 258c6f6ecc..bd1831aa48 100644 --- a/x/emissions/abci.go +++ b/x/emissions/abci.go @@ -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 diff --git a/x/emissions/types/expected_keepers.go b/x/emissions/types/expected_keepers.go index a71a288e21..fc9c6c022d 100644 --- a/x/emissions/types/expected_keepers.go +++ b/x/emissions/types/expected_keepers.go @@ -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. diff --git a/x/observer/keeper/ballot.go b/x/observer/keeper/ballot.go index 7278c4d05d..5a05a5e76b 100644 --- a/x/observer/keeper/ballot.go +++ b/x/observer/keeper/ballot.go @@ -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{}) diff --git a/x/observer/keeper/ballot_test.go b/x/observer/keeper/ballot_test.go index d2644a3801..e7511a3fe4 100644 --- a/x/observer/keeper/ballot_test.go +++ b/x/observer/keeper/ballot_test.go @@ -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)