Skip to content

Commit

Permalink
Fix TestHandleEquivocationProposal (#734)
Browse files Browse the repository at this point in the history
* changes to TestHandleEquivocationProposal

* Update proposal_test.go
  • Loading branch information
shaspitz authored Feb 16, 2023
1 parent 2c5942d commit 558516f
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,55 +1002,62 @@ func TestBeginBlockCCR(t *testing.T) {
}

func TestHandleEquivocationProposal(t *testing.T) {
keeperParams := testkeeper.NewInMemKeeperParams(t)
keeper, ctx, _, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams)
tcFail := []*evidencetypes.Equivocation{
&evidencetypes.Equivocation{
Time: time.Now(),
Height: 1,
Power: 1,
ConsensusAddress: "addr1",
},
&evidencetypes.Equivocation{
Time: time.Now(),
Height: 1,
Power: 1,
ConsensusAddress: "addr2",
},
}

tcPass := []*evidencetypes.Equivocation{
&evidencetypes.Equivocation{
equivocations := []*evidencetypes.Equivocation{
{
Time: time.Now(),
Height: 1,
Power: 1,
ConsensusAddress: "addr3",
ConsensusAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
},
&evidencetypes.Equivocation{
{
Time: time.Now(),
Height: 1,
Power: 1,
ConsensusAddress: "addr4",
ConsensusAddress: "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
},
}

// test failing prop
propFail := &providertypes.EquivocationProposal{
Equivocations: []*evidencetypes.Equivocation{tcFail[0], tcFail[1]},
prop := &providertypes.EquivocationProposal{
Equivocations: []*evidencetypes.Equivocation{equivocations[0], equivocations[1]},
}
err := keeper.HandleEquivocationProposal(ctx, propFail)
require.Error(t, err)

// test passing prop
propPass := &providertypes.EquivocationProposal{
Equivocations: []*evidencetypes.Equivocation{tcPass[0], tcPass[1]},
testCases := []struct {
name string
setSlashLogs bool
expectEquivsHandled bool
expectErr bool
}{
{name: "slash logs not set", setSlashLogs: false, expectEquivsHandled: false, expectErr: true},
{name: "slash logs set", setSlashLogs: true, expectEquivsHandled: true, expectErr: false},
}
keeper.SetSlashLog(ctx, tcPass[0].GetConsensusAddress())
keeper.SetSlashLog(ctx, tcPass[0].GetConsensusAddress())
for _, tc := range testCases {

mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, tcPass[0])
mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, tcPass[1])
keeperParams := testkeeper.NewInMemKeeperParams(t)
keeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams)

if tc.setSlashLogs {
// Set slash logs according to cons addrs in equivocations
consAddr := equivocations[0].GetConsensusAddress()
require.NotNil(t, consAddr, "consensus address could not be parsed")
keeper.SetSlashLog(ctx, consAddr)
consAddr = equivocations[1].GetConsensusAddress()
require.NotNil(t, consAddr, "consensus address could not be parsed")
keeper.SetSlashLog(ctx, consAddr)
}

err = keeper.HandleEquivocationProposal(ctx, propPass)
require.NoError(t, err)
if tc.expectEquivsHandled {
mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, equivocations[0])
mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, equivocations[1])
}

err := keeper.HandleEquivocationProposal(ctx, prop)

if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
ctrl.Finish()
}
}

0 comments on commit 558516f

Please sign in to comment.