refactor!: deprecate blocktime on context (#17738)

This commit is contained in:
Marko
2023-09-18 13:55:21 +00:00
committed by GitHub
parent 8df065b611
commit 6615ff4f76
89 changed files with 379 additions and 369 deletions
@@ -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)