From 45867c2634140f7ca3b0b5319b9af27a8cb3abcd Mon Sep 17 00:00:00 2001 From: Karolos Antoniadis Date: Mon, 21 Aug 2023 12:03:02 +0200 Subject: [PATCH] Remove helper function in favor of using directly. --- testutil/keeper/expectations.go | 5 +++-- testutil/keeper/unit_test_helpers.go | 9 +-------- x/ccv/provider/keeper/proposal_test.go | 16 +++++++++++----- x/ccv/provider/keeper/relay_test.go | 2 +- x/ccv/provider/proposal_handler_test.go | 4 +++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/testutil/keeper/expectations.go b/testutil/keeper/expectations.go index 07d4d320ba..7814fe0fcf 100644 --- a/testutil/keeper/expectations.go +++ b/testutil/keeper/expectations.go @@ -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( diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index c98275cffc..4ccb8a1861 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -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, ) { @@ -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, diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index 342e22078c..0d7085068a 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -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) @@ -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())) @@ -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, }, @@ -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...) diff --git a/x/ccv/provider/keeper/relay_test.go b/x/ccv/provider/keeper/relay_test.go index 798238c8f9..590286261c 100644 --- a/x/ccv/provider/keeper/relay_test.go +++ b/x/ccv/provider/keeper/relay_test.go @@ -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...) diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 6d31c61638..e8963421d2 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -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()))