refactor historical info test
This commit is contained in:
parent
918949cf23
commit
6025132720
|
@ -4,6 +4,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
@ -38,72 +40,73 @@ func TestHistoricalInfo(t *testing.T) {
|
||||||
require.Equal(t, types.HistoricalInfo{}, recv, "HistoricalInfo is not empty")
|
require.Equal(t, types.HistoricalInfo{}, recv, "HistoricalInfo is not empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
//func TestTrackHistoricalInfo(t *testing.T) {
|
func TestTrackHistoricalInfo(t *testing.T) {
|
||||||
// ctx, _, _, k, _ := CreateTestInput(t, false, 10)
|
app := simapp.Setup(false)
|
||||||
//
|
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||||
// // set historical entries in params to 5
|
|
||||||
// params := types.DefaultParams()
|
// set historical entries in params to 5
|
||||||
// params.HistoricalEntries = 5
|
params := types.DefaultParams()
|
||||||
// k.SetParams(ctx, params)
|
params.HistoricalEntries = 5
|
||||||
//
|
app.StakingKeeper.SetParams(ctx, params)
|
||||||
// // set historical info at 5, 4 which should be pruned
|
|
||||||
// // and check that it has been stored
|
// set historical info at 5, 4 which should be pruned
|
||||||
// h4 := abci.Header{
|
// and check that it has been stored
|
||||||
// ChainID: "HelloChain",
|
h4 := abci.Header{
|
||||||
// Height: 4,
|
ChainID: "HelloChain",
|
||||||
// }
|
Height: 4,
|
||||||
// h5 := abci.Header{
|
}
|
||||||
// ChainID: "HelloChain",
|
h5 := abci.Header{
|
||||||
// Height: 5,
|
ChainID: "HelloChain",
|
||||||
// }
|
Height: 5,
|
||||||
// valSet := []types.Validator{
|
}
|
||||||
// types.NewValidator(sdk.ValAddress(Addrs[0]), PKs[0], types.Description{}),
|
valSet := []types.Validator{
|
||||||
// types.NewValidator(sdk.ValAddress(Addrs[1]), PKs[1], types.Description{}),
|
types.NewValidator(sdk.ValAddress(Addrs[0]), PKs[0], types.Description{}),
|
||||||
// }
|
types.NewValidator(sdk.ValAddress(Addrs[1]), PKs[1], types.Description{}),
|
||||||
// hi4 := types.NewHistoricalInfo(h4, valSet)
|
}
|
||||||
// hi5 := types.NewHistoricalInfo(h5, valSet)
|
hi4 := types.NewHistoricalInfo(h4, valSet)
|
||||||
// k.SetHistoricalInfo(ctx, 4, hi4)
|
hi5 := types.NewHistoricalInfo(h5, valSet)
|
||||||
// k.SetHistoricalInfo(ctx, 5, hi5)
|
app.StakingKeeper.SetHistoricalInfo(ctx, 4, hi4)
|
||||||
// recv, found := k.GetHistoricalInfo(ctx, 4)
|
app.StakingKeeper.SetHistoricalInfo(ctx, 5, hi5)
|
||||||
// require.True(t, found)
|
recv, found := app.StakingKeeper.GetHistoricalInfo(ctx, 4)
|
||||||
// require.Equal(t, hi4, recv)
|
require.True(t, found)
|
||||||
// recv, found = k.GetHistoricalInfo(ctx, 5)
|
require.Equal(t, hi4, recv)
|
||||||
// require.True(t, found)
|
recv, found = app.StakingKeeper.GetHistoricalInfo(ctx, 5)
|
||||||
// require.Equal(t, hi5, recv)
|
require.True(t, found)
|
||||||
//
|
require.Equal(t, hi5, recv)
|
||||||
// // Set last validators in keeper
|
|
||||||
// val1 := types.NewValidator(sdk.ValAddress(Addrs[2]), PKs[2], types.Description{})
|
// Set last validators in keeper
|
||||||
// k.SetValidator(ctx, val1)
|
val1 := types.NewValidator(sdk.ValAddress(Addrs[2]), PKs[2], types.Description{})
|
||||||
// k.SetLastValidatorPower(ctx, val1.OperatorAddress, 10)
|
app.StakingKeeper.SetValidator(ctx, val1)
|
||||||
// val2 := types.NewValidator(sdk.ValAddress(Addrs[3]), PKs[3], types.Description{})
|
app.StakingKeeper.SetLastValidatorPower(ctx, val1.OperatorAddress, 10)
|
||||||
// vals := []types.Validator{val1, val2}
|
val2 := types.NewValidator(sdk.ValAddress(Addrs[3]), PKs[3], types.Description{})
|
||||||
// sort.Sort(types.Validators(vals))
|
vals := []types.Validator{val1, val2}
|
||||||
// k.SetValidator(ctx, val2)
|
sort.Sort(types.Validators(vals))
|
||||||
// k.SetLastValidatorPower(ctx, val2.OperatorAddress, 8)
|
app.StakingKeeper.SetValidator(ctx, val2)
|
||||||
//
|
app.StakingKeeper.SetLastValidatorPower(ctx, val2.OperatorAddress, 8)
|
||||||
// // Set Header for BeginBlock context
|
|
||||||
// header := abci.Header{
|
// Set Header for BeginBlock context
|
||||||
// ChainID: "HelloChain",
|
header := abci.Header{
|
||||||
// Height: 10,
|
ChainID: "HelloChain",
|
||||||
// }
|
Height: 10,
|
||||||
// ctx = ctx.WithBlockHeader(header)
|
}
|
||||||
//
|
ctx = ctx.WithBlockHeader(header)
|
||||||
// k.TrackHistoricalInfo(ctx)
|
|
||||||
//
|
app.StakingKeeper.TrackHistoricalInfo(ctx)
|
||||||
// // Check HistoricalInfo at height 10 is persisted
|
|
||||||
// expected := types.HistoricalInfo{
|
// Check HistoricalInfo at height 10 is persisted
|
||||||
// Header: header,
|
expected := types.HistoricalInfo{
|
||||||
// Valset: vals,
|
Header: header,
|
||||||
// }
|
Valset: vals,
|
||||||
// recv, found = k.GetHistoricalInfo(ctx, 10)
|
}
|
||||||
// require.True(t, found, "GetHistoricalInfo failed after BeginBlock")
|
recv, found = app.StakingKeeper.GetHistoricalInfo(ctx, 10)
|
||||||
// require.Equal(t, expected, recv, "GetHistoricalInfo returned eunexpected result")
|
require.True(t, found, "GetHistoricalInfo failed after BeginBlock")
|
||||||
//
|
require.Equal(t, expected, recv, "GetHistoricalInfo returned eunexpected result")
|
||||||
// // Check HistoricalInfo at height 5, 4 is pruned
|
|
||||||
// recv, found = k.GetHistoricalInfo(ctx, 4)
|
// Check HistoricalInfo at height 5, 4 is pruned
|
||||||
// require.False(t, found, "GetHistoricalInfo did not prune earlier height")
|
recv, found = app.StakingKeeper.GetHistoricalInfo(ctx, 4)
|
||||||
// require.Equal(t, types.HistoricalInfo{}, recv, "GetHistoricalInfo at height 4 is not empty after prune")
|
require.False(t, found, "GetHistoricalInfo did not prune earlier height")
|
||||||
// recv, found = k.GetHistoricalInfo(ctx, 5)
|
require.Equal(t, types.HistoricalInfo{}, recv, "GetHistoricalInfo at height 4 is not empty after prune")
|
||||||
// require.False(t, found, "GetHistoricalInfo did not prune first prune height")
|
recv, found = app.StakingKeeper.GetHistoricalInfo(ctx, 5)
|
||||||
// require.Equal(t, types.HistoricalInfo{}, recv, "GetHistoricalInfo at height 5 is not empty after prune")
|
require.False(t, found, "GetHistoricalInfo did not prune first prune height")
|
||||||
//}
|
require.Equal(t, types.HistoricalInfo{}, recv, "GetHistoricalInfo at height 5 is not empty after prune")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue