refactor(staking)!: remove historical info (#20845)

Co-authored-by: Facundo <facundomedica@gmail.com>
This commit is contained in:
Marko
2024-07-05 09:28:49 +00:00
committed by GitHub
co-authored by Facundo
parent 25d2043909
commit b68eb39412
34 changed files with 2670 additions and 3456 deletions
@@ -472,7 +472,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
ValidatorAddr: validator.OperatorAddress,
}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14637, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14610, false)
}
func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
@@ -562,7 +562,7 @@ func TestGRPCDelegation(t *testing.T) {
DelegatorAddr: delegator1,
}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4689, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4680, false)
}
func TestGRPCUnbondingDelegation(t *testing.T) {
@@ -645,7 +645,7 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
DelegatorAddr: delegator1,
}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4292, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4283, false)
}
func TestGRPCDelegatorValidator(t *testing.T) {
@@ -732,47 +732,6 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorUnbondingDelegations, 1302, false)
}
func TestGRPCHistoricalInfo(t *testing.T) {
t.Parallel()
f := initDeterministicFixture(t)
rapid.Check(t, func(rt *rapid.T) {
historical := stakingtypes.HistoricalRecord{}
height := rapid.Int64Min(0).Draw(rt, "height")
assert.NilError(t, f.stakingKeeper.HistoricalInfo.Set(
f.ctx,
uint64(height),
historical,
))
req := &stakingtypes.QueryHistoricalInfoRequest{
Height: height,
}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.HistoricalInfo, 0, true)
})
f = initDeterministicFixture(t) // reset
historicalInfo := stakingtypes.HistoricalRecord{}
height := int64(127)
assert.NilError(t, f.stakingKeeper.HistoricalInfo.Set(
f.ctx,
uint64(height),
historicalInfo,
))
req := &stakingtypes.QueryHistoricalInfoRequest{
Height: height,
}
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.HistoricalInfo, 1027, false)
}
func TestGRPCDelegatorValidators(t *testing.T) {
t.Parallel()
f := initDeterministicFixture(t)
@@ -821,7 +780,7 @@ func TestGRPCPool(t *testing.T) {
f = initDeterministicFixture(t) // reset
getStaticValidator(t, f)
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6296, false)
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6287, false)
}
func TestGRPCRedelegations(t *testing.T) {
@@ -5,7 +5,6 @@ import (
"fmt"
"testing"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"gotest.tools/v3/assert"
"cosmossdk.io/collections"
@@ -20,17 +19,11 @@ import (
func createValidatorAccs(t *testing.T, f *fixture) ([]sdk.AccAddress, []types.Validator) {
t.Helper()
addrs, _, validators := createValidators(&testing.T{}, f, []int64{9, 8, 7})
header := cmtproto.Header{
ChainID: "HelloChain",
Height: 5,
}
// sort a copy of the validators, so that original validators does not
// have its order changed
sortedVals := make([]types.Validator, len(validators))
copy(sortedVals, validators)
hi := types.HistoricalRecord{Time: &header.Time, Apphash: header.AppHash, ValidatorsHash: header.NextValidatorsHash}
assert.NilError(t, f.stakingKeeper.HistoricalInfo.Set(f.sdkCtx, uint64(5), hi))
return addrs, validators
}
@@ -725,71 +718,11 @@ func TestGRPCQueryPoolParameters(t *testing.T) {
func TestGRPCQueryHistoricalInfo(t *testing.T) {
t.Parallel()
f := initFixture(t)
ctx := f.sdkCtx
_, _ = createValidatorAccs(t, f)
qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
hi, found := f.stakingKeeper.HistoricalInfo.Get(ctx, uint64(5))
assert.Assert(t, found)
var req *types.QueryHistoricalInfoRequest
testCases := []struct {
msg string
malleate func()
expPass bool
expErrMsg string
}{
{
"empty request",
func() {
req = &types.QueryHistoricalInfoRequest{}
},
false,
"historical info for height 0 not found",
},
{
"invalid request with negative height",
func() {
req = &types.QueryHistoricalInfoRequest{Height: -1}
},
false,
"height cannot be negative",
},
{
"valid request with old height",
func() {
req = &types.QueryHistoricalInfoRequest{Height: 4}
},
false,
"historical info for height 4 not found",
},
{
"valid request with current height",
func() {
req = &types.QueryHistoricalInfoRequest{Height: 5}
},
true,
"",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("Case %s", tc.msg), func(t *testing.T) {
tc.malleate()
res, err := queryClient.HistoricalInfo(gocontext.Background(), req)
if tc.expPass {
assert.NilError(t, err)
assert.Assert(t, res != nil)
assert.DeepEqual(t, &hi, res.HistoricalRecord)
} else {
assert.ErrorContains(t, err, tc.expErrMsg)
assert.Assert(t, res == nil)
}
})
}
_, err := queryClient.HistoricalInfo(gocontext.Background(), &types.QueryHistoricalInfoRequest{}) // nolint:staticcheck // SA1019: deprecated endpoint
assert.ErrorContains(t, err, "this endpoint has been deprecated and removed in 0.52")
}
func TestGRPCQueryRedelegations(t *testing.T) {