Skip to content

Commit

Permalink
Remove helper function in favor of using directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Aug 21, 2023
1 parent 92e37d8 commit 45867c2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
5 changes: 3 additions & 2 deletions testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func GetMocksForSetConsumerChain(ctx sdk.Context, mocks *MockedKeepers,
}
}

// GetMocksForStopConsumerChain returns mock expectations needed to call StopConsumerChain().
func GetMocksForStopConsumerChain(ctx sdk.Context, mocks *MockedKeepers) []*gomock.Call {
// GetMocksForStopConsumerChainWithCloseChannel returns mock expectations needed to call StopConsumerChain() when
// `closeChan` is true.
func GetMocksForStopConsumerChainWithCloseChannel(ctx sdk.Context, mocks *MockedKeepers) []*gomock.Call {
dummyCap := &capabilitytypes.Capability{}
return []*gomock.Call{
mocks.MockChannelKeeper.EXPECT().GetChannel(gomock.Any(), types.ProviderPortID, "channelID").Return(
Expand Down
9 changes: 1 addition & 8 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func GetNewVSCMaturedPacketData() types.VSCMaturedPacketData {
// which assert that a consumer chain was properly setup to be later stopped from `StopConsumerChain`.
// Note: This function only setups and tests that we correctly setup a consumer chain that we could later stop when
// calling `StopConsumerChain` -- this does NOT necessarily mean that the consumer chain is stopped.
// Also see `SetupForStoppingConsumerChainChannel` and `TestProviderStateIsCleanedAfterConsumerChainIsStopped`.
// Also see `TestProviderStateIsCleanedAfterConsumerChainIsStopped`.
func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,
providerKeeper *providerkeeper.Keeper, mocks MockedKeepers,
) {
Expand All @@ -228,13 +228,6 @@ func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,
require.NoError(t, err)
}

// SetupForStoppingConsumerChainChannel registers expected mock calls which assert that the channel to the consumer
// chain is closed. To be used when we test that `StopConsumerChain` is called with `closeChan` set to `true`.
func SetupForStoppingConsumerChainChannel(t *testing.T, ctx sdk.Context, mocks MockedKeepers) {
t.Helper()
gomock.InOrder(GetMocksForStopConsumerChain(ctx, &mocks)...)
}

// TestProviderStateIsCleanedAfterConsumerChainIsStopped executes test assertions for the provider's state being cleaned
// after a stopped consumer chain.
func TestProviderStateIsCleanedAfterConsumerChainIsStopped(t *testing.T, ctx sdk.Context, providerKeeper providerkeeper.Keeper,
Expand Down
16 changes: 11 additions & 5 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ func TestHandleConsumerRemovalProposal(t *testing.T) {
// meaning no external keeper methods are allowed to be called.
if tc.expAppendProp {
testkeeper.SetupForStoppingConsumerChain(t, ctx, &providerKeeper, mocks)
testkeeper.SetupForStoppingConsumerChainChannel(t, ctx, mocks)

// assert mocks for expected calls to `StopConsumerChain` when closing the underlying channel
gomock.InOrder(testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)
}

tc.setupMocks(ctx, providerKeeper, tc.prop.ChainId)
Expand Down Expand Up @@ -528,7 +530,9 @@ func TestStopConsumerChain(t *testing.T) {
description: "valid stop of consumer chain, throttle related queues are cleaned",
setup: func(ctx sdk.Context, providerKeeper *providerkeeper.Keeper, mocks testkeeper.MockedKeepers) {
testkeeper.SetupForStoppingConsumerChain(t, ctx, providerKeeper, mocks)
testkeeper.SetupForStoppingConsumerChainChannel(t, ctx, mocks)

// assert mocks for expected calls to `StopConsumerChain` when closing the underlying channel
gomock.InOrder(testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)

providerKeeper.QueueGlobalSlashEntry(ctx, providertypes.NewGlobalSlashEntry(
ctx.BlockTime(), "chainID", 1, cryptoutil.NewCryptoIdentityFromIntSeed(90).ProviderConsAddress()))
Expand All @@ -548,7 +552,9 @@ func TestStopConsumerChain(t *testing.T) {
description: "valid stop of consumer chain, all mock calls hit",
setup: func(ctx sdk.Context, providerKeeper *providerkeeper.Keeper, mocks testkeeper.MockedKeepers) {
testkeeper.SetupForStoppingConsumerChain(t, ctx, providerKeeper, mocks)
testkeeper.SetupForStoppingConsumerChainChannel(t, ctx, mocks)

// assert mocks for expected calls to `StopConsumerChain` when closing the underlying channel
gomock.InOrder(testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)
},
expErr: false,
},
Expand Down Expand Up @@ -1042,8 +1048,8 @@ func TestBeginBlockCCR(t *testing.T) {
expectations = append(expectations, testkeeper.GetMocksForSetConsumerChain(ctx, &mocks, prop.ChainId)...)
}
// Only first two consumer chains should be stopped
expectations = append(expectations, testkeeper.GetMocksForStopConsumerChain(ctx, &mocks)...)
expectations = append(expectations, testkeeper.GetMocksForStopConsumerChain(ctx, &mocks)...)
expectations = append(expectations, testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)
expectations = append(expectations, testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)

gomock.InOrder(expectations...)

Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func TestSendVSCPacketsToChainFailure(t *testing.T) {
)

// Append mocks for expected call to StopConsumerChain
mockCalls = append(mockCalls, testkeeper.GetMocksForStopConsumerChain(ctx, &mocks)...)
mockCalls = append(mockCalls, testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)

// Assert mock calls hit
gomock.InOrder(mockCalls...)
Expand Down
4 changes: 3 additions & 1 deletion x/ccv/provider/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ func TestProviderProposalHandler(t *testing.T) {

case tc.expValidConsumerRemoval:
testkeeper.SetupForStoppingConsumerChain(t, ctx, &providerKeeper, mocks)
testkeeper.SetupForStoppingConsumerChainChannel(t, ctx, mocks)

// assert mocks for expected calls to `StopConsumerChain` when closing the underlying channel
gomock.InOrder(testkeeper.GetMocksForStopConsumerChainWithCloseChannel(ctx, &mocks)...)

case tc.expValidEquivocation:
providerKeeper.SetSlashLog(ctx, providertypes.NewProviderConsAddress(equivocation.GetConsensusAddress()))
Expand Down

0 comments on commit 45867c2

Please sign in to comment.