Skip to content

Commit

Permalink
added one more test case
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed May 17, 2024
1 parent 6e554ff commit 4628cf2
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,33 @@ func TestBeginBlockInit(t *testing.T) {
nil,
nil,
).(*providertypes.ConsumerAdditionProposal),
providertypes.NewConsumerAdditionProposal(
"title", "opt-in chain with no validator opted in", "chain6", clienttypes.NewHeight(3, 4), []byte{}, []byte{},
now.Add(-time.Minute).UTC(),
"0.75",
10,
"",
10000,
100000000000,
100000000000,
100000000000,
0,
0,
0,
nil,
nil,
).(*providertypes.ConsumerAdditionProposal),
}

// Expect client creation for only the first, second, and fifth proposals (spawn time already passed and valid)
expectedCalls := testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks, "chain1", clienttypes.NewHeight(3, 4))
expectedCalls = append(expectedCalls, testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks, "chain2", clienttypes.NewHeight(3, 4))...)
expectedCalls = append(expectedCalls, testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks, "chain5", clienttypes.NewHeight(3, 4))...)

// The sixth proposal would have spawn time passed and hence needs the mocks but the client will not be
// created because `chain6` is an Opt In chain and has no validator opted in
expectedCalls = append(expectedCalls, testkeeper.GetMocksForCreateConsumerClient(ctx, &mocks, "chain6", clienttypes.NewHeight(3, 4))...)

gomock.InOrder(expectedCalls...)

for _, prop := range pendingProps {
Expand Down Expand Up @@ -1067,10 +1087,30 @@ func TestBeginBlockInit(t *testing.T) {
_, found = providerKeeper.GetPendingConsumerAdditionProp(
ctx, pendingProps[4].SpawnTime, pendingProps[4].ChainId)
require.False(t, found)
// sixth proposal was successfully executed and hence consumer genesis was created
// fifth proposal was successfully executed and hence consumer genesis was created
_, found = providerKeeper.GetConsumerGenesis(ctx, pendingProps[4].ChainId)
require.True(t, found)

// sixth proposal corresponds to an Opt-In chain with no opted-in validators and hence the
// proposal is not successful
_, found = providerKeeper.GetPendingConsumerAdditionProp(
ctx, pendingProps[5].SpawnTime, pendingProps[5].ChainId)
// the proposal was dropped and deleted
require.False(t, found)
// no consumer genesis is created
_, found = providerKeeper.GetConsumerGenesis(ctx, pendingProps[5].ChainId)
require.False(t, found)
// no consumer client is associated with this chain
_, found = providerKeeper.GetConsumerClientId(ctx, pendingProps[5].ChainId)
require.False(t, found)
// no fields should be set for this (check some of them)
_, found = providerKeeper.GetTopN(ctx, pendingProps[5].ChainId)
require.False(t, found)
_, found = providerKeeper.GetValidatorsPowerCap(ctx, pendingProps[5].ChainId)
require.False(t, found)
_, found = providerKeeper.GetValidatorSetCap(ctx, pendingProps[5].ChainId)
require.False(t, found)

// test that Top N is set correctly
require.True(t, providerKeeper.IsTopN(ctx, "chain1"))
topN, found := providerKeeper.GetTopN(ctx, "chain1")
Expand Down

0 comments on commit 4628cf2

Please sign in to comment.