Skip to content

Commit

Permalink
brought one more test from #1732
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Jun 28, 2024
1 parent 2142d3a commit 9228132
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion x/ccv/provider/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func TestAssignConsensusKeyForConsumerChain(t *testing.T) {
providerCryptoId := testcrypto.NewCryptoIdentityFromIntSeed(0)
providerConsAddr := providerCryptoId.ProviderConsAddress()

// a different providerConsAddr, to simulate different validators having assigned keys
providerCryptoId2 := testcrypto.NewCryptoIdentityFromIntSeed(10)
providerConsAddr2 := providerCryptoId2.ProviderConsAddress()

consumerCryptoId := testcrypto.NewCryptoIdentityFromIntSeed(1)
consumerConsAddr := consumerCryptoId.ConsumerConsAddress()
consumerKeyBz := base64.StdEncoding.EncodeToString(consumerCryptoId.ConsensusSDKPubKey().Bytes())
Expand Down Expand Up @@ -101,7 +105,7 @@ func TestAssignConsensusKeyForConsumerChain(t *testing.T) {
chainID: "chainid",
},
{
name: "fail: consumer key in use",
name: "fail: consumer key in use by the same validator",
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
Expand All @@ -124,6 +128,32 @@ func TestAssignConsensusKeyForConsumerChain(t *testing.T) {
expError: true,
chainID: "chainid",
},
{
name: "fail: consumer key in use by other validator",
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetPendingConsumerAdditionProp(ctx, &providertypes.ConsumerAdditionProposal{
ChainId: "chainid",
})

// Use the consumer key already used by some other validator
k.SetValidatorByConsumerAddr(ctx, "chainid", consumerConsAddr, providerConsAddr2)

gomock.InOrder(
mocks.MockStakingKeeper.EXPECT().GetValidator(
ctx, providerCryptoId.SDKValOpAddress(),
// validator should not be missing
).Return(providerCryptoId.SDKStakingValidator(), true).Times(1),
mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr(ctx,
consumerConsAddr.ToSdkConsAddr(),
// return false - no other validator uses the consumer key to validate *on the provider*
).Return(stakingtypes.Validator{}, false),
)
},
expError: true,
chainID: "chainid",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 9228132

Please sign in to comment.