From f1933617affdee348978e5b120481322c9a36285 Mon Sep 17 00:00:00 2001 From: Yaru Wang Date: Thu, 21 Sep 2023 12:38:19 +0200 Subject: [PATCH] add TestParseProposedConsumerChainKey --- x/ccv/provider/keeper/keeper.go | 4 ++-- x/ccv/provider/types/keys.go | 4 ++-- x/ccv/provider/types/keys_test.go | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 7e01fef383..7984bfe6ab 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -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. diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index de441aad9a..caddfff5fe 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -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}, diff --git a/x/ccv/provider/types/keys_test.go b/x/ccv/provider/types/keys_test.go index d08ea3a7bb..e137817daa 100644 --- a/x/ccv/provider/types/keys_test.go +++ b/x/ccv/provider/types/keys_test.go @@ -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) + } +}