* Update PENDING.md * SlashingPeriod struct * Seperate keys.go, constant prefixes * Make linter happy * Update Gopkg.lock * Seek slashing period by infraction height * Slashing period hooks * Slashing period unit tests; bugfix * Add simple hook tests * Add sdk.ValidatorHooks interface * No-op hooks * Real hooks * Fix iteration direction & duplicate key, update Gaia * Correctly simulate past validator set signatures * Tiny rename * Update dep; 'make format' * Add quick slashing period functionality test * Additional unit tests * Use current validators when selected * Panic in the right place * Address @rigelrozanski comments * Fix linter errors * Address @melekes suggestion * Rename hook * Update for new bech32 types * 'make format'
27 lines
880 B
Go
27 lines
880 B
Go
package slashing
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func TestHookOnValidatorBonded(t *testing.T) {
|
|
ctx, _, _, _, keeper := createTestInput(t)
|
|
addr := sdk.ConsAddress(addrs[0])
|
|
keeper.onValidatorBonded(ctx, addr)
|
|
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
|
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), 0, sdk.ZeroDec()}, period)
|
|
}
|
|
|
|
func TestHookOnValidatorBeginUnbonding(t *testing.T) {
|
|
ctx, _, _, _, keeper := createTestInput(t)
|
|
addr := sdk.ConsAddress(addrs[0])
|
|
keeper.onValidatorBonded(ctx, addr)
|
|
keeper.onValidatorBeginUnbonding(ctx, addr)
|
|
period := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, ctx.BlockHeight())
|
|
require.Equal(t, ValidatorSlashingPeriod{addr, ctx.BlockHeight(), ctx.BlockHeight(), sdk.ZeroDec()}, period)
|
|
}
|