Skip to content

Commit

Permalink
add CRUD test
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 17, 2023
1 parent 5675f8c commit 22e6258
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions x/ccv/provider/keeper/consumer_equivocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
cryptotestutil "github.com/cosmos/interchain-security/v2/testutil/crypto"
testutil "github.com/cosmos/interchain-security/v2/testutil/crypto"
testkeeper "github.com/cosmos/interchain-security/v2/testutil/keeper"
"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
"github.com/golang/mock/gomock"
Expand All @@ -34,8 +33,8 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {

valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val1, val2})

blockID1 := testutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := testutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))
blockID1 := cryptotestutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := cryptotestutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))

ctx = ctx.WithBlockTime(time.Now())

Expand All @@ -55,15 +54,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"invalid verifying public key - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -81,7 +80,7 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
// signer2 is used to derive the validator addresss of the same vote
"verifying public key doesn't correspond to validator address",
[]*tmtypes.Vote{
testutil.MakeAndSignVoteWithForgedValAddress(
cryptotestutil.MakeAndSignVoteWithForgedValAddress(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -90,7 +89,7 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
signer2,
chainID,
),
testutil.MakeAndSignVoteWithForgedValAddress(
cryptotestutil.MakeAndSignVoteWithForgedValAddress(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -107,15 +106,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"evidence has votes with different block height - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight()+1,
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -131,15 +130,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"evidence has votes with different validator address - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -155,15 +154,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"evidence has votes with same block IDs - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -179,15 +178,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"given chain ID isn't the same as the one used to sign the votes - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -203,15 +202,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"voteA is signed using the wrong chain ID - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
"WrongChainID",
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -227,15 +226,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"voteB is signed using the wrong chain ID - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -251,15 +250,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"wrong public key - shouldn't pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand All @@ -275,15 +274,15 @@ func TestVerifyDoubleVotingEvidence(t *testing.T) {
{
"valid double voting evidence should pass",
[]*tmtypes.Vote{
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID1,
ctx.BlockHeight(),
ctx.BlockTime(),
valSet,
signer1,
chainID,
),
testutil.MakeAndSignVote(
cryptotestutil.MakeAndSignVote(
blockID2,
ctx.BlockHeight(),
ctx.BlockTime(),
Expand Down Expand Up @@ -779,3 +778,21 @@ func TestSlashValidatorDoesNotSlashIfValidatorIsUnbonded(t *testing.T) {
gomock.InOrder(expectedCalls...)
keeper.SlashValidator(ctx, providerAddr)
}

func TestEquivocationEvidenceMinHeightCRUD(t *testing.T) {
chainID := consumer
expMinHeight := uint64(12)
keeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

height := keeper.GetEquivocationEvidenceMinHeight(ctx, chainID)
require.Zero(t, height, "equivocation evidence min height should be 0")

keeper.SetEquivocationEvidenceMinHeight(ctx, chainID, expMinHeight)
height = keeper.GetEquivocationEvidenceMinHeight(ctx, chainID)
require.Equal(t, height, expMinHeight)

keeper.DeleteEquivocationEvidenceMinHeight(ctx, chainID)
height = keeper.GetEquivocationEvidenceMinHeight(ctx, chainID)
require.Zero(t, height, "equivocation evidence min height should be 0")
}

0 comments on commit 22e6258

Please sign in to comment.