github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/genesis_test.go (about) 1 package slashing_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 9 10 "github.com/Finschia/finschia-sdk/simapp" 11 sdk "github.com/Finschia/finschia-sdk/types" 12 "github.com/Finschia/finschia-sdk/x/slashing" 13 "github.com/Finschia/finschia-sdk/x/slashing/testslashing" 14 "github.com/Finschia/finschia-sdk/x/slashing/types" 15 ) 16 17 func TestExportAndInitGenesis(t *testing.T) { 18 app := simapp.Setup(false) 19 ctx := app.BaseApp.NewContext(false, tmproto.Header{}) 20 21 app.SlashingKeeper.SetParams(ctx, testslashing.TestParams()) 22 23 addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) 24 info1 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[0]), int64(4), int64(3), 25 time.Now().UTC().Add(100000000000), false, int64(10)) 26 info2 := types.NewValidatorSigningInfo(sdk.ConsAddress(addrDels[1]), int64(5), int64(4), 27 time.Now().UTC().Add(10000000000), false, int64(10)) 28 29 app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0]), info1) 30 app.SlashingKeeper.SetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1]), info2) 31 genesisState := slashing.ExportGenesis(ctx, app.SlashingKeeper) 32 33 require.Equal(t, genesisState.Params, testslashing.TestParams()) 34 require.Len(t, genesisState.SigningInfos, 2) 35 require.Equal(t, genesisState.SigningInfos[0].ValidatorSigningInfo, info1) 36 37 // Tombstone validators after genesis shouldn't effect genesis state 38 app.SlashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[0])) 39 app.SlashingKeeper.Tombstone(ctx, sdk.ConsAddress(addrDels[1])) 40 41 ok := app.SlashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0])) 42 require.True(t, ok) 43 44 newInfo1, ok := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0])) 45 require.NotEqual(t, info1, newInfo1) 46 // Initialise genesis with genesis state before tombstone 47 slashing.InitGenesis(ctx, app.SlashingKeeper, app.StakingKeeper, genesisState) 48 49 // Validator isTombstoned should return false as GenesisState is initialised 50 ok = app.SlashingKeeper.IsTombstoned(ctx, sdk.ConsAddress(addrDels[0])) 51 require.False(t, ok) 52 53 newInfo1, ok = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[0])) 54 newInfo2, ok := app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(addrDels[1])) 55 require.True(t, ok) 56 require.Equal(t, info1, newInfo1) 57 require.Equal(t, info2, newInfo2) 58 }