-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix!: handle some panics #2205
fix!: handle some panics #2205
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,11 +68,14 @@ func TestQueueVSCPackets(t *testing.T) { | |
mocks := testkeeper.NewMockedKeepers(ctrl) | ||
testkeeper.SetupMocksForLastBondedValidatorsExpectation(mocks.MockStakingKeeper, 0, []stakingtypes.Validator{}, 1) | ||
|
||
mocks.MockStakingKeeper.EXPECT().GetBondedValidatorsByPower(gomock.Any()).Return([]stakingtypes.Validator{}, nil).AnyTimes() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this indented correctly? Looks like it's fully on the left in comparison to the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks fine to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also fine for me, but gets confusing/wrong when I scale down the browser window |
||
|
||
pk := testkeeper.NewInMemProviderKeeper(keeperParams, mocks) | ||
// no-op if tc.packets is empty | ||
pk.AppendPendingVSCPackets(ctx, chainID, tc.packets...) | ||
|
||
pk.QueueVSCPackets(ctx) | ||
err := pk.QueueVSCPackets(ctx) | ||
require.NoError(t, err) | ||
pending := pk.GetPendingVSCPackets(ctx, chainID) | ||
require.Len(t, pending, tc.expectedQueueSize, "pending vsc queue mismatch (%v != %v) in case: '%s'", tc.expectedQueueSize, len(pending), tc.name) | ||
|
||
|
@@ -120,7 +123,8 @@ func TestQueueVSCPacketsDoesNotResetConsumerValidatorsHeights(t *testing.T) { | |
// validator for the first time after the `QueueVSCPackets` call. | ||
providerKeeper.SetOptedIn(ctx, "chainID", providertypes.NewProviderConsAddress(valBConsAddr)) | ||
|
||
providerKeeper.QueueVSCPackets(ctx) | ||
err := providerKeeper.QueueVSCPackets(ctx) | ||
require.NoError(t, err) | ||
|
||
// the height of consumer validator A should not be modified because A was already a consumer validator | ||
cv, _ := providerKeeper.GetConsumerValidator(ctx, "chainID", providertypes.NewProviderConsAddress(valAConsAddr)) | ||
|
@@ -501,8 +505,9 @@ func TestSendVSCPacketsToChainFailure(t *testing.T) { | |
require.NoError(t, err) | ||
providerKeeper.SetConsumerClientId(ctx, "consumerChainID", "clientID") | ||
|
||
// No panic should occur, StopConsumerChain should be called | ||
providerKeeper.SendVSCPacketsToChain(ctx, "consumerChainID", "CCVChannelID") | ||
// No error should occur, StopConsumerChain should be called | ||
err = providerKeeper.SendVSCPacketsToChain(ctx, "consumerChainID", "CCVChannelID") | ||
require.NoError(t, err) | ||
|
||
// Pending VSC packets should be deleted in StopConsumerChain | ||
require.Empty(t, providerKeeper.GetPendingVSCPackets(ctx, "consumerChainID")) | ||
|
@@ -616,24 +621,28 @@ func TestEndBlockVSU(t *testing.T) { | |
|
||
// with block height of 1 we do not expect any queueing of VSC packets | ||
ctx = ctx.WithBlockHeight(1) | ||
providerKeeper.EndBlockVSU(ctx) | ||
_, err := providerKeeper.EndBlockVSU(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, 0, len(providerKeeper.GetPendingVSCPackets(ctx, chainID))) | ||
|
||
// with block height of 5 we do not expect any queueing of VSC packets | ||
ctx = ctx.WithBlockHeight(5) | ||
providerKeeper.EndBlockVSU(ctx) | ||
_, err = providerKeeper.EndBlockVSU(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, 0, len(providerKeeper.GetPendingVSCPackets(ctx, chainID))) | ||
|
||
// with block height of 10 we expect the queueing of one VSC packet | ||
ctx = ctx.WithBlockHeight(10) | ||
providerKeeper.EndBlockVSU(ctx) | ||
_, err = providerKeeper.EndBlockVSU(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(providerKeeper.GetPendingVSCPackets(ctx, chainID))) | ||
|
||
// With block height of 15 we expect no additional queueing of a VSC packet. | ||
// Note that the pending VSC packet is still there because `SendVSCPackets` does not send the packet. We | ||
// need to mock channels, etc. for this to work, and it's out of scope for this test. | ||
ctx = ctx.WithBlockHeight(15) | ||
providerKeeper.EndBlockVSU(ctx) | ||
_, err = providerKeeper.EndBlockVSU(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(providerKeeper.GetPendingVSCPackets(ctx, chainID))) | ||
} | ||
|
||
|
@@ -699,7 +708,8 @@ func TestProviderValidatorUpdates(t *testing.T) { | |
} | ||
|
||
// Execute the function | ||
updates := providerKeeper.ProviderValidatorUpdates(ctx) | ||
updates, err := providerKeeper.ProviderValidatorUpdates(ctx) | ||
require.NoError(t, err) | ||
|
||
// Assertions | ||
require.ElementsMatch(t, expectedUpdates, updates, "The validator updates should match the expected updates") | ||
|
@@ -756,7 +766,8 @@ func TestQueueVSCPacketsWithPowerCapping(t *testing.T) { | |
params.MaxProviderConsensusValidators = 180 | ||
providerKeeper.SetParams(ctx, params) | ||
|
||
providerKeeper.QueueVSCPackets(ctx) | ||
err := providerKeeper.QueueVSCPackets(ctx) | ||
require.NoError(t, err) | ||
|
||
actualQueuedVSCPackets := providerKeeper.GetPendingVSCPackets(ctx, "chainID") | ||
expectedQueuedVSCPackets := []ccv.ValidatorSetChangePacketData{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this returning an error now instead of simply logging? We want this to fail as a whole if we fail to create a single validator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. Why would we fail to create a validator. If that happens, that's for sure something wrong with the state, right?