-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * Deletes out of date duplicate code * Adds check that validator with key does not already exist * Partially adjust assign unit test * Finishes adjusting unit * Updates stress test to never find a validator * Improves comment * Fixes handler_test * Adds validatorI iterator to expected keeper * Implements AfterValidatorCreated hook * Names * Simplifies validator query * Adds hooks test * Remove TODO * Fix random sim test Co-authored-by: Daniel <[email protected]>
- Loading branch information
Showing
6 changed files
with
233 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
cryptotestutil "github.com/cosmos/interchain-security/testutil/crypto" | ||
testkeeper "github.com/cosmos/interchain-security/testutil/keeper" | ||
providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestValidatorConsensusKeyInUse(t *testing.T) { | ||
|
||
newValidator := cryptotestutil.NewCryptoIdentityFromIntSeed(0) | ||
anotherValidator0 := cryptotestutil.NewCryptoIdentityFromIntSeed(1) | ||
anotherValidator1 := cryptotestutil.NewCryptoIdentityFromIntSeed(2) | ||
|
||
tests := []struct { | ||
name string | ||
setup func(sdk.Context, providerkeeper.Keeper) | ||
expect bool | ||
}{ | ||
{ | ||
name: "not in use by another validator", | ||
setup: func(ctx sdk.Context, k providerkeeper.Keeper) { | ||
// Another validator does not exist | ||
}, | ||
expect: false, | ||
}, | ||
{ | ||
name: "in use by another validator", | ||
setup: func(ctx sdk.Context, k providerkeeper.Keeper) { | ||
// We are trying to add a new validator, but its address has already been used | ||
// by another validator | ||
k.SetValidatorByConsumerAddr(ctx, "chainid", newValidator.SDKConsAddress(), anotherValidator0.SDKConsAddress()) | ||
}, | ||
expect: true, | ||
}, | ||
{ | ||
name: "in use by one of several other validators", | ||
setup: func(ctx sdk.Context, k providerkeeper.Keeper) { | ||
// We are trying to add a new validator, but its address has already been used | ||
// by another validator, of which there are several, across potentially several chains | ||
k.SetValidatorByConsumerAddr(ctx, "chainid0", newValidator.SDKConsAddress(), anotherValidator0.SDKConsAddress()) | ||
k.SetValidatorByConsumerAddr(ctx, "chainid1", anotherValidator1.SDKConsAddress(), anotherValidator1.SDKConsAddress()) | ||
}, | ||
expect: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
k, ctx, _, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) | ||
|
||
gomock.InOrder( | ||
mocks.MockStakingKeeper.EXPECT().GetValidator(ctx, | ||
newValidator.SDKStakingOperator(), | ||
).Return(newValidator.SDKStakingValidator(), true), | ||
) | ||
|
||
tt.setup(ctx, k) | ||
|
||
t.Run(tt.name, func(t *testing.T) { | ||
if actual := providerkeeper.ValidatorConsensusKeyInUse(&k, ctx, newValidator.SDKStakingOperator()); actual != tt.expect { | ||
t.Errorf("validatorConsensusKeyInUse() = %v, want %v", actual, tt.expect) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.