Skip to content

Commit

Permalink
changed providerKeeper.GetProposedConsumerChain to return a bool
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Feb 8, 2024
1 parent bef8202 commit 3402f75
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 6 additions & 1 deletion x/ccv/provider/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (h Hooks) AfterProposalVotingPeriodEnded(ctx sdk.Context, proposalID uint64
func (h Hooks) AfterProposalDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) {
}

// AfterProposalVote opts in validators that vote YES (with 100% weight) on a `ConsumerAdditionProposal`. If a
// validator votes multiple times, only the last vote would be considered on whether the validator is opted in or not.
func (h Hooks) AfterProposalVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) {
validator, found := h.k.stakingKeeper.GetValidator(ctx, voterAddr.Bytes())
if !found {
Expand All @@ -186,7 +188,10 @@ func (h Hooks) AfterProposalVote(ctx sdk.Context, proposalID uint64, voterAddr s
return
}

chainID := h.k.GetProposedConsumerChain(ctx, proposalID)
chainID, found := h.k.GetProposedConsumerChain(ctx, proposalID)
if !found {
return
}

vote, found := h.k.govKeeper.GetVote(ctx, proposalID, voterAddr)
if !found {
Expand Down
6 changes: 4 additions & 2 deletions x/ccv/provider/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ func TestAfterPropSubmissionAndVotingPeriodEnded(t *testing.T) {

k.Hooks().AfterProposalSubmission(ctx, prop.Id)
// verify that the proposal ID is created
require.NotEmpty(t, k.GetProposedConsumerChain(ctx, prop.Id))
_, found := k.GetProposedConsumerChain(ctx, prop.Id)
require.True(t, found)

k.Hooks().AfterProposalVotingPeriodEnded(ctx, prop.Id)
// verify that the proposal ID is deleted
require.Empty(t, k.GetProposedConsumerChain(ctx, prop.Id))
_, found = k.GetProposedConsumerChain(ctx, prop.Id)
require.False(t, found)
}

func TestGetConsumerAdditionLegacyPropFromProp(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ func (k Keeper) SetProposedConsumerChain(ctx sdk.Context, chainID string, propos
}

// GetProposedConsumerChain returns the proposed chainID for the given consumerAddition proposal ID.
func (k Keeper) GetProposedConsumerChain(ctx sdk.Context, proposalID uint64) string {
func (k Keeper) GetProposedConsumerChain(ctx sdk.Context, proposalID uint64) (string, bool) {
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.ProposedConsumerChainKey(proposalID)))
consumerChain := store.Get(types.ProposedConsumerChainKey(proposalID))
return string(consumerChain), consumerChain != nil
}

// DeleteProposedConsumerChainInStore deletes the consumer chainID from store
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestSetProposedConsumerChains(t *testing.T) {

for _, test := range tests {
providerKeeper.SetProposedConsumerChain(ctx, test.chainID, test.proposalID)
cID := providerKeeper.GetProposedConsumerChain(ctx, test.proposalID)
cID, _ := providerKeeper.GetProposedConsumerChain(ctx, test.proposalID)
require.Equal(t, cID, test.chainID)
}
}
Expand All @@ -574,9 +574,9 @@ func TestDeleteProposedConsumerChainInStore(t *testing.T) {
for _, test := range tests {
providerKeeper.SetProposedConsumerChain(ctx, test.chainID, test.proposalID)
providerKeeper.DeleteProposedConsumerChainInStore(ctx, test.deleteProposalID)
cID := providerKeeper.GetProposedConsumerChain(ctx, test.proposalID)
cID, found := providerKeeper.GetProposedConsumerChain(ctx, test.proposalID)
if test.ok {
require.Equal(t, cID, "")
require.False(t, found)
} else {
require.Equal(t, cID, test.chainID)
}
Expand Down

0 comments on commit 3402f75

Please sign in to comment.