Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 7, 2023
1 parent 911319f commit 3527963
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
10 changes: 5 additions & 5 deletions x/feegrant/basic_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -19,23 +19,23 @@ 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))
atom := sdk.NewCoins(sdk.NewInt64Coin("atom", 555))
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 {
Expand Down
11 changes: 10 additions & 1 deletion x/staking/keeper/historical_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion x/staking/keeper/historical_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 3527963

Please sign in to comment.