Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Jul 3, 2024
1 parent fe47d58 commit 3d4814e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 118 deletions.
41 changes: 0 additions & 41 deletions tests/integration/staking/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 0 additions & 77 deletions tests/integration/staking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"gotest.tools/v3/assert"

"cosmossdk.io/collections"
Expand All @@ -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
}
Expand Down Expand Up @@ -722,76 +715,6 @@ func TestGRPCQueryPoolParameters(t *testing.T) {
assert.DeepEqual(t, params, resp.Params)
}

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)
}
})
}
}

func TestGRPCQueryRedelegations(t *testing.T) {
t.Parallel()
f := initFixture(t)
Expand Down

0 comments on commit 3d4814e

Please sign in to comment.