Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Sep 22, 2023
1 parent 6f15a61 commit 93c2cdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package keeper
import (
"bytes"
"fmt"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
Expand Down
7 changes: 4 additions & 3 deletions x/ccv/provider/keeper/punish_validator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package keeper

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
"time"
)

// JailAndTombstoneValidator jails and tombstones the validator with the given provider consensus address
Expand Down Expand Up @@ -46,8 +47,8 @@ func (k Keeper) JailAndTombstoneValidator(ctx sdk.Context, providerAddr types.Pr
// ComputePowerToSlash computes the power to be slashed based on the tokens in non-matured (based on the
// provider `now` time) `undelegations` and `redelegations`, as well as the current `power` of the validator
func (k Keeper) ComputePowerToSlash(now time.Time, undelegations []stakingtypes.UnbondingDelegation,
redelegations []stakingtypes.Redelegation, power int64, powerReduction sdk.Int) int64 {

redelegations []stakingtypes.Redelegation, power int64, powerReduction sdk.Int,
) int64 {
// compute the total numbers of tokens currently being undelegated
undelegationsInTokens := sdk.NewInt(0)
for _, u := range undelegations {
Expand Down
23 changes: 15 additions & 8 deletions x/ccv/provider/keeper/punish_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package keeper_test

import (
"fmt"
"testing"
"time"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

Expand All @@ -15,8 +18,6 @@ import (

"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"testing"
"time"
)

// TestJailAndTombstoneValidator tests that the jailing of a validator is only executed
Expand Down Expand Up @@ -196,7 +197,8 @@ func TestComputePowerToSlash(t *testing.T) {
// 1000 total undelegation tokens
[]stakingtypes.UnbondingDelegation{
createUndelegation([]int64{250, 250}, []time.Time{nowPlus1Hour, nowPlus1Hour}),
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour, nowPlus1Hour})},
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour, nowPlus1Hour}),
},
// 1000 total redelegation tokens
[]stakingtypes.Redelegation{
createRedelegation([]int64{500}, []time.Time{nowPlus1Hour, nowPlus1Hour}),
Expand All @@ -214,7 +216,8 @@ func TestComputePowerToSlash(t *testing.T) {
createUndelegation([]int64{}, []time.Time{}),
createUndelegation([]int64{100, 100}, []time.Time{nowPlus1Hour, nowPlus1Hour}),
createUndelegation([]int64{800}, []time.Time{nowPlus1Hour}),
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour})},
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour}),
},
// 3500 total redelegation tokens
[]stakingtypes.Redelegation{
createRedelegation([]int64{}, []time.Time{}),
Expand Down Expand Up @@ -260,7 +263,8 @@ func TestComputePowerToSlash(t *testing.T) {
createUndelegation([]int64{}, []time.Time{}),
createUndelegation([]int64{100, 100}, []time.Time{nowPlus1Hour, nowPlus1Hour}),
createUndelegation([]int64{800}, []time.Time{nowPlus1Hour}),
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour})},
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour}),
},
[]stakingtypes.Redelegation{},
int64(1),
sdk.NewInt(3),
Expand All @@ -275,7 +279,8 @@ func TestComputePowerToSlash(t *testing.T) {
createUndelegation([]int64{}, []time.Time{}),
createUndelegation([]int64{100, 100}, []time.Time{now, nowPlus1Hour}),
createUndelegation([]int64{800}, []time.Time{nowPlus1Hour}),
createUndelegation([]int64{500}, []time.Time{now})},
createUndelegation([]int64{500}, []time.Time{now}),
},
// 3500 total redelegation tokens, 350 + 200 + 400 = 950 of those are from mature redelegations
// so 3500 - 950 = 2550
[]stakingtypes.Redelegation{
Expand Down Expand Up @@ -344,10 +349,12 @@ func TestSlashValidator(t *testing.T) {
// we also create 1000 tokens worth of redelegations, 750 of them are non-matured
undelegations := []stakingtypes.UnbondingDelegation{
createUndelegation([]int64{250, 250}, []time.Time{nowPlus1Hour, now}),
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour})}
createUndelegation([]int64{500}, []time.Time{nowPlus1Hour}),
}
redelegations := []stakingtypes.Redelegation{
createRedelegation([]int64{250, 250}, []time.Time{now, nowPlus1Hour}),
createRedelegation([]int64{500}, []time.Time{nowPlus1Hour})}
createRedelegation([]int64{500}, []time.Time{nowPlus1Hour}),
}

// validator's current power
currentPower := int64(3000)
Expand Down

0 comments on commit 93c2cdb

Please sign in to comment.