refactor TestGetSetValidatorSigningInfo test
This commit is contained in:
parent
416f0147f7
commit
c2cc84950b
|
@ -0,0 +1,61 @@
|
||||||
|
package keeper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
|
||||||
|
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
||||||
|
missed := keeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0)
|
||||||
|
require.False(t, missed) // treat empty key as not missed
|
||||||
|
keeper.SetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0, true)
|
||||||
|
missed = keeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0)
|
||||||
|
require.True(t, missed) // now should be missed
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTombstoned(t *testing.T) {
|
||||||
|
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
||||||
|
require.Panics(t, func() { keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0])) })
|
||||||
|
require.False(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
||||||
|
|
||||||
|
newInfo := types.NewValidatorSigningInfo(
|
||||||
|
sdk.ConsAddress(Addrs[0]),
|
||||||
|
int64(4),
|
||||||
|
int64(3),
|
||||||
|
time.Unix(2, 0),
|
||||||
|
false,
|
||||||
|
int64(10),
|
||||||
|
)
|
||||||
|
keeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]), newInfo)
|
||||||
|
|
||||||
|
require.False(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
||||||
|
keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0]))
|
||||||
|
require.True(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
||||||
|
require.Panics(t, func() { keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0])) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJailUntil(t *testing.T) {
|
||||||
|
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
||||||
|
require.Panics(t, func() { keeper.JailUntil(ctx, sdk.ConsAddress(Addrs[0]), time.Now()) })
|
||||||
|
|
||||||
|
newInfo := types.NewValidatorSigningInfo(
|
||||||
|
sdk.ConsAddress(Addrs[0]),
|
||||||
|
int64(4),
|
||||||
|
int64(3),
|
||||||
|
time.Unix(2, 0),
|
||||||
|
false,
|
||||||
|
int64(10),
|
||||||
|
)
|
||||||
|
keeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]), newInfo)
|
||||||
|
keeper.JailUntil(ctx, sdk.ConsAddress(Addrs[0]), time.Unix(253402300799, 0).UTC())
|
||||||
|
|
||||||
|
info, ok := keeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]))
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, time.Unix(253402300799, 0).UTC(), info.JailedUntil)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package keeper
|
package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -6,77 +6,33 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetSetValidatorSigningInfo(t *testing.T) {
|
func TestGetSetValidatorSigningInfo(t *testing.T) {
|
||||||
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
app := simapp.Setup(false)
|
||||||
info, found := keeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]))
|
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||||
|
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.TokensFromConsensusPower(200))
|
||||||
|
|
||||||
|
info, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]))
|
||||||
require.False(t, found)
|
require.False(t, found)
|
||||||
newInfo := types.NewValidatorSigningInfo(
|
newInfo := types.NewValidatorSigningInfo(
|
||||||
sdk.ConsAddress(Addrs[0]),
|
sdk.ConsAddress(addrDels[0]),
|
||||||
int64(4),
|
int64(4),
|
||||||
int64(3),
|
int64(3),
|
||||||
time.Unix(2, 0),
|
time.Unix(2, 0),
|
||||||
false,
|
false,
|
||||||
int64(10),
|
int64(10),
|
||||||
)
|
)
|
||||||
keeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]), newInfo)
|
app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), newInfo)
|
||||||
info, found = keeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]))
|
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]))
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, info.StartHeight, int64(4))
|
require.Equal(t, info.StartHeight, int64(4))
|
||||||
require.Equal(t, info.IndexOffset, int64(3))
|
require.Equal(t, info.IndexOffset, int64(3))
|
||||||
require.Equal(t, info.JailedUntil, time.Unix(2, 0).UTC())
|
require.Equal(t, info.JailedUntil, time.Unix(2, 0).UTC())
|
||||||
require.Equal(t, info.MissedBlocksCounter, int64(10))
|
require.Equal(t, info.MissedBlocksCounter, int64(10))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSetValidatorMissedBlockBitArray(t *testing.T) {
|
|
||||||
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
|
||||||
missed := keeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0)
|
|
||||||
require.False(t, missed) // treat empty key as not missed
|
|
||||||
keeper.SetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0, true)
|
|
||||||
missed = keeper.GetValidatorMissedBlockBitArray(ctx, sdk.ConsAddress(Addrs[0]), 0)
|
|
||||||
require.True(t, missed) // now should be missed
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTombstoned(t *testing.T) {
|
|
||||||
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
|
||||||
require.Panics(t, func() { keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0])) })
|
|
||||||
require.False(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
|
||||||
|
|
||||||
newInfo := types.NewValidatorSigningInfo(
|
|
||||||
sdk.ConsAddress(Addrs[0]),
|
|
||||||
int64(4),
|
|
||||||
int64(3),
|
|
||||||
time.Unix(2, 0),
|
|
||||||
false,
|
|
||||||
int64(10),
|
|
||||||
)
|
|
||||||
keeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]), newInfo)
|
|
||||||
|
|
||||||
require.False(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
|
||||||
keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0]))
|
|
||||||
require.True(t, keeper.IsTombstoned(ctx, sdk.ConsAddress(Addrs[0])))
|
|
||||||
require.Panics(t, func() { keeper.Tombstone(ctx, sdk.ConsAddress(Addrs[0])) })
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJailUntil(t *testing.T) {
|
|
||||||
ctx, _, _, _, keeper := CreateTestInput(t, types.DefaultParams())
|
|
||||||
require.Panics(t, func() { keeper.JailUntil(ctx, sdk.ConsAddress(Addrs[0]), time.Now()) })
|
|
||||||
|
|
||||||
newInfo := types.NewValidatorSigningInfo(
|
|
||||||
sdk.ConsAddress(Addrs[0]),
|
|
||||||
int64(4),
|
|
||||||
int64(3),
|
|
||||||
time.Unix(2, 0),
|
|
||||||
false,
|
|
||||||
int64(10),
|
|
||||||
)
|
|
||||||
keeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]), newInfo)
|
|
||||||
keeper.JailUntil(ctx, sdk.ConsAddress(Addrs[0]), time.Unix(253402300799, 0).UTC())
|
|
||||||
|
|
||||||
info, ok := keeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(Addrs[0]))
|
|
||||||
require.True(t, ok)
|
|
||||||
require.Equal(t, time.Unix(253402300799, 0).UTC(), info.JailedUntil)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue