refactor!: deprecate blocktime on context (#17738)
This commit is contained in:
@@ -6,9 +6,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@@ -73,7 +73,8 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
legacySubspace := newMockSubspace(authtypes.DefaultParams())
|
||||
require.NoError(t, v4.Migrate(ctx, storeService, legacySubspace, cdc))
|
||||
|
||||
ctx = app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()})
|
||||
ctx = app.BaseApp.NewContext(false)
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Now()})
|
||||
err = stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())
|
||||
require.NoError(t, err)
|
||||
lastAccNum := uint64(1000)
|
||||
@@ -99,10 +100,10 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
err = accountKeeper.Params.Set(ctx, authtypes.DefaultParams())
|
||||
require.NoError(t, err)
|
||||
@@ -129,10 +130,10 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -152,10 +153,10 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -179,7 +180,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(1, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -200,7 +201,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(200)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(1, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -225,7 +226,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(1, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -250,7 +251,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(1, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(1, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -271,10 +272,10 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -290,8 +291,8 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
{
|
||||
"continuous vesting, start time after blocktime",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
startTime := ctx.BlockTime().AddDate(1, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(2, 0, 0).Unix()
|
||||
startTime := ctx.HeaderInfo().Time.AddDate(1, 0, 0).Unix()
|
||||
endTime := ctx.HeaderInfo().Time.AddDate(2, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -299,7 +300,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -315,8 +316,8 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
{
|
||||
"continuous vesting, start time passed but not ended",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
startTime := ctx.BlockTime().AddDate(-1, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(2, 0, 0).Unix()
|
||||
startTime := ctx.HeaderInfo().Time.AddDate(-1, 0, 0).Unix()
|
||||
endTime := ctx.HeaderInfo().Time.AddDate(2, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -324,7 +325,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -340,8 +341,8 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
{
|
||||
"continuous vesting, start time and endtime passed",
|
||||
func(ctx sdk.Context, validator stakingtypes.Validator, delegatorAddr sdk.AccAddress) {
|
||||
startTime := ctx.BlockTime().AddDate(-2, 0, 0).Unix()
|
||||
endTime := ctx.BlockTime().AddDate(-1, 0, 0).Unix()
|
||||
startTime := ctx.HeaderInfo().Time.AddDate(-2, 0, 0).Unix()
|
||||
endTime := ctx.HeaderInfo().Time.AddDate(-1, 0, 0).Unix()
|
||||
baseAccount := createBaseAccount(delegatorAddr)
|
||||
bondDenom, err := stakingKeeper.BondDenom(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -349,7 +350,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewContinuousVestingAccount(baseAccount, vestedCoins, startTime, endTime)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -370,7 +371,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(100)))
|
||||
|
||||
start := ctx.BlockTime().Unix() + int64(time.Hour/time.Second)
|
||||
start := ctx.HeaderInfo().Time.Unix() + int64(time.Hour/time.Second)
|
||||
|
||||
periods := []types.Period{
|
||||
{
|
||||
@@ -475,7 +476,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewPeriodicVestingAccount(baseAccount, vestedCoins, startTime, periods)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(time.Unix(1601042400+31536000+15897600+15897600+1, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Unix(1601042400+31536000+15897600+15897600+1, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -524,7 +525,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewPeriodicVestingAccount(baseAccount, vestedCoins, startTime, periods)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(time.Unix(1601042400+31536000+1, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Unix(1601042400+31536000+1, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -573,7 +574,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
delayedAccount, err := types.NewPeriodicVestingAccount(baseAccount, vestedCoins, startTime, periods)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(time.Unix(1601042400+31536000+15638400+1, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Unix(1601042400+31536000+15638400+1, 0)})
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
|
||||
@@ -595,7 +596,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(10, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -604,7 +605,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
_, err = stakingKeeper.Delegate(ctx, delegatorAddr, sdkmath.NewInt(300), stakingtypes.Unbonded, validator, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().AddDate(1, 0, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.AddDate(1, 0, 0)})
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress)
|
||||
require.NoError(t, err)
|
||||
@@ -627,7 +628,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(10, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -646,7 +647,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
vestedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, sdkmath.NewInt(300)))
|
||||
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.BlockTime().AddDate(10, 0, 0).Unix())
|
||||
delayedAccount, err := types.NewDelayedVestingAccount(baseAccount, vestedCoins, ctx.HeaderInfo().Time.AddDate(10, 0, 0).Unix())
|
||||
require.NoError(t, err)
|
||||
|
||||
accountKeeper.SetAccount(ctx, delayedAccount)
|
||||
@@ -675,7 +676,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
|
||||
tc.prepareFunc(ctx, validator, delegatorAddr)
|
||||
|
||||
if tc.blockTime != 0 {
|
||||
ctx = ctx.WithBlockTime(time.Unix(tc.blockTime, 0))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Unix(tc.blockTime, 0)})
|
||||
}
|
||||
|
||||
// We introduce the bug
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/comet"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/log"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/evidence"
|
||||
@@ -236,7 +237,7 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||
assert.Assert(t, val.GetTokens().Equal(newTokens))
|
||||
|
||||
// jump to past the unbonding period
|
||||
ctx = ctx.WithBlockTime(time.Unix(1, 0).Add(stakingParams.UnbondingTime))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: time.Unix(1, 0).Add(stakingParams.UnbondingTime)})
|
||||
|
||||
// require we cannot unjail
|
||||
assert.Error(t, f.slashingKeeper.Unjail(ctx, operatorAddr), slashingtypes.ErrValidatorJailed.Error())
|
||||
@@ -262,7 +263,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
ctx := f.sdkCtx.WithIsCheckTx(false).WithBlockHeight(1).WithBlockTime(time.Now())
|
||||
ctx := f.sdkCtx.WithIsCheckTx(false).WithBlockHeight(1).WithHeaderInfo(header.Info{Time: time.Now()})
|
||||
populateValidators(t, f)
|
||||
|
||||
power := int64(100)
|
||||
@@ -288,7 +289,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
nci := comet.Info{Evidence: []comet.Evidence{{
|
||||
Validator: comet.Validator{Address: valpubkey.Address(), Power: power},
|
||||
Type: comet.MisbehaviorType(abci.MisbehaviorType_DUPLICATE_VOTE),
|
||||
Time: ctx.BlockTime(),
|
||||
Time: ctx.HeaderInfo().Time,
|
||||
Height: 0,
|
||||
}}}
|
||||
|
||||
@@ -297,7 +298,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
|
||||
ctx = ctx.WithCometInfo(nci)
|
||||
ctx = ctx.WithConsensusParams(cp)
|
||||
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(cp.Evidence.MaxAgeDuration + 1))
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: ctx.HeaderInfo().Time.Add(cp.Evidence.MaxAgeDuration + 1)})
|
||||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + cp.Evidence.MaxAgeNumBlocks + 1)
|
||||
|
||||
assert.NilError(t, f.evidenceKeeper.BeginBlocker(ctx))
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
@@ -163,7 +164,7 @@ func TestImportExportQueues(t *testing.T) {
|
||||
params, err = s2.GovKeeper.Params.Get(ctx2)
|
||||
assert.NilError(t, err)
|
||||
// Jump the time forward past the DepositPeriod and VotingPeriod
|
||||
ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod))
|
||||
ctx2 = ctx2.WithHeaderInfo(header.Info{Time: ctx2.BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod)})
|
||||
|
||||
// Make sure that they are still in the DepositPeriod and VotingPeriod respectively
|
||||
proposal1, err = s2.GovKeeper.Proposals.Get(ctx2, proposalID1)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -93,7 +94,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
assert.Assert(math.IntEq(t, newNotBonded, oldNotBonded))
|
||||
|
||||
// mature unbonding delegations
|
||||
ctx = ctx.WithBlockTime(completionTime)
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
_, err = f.stakingKeeper.CompleteUnbonding(ctx, addrDel, addrVal)
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
unbondingAmount := sdk.NewInt64Coin(bondDenom, 5)
|
||||
ubd := types.NewUnbondingDelegation(
|
||||
delegatorAddr, validatorAddr, 10,
|
||||
ctx.BlockTime().Add(time.Minute*10),
|
||||
ctx.HeaderInfo().Time.Add(time.Minute*10),
|
||||
unbondingAmount.Amount,
|
||||
0,
|
||||
address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"),
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
@@ -74,7 +74,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
||||
assert.Assert(t, slashAmount.Equal(math.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(10, 0)})
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: time.Unix(10, 0)})
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
slashAmount, err = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
@@ -83,7 +83,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
||||
// test valid slash, before expiration timestamp and to which stake contributed
|
||||
notBondedPool := f.stakingKeeper.GetNotBondedPool(f.sdkCtx)
|
||||
oldUnbondedPoolBalances := f.bankKeeper.GetAllBalances(f.sdkCtx, notBondedPool.GetAddress())
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(0, 0)})
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: time.Unix(0, 0)})
|
||||
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
|
||||
slashAmount, err = f.stakingKeeper.SlashUnbondingDelegation(f.sdkCtx, ubd, 0, fraction)
|
||||
assert.NilError(t, err)
|
||||
@@ -139,7 +139,7 @@ func TestSlashRedelegation(t *testing.T) {
|
||||
assert.Assert(t, slashAmount.Equal(math.NewInt(0)))
|
||||
|
||||
// after the expiration time, no longer eligible for slashing
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(10, 0)})
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: time.Unix(10, 0)})
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
validator, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
@@ -150,7 +150,7 @@ func TestSlashRedelegation(t *testing.T) {
|
||||
balances := f.bankKeeper.GetAllBalances(f.sdkCtx, bondedPool.GetAddress())
|
||||
|
||||
// test valid slash, before expiration timestamp and to which stake contributed
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeader(cmtproto.Header{Time: time.Unix(0, 0)})
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: time.Unix(0, 0)})
|
||||
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
|
||||
validator, found = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[1])
|
||||
assert.Assert(t, found)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/golang/mock/gomock"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/math"
|
||||
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
@@ -207,7 +208,7 @@ func TestValidatorUnbondingOnHold1(t *testing.T) {
|
||||
assert.Equal(t, validator.OperatorAddress, unbondingVals[0])
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime.Add(time.Duration(1)))
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime.Add(time.Duration(1))})
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(completionHeight + 1)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
@@ -253,7 +254,7 @@ func TestValidatorUnbondingOnHold2(t *testing.T) {
|
||||
completionHeight := validator1.UnbondingHeight
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime.Add(time.Duration(1)))
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime.Add(time.Duration(1))})
|
||||
f.sdkCtx = f.sdkCtx.WithBlockHeight(completionHeight + 1)
|
||||
assert.NilError(t, f.stakingKeeper.UnbondAllMatureValidators(f.sdkCtx))
|
||||
|
||||
@@ -328,7 +329,7 @@ func TestRedelegationOnHold1(t *testing.T) {
|
||||
assert.Equal(t, 1, len(redelegations))
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - STOPPED UNBONDING CAN NOW COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime)
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
_, err = f.stakingKeeper.CompleteRedelegation(f.sdkCtx, addrDels[0], addrVals[0], addrVals[1])
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -352,7 +353,7 @@ func TestRedelegationOnHold2(t *testing.T) {
|
||||
completionTime := doRedelegation(t, f.stakingKeeper, f.sdkCtx, addrDels, addrVals, &hookCalled)
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime)
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
_, err := f.stakingKeeper.CompleteRedelegation(f.sdkCtx, addrDels[0], addrVals[0], addrVals[1])
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -397,7 +398,7 @@ func TestUnbondingDelegationOnHold1(t *testing.T) {
|
||||
assert.Assert(math.IntEq(t, notBondedAmt1, notBondedAmt3))
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - STOPPED UNBONDING CAN NOW COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime)
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
_, err = f.stakingKeeper.CompleteUnbonding(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -424,7 +425,7 @@ func TestUnbondingDelegationOnHold2(t *testing.T) {
|
||||
completionTime, bondedAmt1, notBondedAmt1 := doUnbondingDelegation(t, f.stakingKeeper, f.bankKeeper, f.sdkCtx, bondDenom, addrDels, addrVals, &hookCalled)
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
f.sdkCtx = f.sdkCtx.WithBlockTime(completionTime)
|
||||
f.sdkCtx = f.sdkCtx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
_, err := f.stakingKeeper.CompleteUnbonding(f.sdkCtx, addrDels[0], addrVals[0])
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/depinject"
|
||||
sdklog "cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
@@ -188,7 +189,7 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() {
|
||||
func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() {
|
||||
require := s.Require()
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := s.ctx.WithBlockTime(blockTime)
|
||||
ctx := s.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// setup accounts[1] as validator
|
||||
validator0 := s.getTestingValidator0(ctx)
|
||||
@@ -233,7 +234,7 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() {
|
||||
func (s *SimTestSuite) TestSimulateMsgEditValidator() {
|
||||
require := s.Require()
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := s.ctx.WithBlockTime(blockTime)
|
||||
ctx := s.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// setup accounts[0] as validator
|
||||
_ = s.getTestingValidator0(ctx)
|
||||
@@ -259,7 +260,7 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() {
|
||||
func (s *SimTestSuite) TestSimulateMsgDelegate() {
|
||||
require := s.Require()
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := s.ctx.WithBlockTime(blockTime)
|
||||
ctx := s.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// execute operation
|
||||
op := simulation.SimulateMsgDelegate(s.txConfig, s.accountKeeper, s.bankKeeper, s.stakingKeeper)
|
||||
@@ -282,7 +283,7 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() {
|
||||
func (s *SimTestSuite) TestSimulateMsgUndelegate() {
|
||||
require := s.Require()
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := s.ctx.WithBlockTime(blockTime)
|
||||
ctx := s.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// setup accounts[1] as validator
|
||||
validator0 := s.getTestingValidator0(ctx)
|
||||
@@ -323,7 +324,7 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() {
|
||||
func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() {
|
||||
require := s.Require()
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := s.ctx.WithBlockTime(blockTime)
|
||||
ctx := s.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// setup accounts[1] as validator0 and accounts[2] as validator1
|
||||
validator0 := s.getTestingValidator0(ctx)
|
||||
|
||||
Reference in New Issue
Block a user