From 3527963724635a67d9f11560cca73fe050460dd5 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 7 Sep 2023 13:59:16 +0200 Subject: [PATCH] fix more tests --- x/feegrant/basic_fee_test.go | 10 +++++----- x/staking/keeper/historical_info.go | 11 ++++++++++- x/staking/keeper/historical_info_test.go | 11 ++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/x/feegrant/basic_fee_test.go b/x/feegrant/basic_fee_test.go index 00e5ce5cc367..524bd94c40a9 100644 --- a/x/feegrant/basic_fee_test.go +++ b/x/feegrant/basic_fee_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/feegrant" @@ -19,15 +19,15 @@ func TestBasicFeeValidAllow(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) - badTime := ctx.BlockTime().AddDate(0, 0, -1) + badTime := ctx.HeaderInfo().Time.AddDate(0, 0, -1) allowace := &feegrant.BasicAllowance{ Expiration: &badTime, } require.Error(t, allowace.ValidateBasic()) - ctx = ctx.WithBlockHeader(cmtproto.Header{ + ctx = ctx.WithHeaderInfo(header.Info{ Time: time.Now(), }) eth := sdk.NewCoins(sdk.NewInt64Coin("eth", 10)) @@ -35,7 +35,7 @@ func TestBasicFeeValidAllow(t *testing.T) { smallAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 43)) bigAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 1000)) leftAtom := sdk.NewCoins(sdk.NewInt64Coin("atom", 512)) - now := ctx.BlockTime() + now := ctx.HeaderInfo().Time oneHour := now.Add(1 * time.Hour) cases := map[string]struct { diff --git a/x/staking/keeper/historical_info.go b/x/staking/keeper/historical_info.go index e23fbd207256..520a0062b55d 100644 --- a/x/staking/keeper/historical_info.go +++ b/x/staking/keeper/historical_info.go @@ -3,6 +3,8 @@ package keeper import ( "context" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -48,7 +50,14 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { return err } - historicalEntry := types.NewHistoricalInfo(sdkCtx.BlockHeader(), types.Validators{Validators: lastVals, ValidatorCodec: k.validatorAddressCodec}, k.PowerReduction(ctx)) + h := cmtproto.Header{ + Height: sdkCtx.BlockHeight(), + Time: sdkCtx.HeaderInfo().Time, + ChainID: sdkCtx.HeaderInfo().ChainID, + NextValidatorsHash: sdkCtx.CometInfo().GetValidatorsHash(), + } + + historicalEntry := types.NewHistoricalInfo(h, types.Validators{Validators: lastVals, ValidatorCodec: k.validatorAddressCodec}, k.PowerReduction(ctx)) // Set latest HistoricalInfo at current height return k.HistoricalInfo.Set(ctx, uint64(sdkCtx.BlockHeight()), historicalEntry) diff --git a/x/staking/keeper/historical_info_test.go b/x/staking/keeper/historical_info_test.go index 0f254770d99f..b211d25ab2e9 100644 --- a/x/staking/keeper/historical_info_test.go +++ b/x/staking/keeper/historical_info_test.go @@ -4,6 +4,7 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "cosmossdk.io/collections" + coreheader "cosmossdk.io/core/header" "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/x/staking/testutil" @@ -108,7 +109,15 @@ func (s *KeeperTestSuite) TestTrackHistoricalInfo() { ChainID: "HelloChain", Height: 10, } - ctx = ctx.WithBlockHeader(header) + ctx = ctx.WithHeaderInfo(coreheader.Info{ + ChainID: "HelloChain", + Height: 10, + }) + + // ctx = ctx.WithCometInfo(comet.BlockInfo{ + // ChainID: "HelloChain", + // Height: 10, + // }) require.NoError(keeper.TrackHistoricalInfo(ctx))