Skip to content

Commit

Permalink
add TestParseProposedConsumerChainKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaru Wang committed Sep 21, 2023
1 parent 956b4cc commit f193361
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) {
// does not end.
func (k Keeper) SetChainsInProposal(ctx sdk.Context, chainID string, proposalID uint64) {
store := ctx.KVStore(k.storeKey)
store.Set(types.ChainInProposalKey(chainID, proposalID), []byte(chainID))
store.Set(types.ProposedConsumerChainKey(chainID, proposalID), []byte(chainID))
}

// DeleteChainsInProposal deletes the consumer chainID from store
// which is in gov consumerAddition proposal
func (k Keeper) DeleteChainsInProposal(ctx sdk.Context, chainID string, proposalID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.ChainInProposalKey(chainID, proposalID))
store.Delete(types.ProposedConsumerChainKey(chainID, proposalID))
}

// GetAllProposedConsumerChainIDs get consumer chainId in gov consumerAddition proposal before voting period ends.
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ func VSCMaturedHandledThisBlockKey() []byte {
return []byte{VSCMaturedHandledThisBlockBytePrefix}
}

// ChainInProposalKey returns the key of proposed consumer chainId in consumerAddition gov proposal before voting finishes, the stored key format is prefix|len(chainID)|chainID|proposalID
func ChainInProposalKey(chainID string, proposalID uint64) []byte {
// ProposedConsumerChainKey returns the key of proposed consumer chainId in consumerAddition gov proposal before voting finishes, the stored key format is prefix|len(chainID)|chainID|proposalID
func ProposedConsumerChainKey(chainID string, proposalID uint64) []byte {
chainIdL := len(chainID)
return ccvtypes.AppendMany(
[]byte{ProposedConsumerChainByteKey},
Expand Down
21 changes: 21 additions & 0 deletions x/ccv/provider/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,24 @@ func TestKeysWithUint64Payload(t *testing.T) {
}
}
}

func TestParseProposedConsumerChainKey(t *testing.T) {
tests := []struct {
prefix byte
chainID string
proposalID uint64
}{
{chainID: "1", proposalID: 1},
{chainID: "some other ID", proposalID: 12},
{chainID: "some other other chain ID", proposalID: 123},
}

for _, test := range tests {
key := providertypes.ProposedConsumerChainKey(test.chainID, test.proposalID)
cID, pID, err := providertypes.ParseProposedConsumerChainKey(
providertypes.ProposedConsumerChainByteKey, key)
require.NoError(t, err)
require.Equal(t, cID, test.chainID)
require.Equal(t, pID, test.proposalID)
}
}

0 comments on commit f193361

Please sign in to comment.