From 92d4e99d6f38159e89548a66479d10456074fdf4 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:38:24 +0200 Subject: [PATCH 01/17] clean finalizeblock from x/gov --- x/gov/abci_test.go | 48 ++--------------------------- x/gov/simulation/operations_test.go | 37 ---------------------- 2 files changed, 2 insertions(+), 83 deletions(-) diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index deb825a0bbdd..428cfc91afd1 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/stretchr/testify/require" "cosmossdk.io/collections" @@ -87,11 +86,6 @@ func TestTickExpiredDepositPeriod(t *testing.T) { ctx := app.BaseApp.NewContext(false) addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) checkInactiveProposalsQueue(t, ctx, suite.GovKeeper) @@ -137,12 +131,6 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { app := suite.App ctx := app.BaseApp.NewContext(false) addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) checkInactiveProposalsQueue(t, ctx, suite.GovKeeper) @@ -208,12 +196,6 @@ func TestTickPassedDepositPeriod(t *testing.T) { app := suite.App ctx := app.BaseApp.NewContext(false) addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) newProposalMsg, err := v1.NewMsgSubmitProposal( @@ -273,12 +255,6 @@ func TestTickPassedVotingPeriod(t *testing.T) { addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens.Mul(math.NewInt(depositMultiplier))) SortAddresses(addrs) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) checkInactiveProposalsQueue(t, ctx, suite.GovKeeper) @@ -367,18 +343,11 @@ func TestProposalPassedEndblocker(t *testing.T) { govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper) - - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - valAddr := sdk.ValAddress(addrs[0]) proposer := addrs[0] createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10}) - _, err = suite.StakingKeeper.EndBlocker(ctx) + _, err := suite.StakingKeeper.EndBlocker(ctx) require.NoError(t, err) macc := suite.GovKeeper.GetGovernanceAccount(ctx) require.NotNil(t, macc) @@ -428,17 +397,11 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - valAddr := sdk.ValAddress(addrs[0]) proposer := addrs[0] createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10}) - _, err = suite.StakingKeeper.EndBlocker(ctx) + _, err := suite.StakingKeeper.EndBlocker(ctx) require.NoError(t, err) msg := banktypes.NewMsgSend(authtypes.NewModuleAddress(types.ModuleName), addrs[0], sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100000)))) proposal, err := suite.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msg}, "", "title", "summary", proposer, false) @@ -512,13 +475,6 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) { govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper) - - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - valAddr := sdk.ValAddress(addrs[0]) proposer := addrs[0] diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index ec29be847d4d..85b6ee92c955 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" @@ -142,12 +141,6 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { r := rand.New(s) accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgSubmitProposal(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposals{3}.MsgSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") @@ -174,12 +167,6 @@ func TestSimulateMsgSubmitLegacyProposal(t *testing.T) { r := rand.New(s) accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgSubmitLegacyProposal(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposals{3}.ContentSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") @@ -234,12 +221,6 @@ func TestSimulateMsgCancelProposal(t *testing.T) { err = suite.GovKeeper.SetProposal(ctx, proposal) require.NoError(t, err) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgCancelProposal(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") @@ -283,12 +264,6 @@ func TestSimulateMsgDeposit(t *testing.T) { err = suite.GovKeeper.SetProposal(ctx, proposal) require.NoError(t, err) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgDeposit(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") @@ -333,12 +308,6 @@ func TestSimulateMsgVote(t *testing.T) { err = suite.GovKeeper.ActivateVotingPeriod(ctx, proposal) require.NoError(t, err) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgVote(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") @@ -381,12 +350,6 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { err = suite.GovKeeper.ActivateVotingPeriod(ctx, proposal) require.NoError(t, err) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: app.LastBlockHeight() + 1, - Hash: app.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgVoteWeighted(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") From 11fd2a4ef4271db58f7d2d13bbe751755e517131 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:42:46 +0200 Subject: [PATCH 02/17] clean group --- x/group/simulation/operations_test.go | 85 --------------------------- 1 file changed, 85 deletions(-) diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index f3b1d4ad2c8b..8038b1d0fa88 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -130,12 +129,6 @@ func (suite *SimTestSuite) TestSimulateCreateGroup() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 1) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - acc := accounts[0] // execute operation @@ -157,12 +150,6 @@ func (suite *SimTestSuite) TestSimulateCreateGroupWithPolicy() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 1) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - acc := accounts[0] // execute operation @@ -199,12 +186,6 @@ func (suite *SimTestSuite) TestSimulateCreateGroupPolicy() { ) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgCreateGroupPolicy(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -250,12 +231,6 @@ func (suite *SimTestSuite) TestSimulateSubmitProposal() { groupPolicyRes, err := suite.groupKeeper.CreateGroupPolicy(ctx, accountReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgSubmitProposal(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -314,12 +289,6 @@ func (suite *SimTestSuite) TestWithdrawProposal() { _, err = suite.groupKeeper.SubmitProposal(ctx, proposalReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgWithdrawProposal(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -379,12 +348,6 @@ func (suite *SimTestSuite) TestSimulateVote() { _, err = suite.groupKeeper.SubmitProposal(ctx, proposalReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgVote(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -452,12 +415,6 @@ func (suite *SimTestSuite) TestSimulateExec() { }) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgExec(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -492,12 +449,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupAdmin() { ) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupAdmin(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -532,12 +483,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMetadata() { ) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupMetadata(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -572,12 +517,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMembers() { ) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupMembers(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -623,12 +562,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyAdmin() { groupPolicyRes, err := suite.groupKeeper.CreateGroupPolicy(ctx, accountReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupPolicyAdmin(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -674,12 +607,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyDecisionPolicy() { groupPolicyRes, err := suite.groupKeeper.CreateGroupPolicy(ctx, accountReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupPolicyDecisionPolicy(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -725,12 +652,6 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyMetadata() { groupPolicyRes, err := suite.groupKeeper.CreateGroupPolicy(ctx, accountReq) suite.Require().NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgUpdateGroupPolicyMetadata(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.groupKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -789,12 +710,6 @@ func (suite *SimTestSuite) TestSimulateLeaveGroup() { _, err = suite.groupKeeper.CreateGroupPolicy(ctx, accountReq) require.NoError(err) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - require.NoError(err) - // execute operation op := simulation.SimulateMsgLeaveGroup(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.groupKeeper, suite.accountKeeper, suite.bankKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") From 066eaffbfb47582f61fb3a44f69d909a0528000c Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:44:19 +0200 Subject: [PATCH 03/17] clean bank --- x/bank/simulation/operations_test.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 6e026ce0087d..97cc8de99649 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -4,7 +4,6 @@ import ( "math/rand" "testing" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -104,12 +103,6 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgSend(suite.txConfig, suite.accountKeeper, suite.bankKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -134,12 +127,6 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgMultiSend(suite.txConfig, suite.accountKeeper, suite.bankKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -170,13 +157,6 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { r := rand.New(s) accounts := suite.getTestingAccounts(r, accCount) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }, - ) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgSendToModuleAccount(suite.txConfig, suite.accountKeeper, suite.bankKeeper, moduleAccCount) @@ -205,12 +185,6 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { r := rand.New(s) accounts := suite.getTestingAccounts(r, accCount) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgMultiSendToModuleAccount(suite.txConfig, suite.accountKeeper, suite.bankKeeper, mAccCount) From 44e8b675cca04f437278abda2d5f846acb0a23a5 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:45:48 +0200 Subject: [PATCH 04/17] clean authz --- x/authz/simulation/operations_test.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index e5a1550cb087..8e0619f26c8e 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -123,11 +122,6 @@ func (suite *SimTestSuite) TestSimulateGrant() { blockTime := time.Now().UTC() ctx := suite.ctx.WithHeaderInfo(header.Info{Time: blockTime}) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) granter := accounts[0] grantee := accounts[1] @@ -150,12 +144,6 @@ func (suite *SimTestSuite) TestSimulateRevoke() { s := rand.NewSource(2) r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) initAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction) initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt)) @@ -164,7 +152,7 @@ func (suite *SimTestSuite) TestSimulateRevoke() { a := banktypes.NewSendAuthorization(initCoins, nil) expire := time.Now().Add(30 * time.Hour) - err = suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) suite.Require().NoError(err) // execute operation @@ -187,9 +175,6 @@ func (suite *SimTestSuite) TestSimulateExec() { s := rand.NewSource(1) r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: suite.app.LastBlockHeight() + 1, Hash: suite.app.LastCommitID().Hash}) - suite.Require().NoError(err) initAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction) initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt)) @@ -198,7 +183,7 @@ func (suite *SimTestSuite) TestSimulateExec() { a := banktypes.NewSendAuthorization(initCoins, nil) expire := suite.ctx.HeaderInfo().Time.Add(1 * time.Hour) - err = suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) + err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire) suite.Require().NoError(err) // execute operation From eefd2edd16fd65e4585f741836755febd68b346e Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:46:42 +0200 Subject: [PATCH 05/17] clean nft --- x/nft/simulation/operations_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index 4e9b2dc8e70f..92f79e69adfe 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -125,12 +124,6 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { blockTime := time.Now().UTC() ctx := suite.ctx.WithHeaderInfo(header.Info{Time: blockTime}) - // begin new block - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) // execute operation registry := suite.interfaceRegistry op := simulation.SimulateMsgSend(codec.NewProtoCodec(registry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.nftKeeper) From bf8c838d95b39c9671314985e43ab67b23397063 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 16:48:04 +0200 Subject: [PATCH 06/17] clean feegrant --- x/feegrant/simulation/operations_test.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 008517e7d02f..2a745826b42a 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -152,10 +151,6 @@ func (suite *SimTestSuite) TestSimulateMsgGrantAllowance() { addr2, err := suite.accountKeeper.AddressCodec().BytesToString(accounts[2].Address) require.NoError(err) - // new block - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) - require.NoError(err) - // execute operation op := simulation.SimulateMsgGrantAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx.WithHeaderInfo(header.Info{Time: time.Now()}), accounts, "") @@ -178,16 +173,13 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - // begin a new block - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: suite.app.LastBlockHeight() + 1, Hash: suite.app.LastCommitID().Hash}) - require.NoError(err) feeAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction) feeCoins := sdk.NewCoins(sdk.NewCoin("foo", feeAmt)) granter, grantee := accounts[0], accounts[1] oneYear := ctx.HeaderInfo().Time.AddDate(1, 0, 0) - err = suite.feegrantKeeper.GrantAllowance( + err := suite.feegrantKeeper.GrantAllowance( ctx, granter.Address, grantee.Address, From 03cda703cdc861bebc330bf2d76ab350efe54530 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 24 Oct 2023 17:13:40 +0200 Subject: [PATCH 07/17] finished most of cleanup --- x/distribution/simulation/operations_test.go | 17 ----------------- x/protocolpool/simulation/operations_test.go | 7 ------- x/slashing/app_test.go | 3 --- x/slashing/simulation/operations.go | 1 + x/slashing/simulation/operations_test.go | 2 +- x/staking/app_test.go | 6 ------ 6 files changed, 2 insertions(+), 34 deletions(-) diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index c4ad83634b51..a4d63beca166 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -4,7 +4,6 @@ import ( "math/rand" "testing" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -74,11 +73,6 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { r := rand.New(s) accounts := suite.getTestingAccounts(r, 3) - _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) // execute operation op := simulation.SimulateMsgSetWithdrawAddress(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -119,12 +113,6 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { suite.setupValidatorRewards(valBz) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) - // execute operation op := simulation.SimulateMsgWithdrawDelegatorReward(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") @@ -186,11 +174,6 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName suite.Require().NoError(suite.distrKeeper.ValidatorsAccumulatedCommission.Set(suite.ctx, val0, types.ValidatorAccumulatedCommission{Commission: valCommission})) suite.Require().NoError(suite.distrKeeper.ValidatorsAccumulatedCommission.Set(suite.ctx, genVal0, types.ValidatorAccumulatedCommission{Commission: valCommission})) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.app.LastBlockHeight() + 1, - Hash: suite.app.LastCommitID().Hash, - }) - suite.Require().NoError(err) // execute operation op := simulation.SimulateMsgWithdrawValidatorCommission(suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.distrKeeper, suite.stakingKeeper) operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") diff --git a/x/protocolpool/simulation/operations_test.go b/x/protocolpool/simulation/operations_test.go index db6e4767f62b..4e8e00560863 100644 --- a/x/protocolpool/simulation/operations_test.go +++ b/x/protocolpool/simulation/operations_test.go @@ -4,7 +4,6 @@ import ( "math/rand" "testing" - abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" @@ -113,12 +112,6 @@ func TestSimulateMsgFundCommunityPool(t *testing.T) { r := rand.New(s) accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, suite.Ctx, 3) - _, err := suite.App.FinalizeBlock(&abci.RequestFinalizeBlock{ - Height: suite.App.LastBlockHeight() + 1, - Hash: suite.App.LastCommitID().Hash, - }) - require.NoError(t, err) - // execute operation op := simulation.SimulateMsgFundCommunityPool(suite.TxConfig, suite.AccountKeeper, suite.BankKeeper, suite.PoolKeeper) operationMsg, futureOperations, err := op(r, suite.App.BaseApp, suite.Ctx, accounts, "") diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 36c26fadc433..230ecc8bc835 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -4,7 +4,6 @@ import ( "errors" "testing" - abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -97,8 +96,6 @@ func TestSlashingMsgs(t *testing.T) { require.NoError(t, err) require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1))) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) - require.NoError(t, err) ctxCheck = baseApp.NewContext(true) validator, err := stakingKeeper.GetValidator(ctxCheck, sdk.ValAddress(addr1)) require.NoError(t, err) diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index c10b682911b5..53df7054a32a 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -156,6 +156,7 @@ func SimulateMsgUnjail( } if err != nil { + panic(err) return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, errors.New(res.Log) } diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 8437dee66a09..113513321509 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -184,7 +184,7 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(suite.stakingKeeper.SetDelegation(ctx, selfDelegation)) suite.Require().NoError(suite.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(val0AccAddress, sdk.AccAddress(val0AccAddress)), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))) - // begin a new block + // begin a new block (TODO: remove this) _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: suite.app.LastBlockHeight() + 1, Hash: suite.app.LastCommitID().Hash, Time: blockTime}) suite.Require().NoError(err) // execute operation diff --git a/x/staking/app_test.go b/x/staking/app_test.go index b0ef33359b35..342adeb6d1b5 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -3,7 +3,6 @@ package staking_test import ( "testing" - abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" @@ -80,8 +79,6 @@ func TestStakingMsgs(t *testing.T) { require.NoError(t, err) require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1))) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) - require.NoError(t, err) ctxCheck = app.BaseApp.NewContext(true) validator, err := stakingKeeper.GetValidator(ctxCheck, sdk.ValAddress(addr1)) require.NoError(t, err) @@ -90,9 +87,6 @@ func TestStakingMsgs(t *testing.T) { require.Equal(t, types.Bonded, validator.Status) require.True(math.IntEq(t, bondTokens, validator.BondedTokens())) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) - require.NoError(t, err) - // edit the validator description = types.NewDescription("bar_moniker", "", "", "", "") editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1).String(), description, nil, nil) From 577bcf2d53dbcbab2fa45787cddfd852a3871823 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 25 Oct 2023 18:47:18 +0200 Subject: [PATCH 08/17] more cleanup and xp with SimDeliver --- baseapp/test_helpers.go | 11 ----------- x/authz/simulation/operations.go | 6 +++--- x/bank/simulation/operations.go | 4 ++-- x/slashing/simulation/operations.go | 2 +- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 4adc20535cf9..846879b9562d 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -40,17 +40,6 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, return gasInfo, result, err } -func (app *BaseApp) SimTxFinalizeBlock(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) { - // See comment for Check(). - bz, err := txEncoder(tx) - if err != nil { - return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) - } - - gasInfo, result, _, err := app.runTx(execModeFinalize, bz) - return gasInfo, result, err -} - // NewContextLegacy returns a new sdk.Context with the provided header func (app *BaseApp) NewContextLegacy(isCheckTx bool, header cmtproto.Header) sdk.Context { if isCheckTx { diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 4fb59812e63c..1bcebacd37c8 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -141,7 +141,7 @@ func SimulateMsgGrant( return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, "unable to generate mock tx"), nil, err } - _, _, err = app.SimTxFinalizeBlock(txCfg.TxEncoder(), tx) + _, _, err = app.SimDeliver(txCfg.TxEncoder(), tx) if err != nil { return simtypes.NoOpMsg(authz.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } @@ -218,7 +218,7 @@ func SimulateMsgRevoke( return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevoke, err.Error()), nil, err } - _, _, err = app.SimTxFinalizeBlock(txCfg.TxEncoder(), tx) + _, _, err = app.SimDeliver(txCfg.TxEncoder(), tx) if err != nil { return simtypes.NoOpMsg(authz.ModuleName, TypeMsgRevoke, "unable to execute tx: "+err.Error()), nil, err } @@ -318,7 +318,7 @@ func SimulateMsgExec( return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, err } - _, _, err = app.SimTxFinalizeBlock(txCfg.TxEncoder(), tx) + _, _, err = app.SimDeliver(txCfg.TxEncoder(), tx) if err != nil { return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, err } diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 60bfac85845f..2bbbd9749eb3 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -174,7 +174,7 @@ func sendMsgSend( return err } - _, _, err = app.SimTxFinalizeBlock(txGen.TxEncoder(), tx) + _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { return err } @@ -390,7 +390,7 @@ func sendMsgMultiSend( if err != nil { return err } - _, _, err = app.SimTxFinalizeBlock(txGen.TxEncoder(), tx) + _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { return err } diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 53df7054a32a..4b799683746d 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -131,7 +131,7 @@ func SimulateMsgUnjail( return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } - _, res, err := app.SimDeliver(txGen.TxEncoder(), tx) + _, res, err := app.SimDeliver(ctx, txGen.TxEncoder(), tx) // result should fail if: // - validator cannot be unjailed due to tombstone From 2f75dc5cd6fd2ba317d9785157dcda437e99f45e Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 25 Oct 2023 21:39:58 +0200 Subject: [PATCH 09/17] add AdvanceBlock --- testutil/sims/app_helpers.go | 5 +++++ x/bank/keeper/collections_test.go | 6 +++--- x/bank/keeper/keeper_test.go | 26 +++++++++++------------- x/slashing/simulation/operations.go | 2 +- x/slashing/simulation/operations_test.go | 7 +++---- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 04abc34fac3a..00cc9b2e775d 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -181,6 +181,11 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon return app, nil } +func AdvanceBlock(app *runtime.App, blockTime time.Time) error { + _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Hash: app.LastCommitID().Hash, Time: blockTime}) + return err +} + // GenesisStateWithValSet returns a new genesis state with the validator set func GenesisStateWithValSet( codec codec.Codec, diff --git a/x/bank/keeper/collections_test.go b/x/bank/keeper/collections_test.go index 15c22c489d06..1261e083268f 100644 --- a/x/bank/keeper/collections_test.go +++ b/x/bank/keeper/collections_test.go @@ -2,13 +2,13 @@ package keeper_test import ( "testing" + "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/collections" + "cosmossdk.io/core/header" "cosmossdk.io/log" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -27,7 +27,7 @@ import ( func TestBankStateCompatibility(t *testing.T) { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() storeService := runtime.NewKVStoreService(key) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 0bac7d33ee31..df50603c9b0c 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -11,8 +11,6 @@ import ( "time" abci "github.com/cometbft/cometbft/abci/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" @@ -130,7 +128,7 @@ func TestKeeperTestSuite(t *testing.T) { func (suite *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(banktypes.StoreKey) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig() storeService := runtime.NewKVStoreService(key) @@ -1209,7 +1207,7 @@ func (suite *KeeperTestSuite) TestSendCoinsWithRestrictions() { func (suite *KeeperTestSuite) TestSendCoins_Invalid_SendLockedCoins() { balances := sdk.NewCoins(newFooCoin(50)) - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) @@ -1231,7 +1229,7 @@ func (suite *KeeperTestSuite) TestSendCoins_Invalid_NoSpendableCoins() { coins := sdk.NewCoins(coin) balances := coins - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := coins @@ -1255,7 +1253,7 @@ func (suite *KeeperTestSuite) TestSendCoins_Invalid_NoSpendableCoins() { func (suite *KeeperTestSuite) TestValidateBalance() { ctx := suite.ctx require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) @@ -1453,7 +1451,7 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() { func (suite *KeeperTestSuite) TestSpendableCoins() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) @@ -1487,7 +1485,7 @@ func (suite *KeeperTestSuite) TestSpendableCoins() { func (suite *KeeperTestSuite) TestVestingAccountSend() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) @@ -1517,7 +1515,7 @@ func (suite *KeeperTestSuite) TestVestingAccountSend() { func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) @@ -1552,7 +1550,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() { func (suite *KeeperTestSuite) TestVestingAccountReceive() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) @@ -1585,7 +1583,7 @@ func (suite *KeeperTestSuite) TestVestingAccountReceive() { func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) @@ -1623,7 +1621,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() { func (suite *KeeperTestSuite) TestDelegateCoins() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) @@ -1631,7 +1629,7 @@ func (suite *KeeperTestSuite) TestDelegateCoins() { acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.HeaderInfo().Time.Unix(), endTime.Unix()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1681,7 +1679,7 @@ func (suite *KeeperTestSuite) TestDelegateCoins_Invalid() { func (suite *KeeperTestSuite) TestUndelegateCoins() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - now := cmttime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 4b799683746d..53df7054a32a 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -131,7 +131,7 @@ func SimulateMsgUnjail( return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } - _, res, err := app.SimDeliver(ctx, txGen.TxEncoder(), tx) + _, res, err := app.SimDeliver(txGen.TxEncoder(), tx) // result should fail if: // - validator cannot be unjailed due to tombstone diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 113513321509..2e5b639b01df 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - abci "github.com/cometbft/cometbft/abci/types" cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -184,9 +183,9 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(suite.stakingKeeper.SetDelegation(ctx, selfDelegation)) suite.Require().NoError(suite.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(val0AccAddress, sdk.AccAddress(val0AccAddress)), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))) - // begin a new block (TODO: remove this) - _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: suite.app.LastBlockHeight() + 1, Hash: suite.app.LastCommitID().Hash, Time: blockTime}) - suite.Require().NoError(err) + // Skip to next block with a new block time + simtestutil.AdvanceBlock(suite.app, blockTime) + // execute operation op := simulation.SimulateMsgUnjail(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper) operationMsg, futureOperations, err := op(suite.r, suite.app.BaseApp, ctx, suite.accounts, "") From 6dad1ec3282181549e339b7388c8cdab72ca1dc0 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 25 Oct 2023 21:59:33 +0200 Subject: [PATCH 10/17] some fixes --- x/auth/ante/feegrant_test.go | 8 -------- x/auth/vesting/fuzz_test.go | 6 ++---- x/auth/vesting/msg_server_test.go | 6 +++--- x/bank/keeper/keeper_test.go | 8 ++++---- x/genutil/types/genesis.go | 3 +-- x/group/keeper/keeper_test.go | 3 +-- 6 files changed, 11 insertions(+), 23 deletions(-) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index ae680a9ebfbd..ffc8fe97f849 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -7,12 +7,9 @@ import ( "testing" "time" - "github.com/cometbft/cometbft/crypto" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -190,11 +187,6 @@ func TestDeductFeesNoDelegation(t *testing.T) { } } -// don't consume any gas -func SigGasNoConsumer(meter storetypes.GasMeter, sig []byte, pubkey crypto.PubKey, params authtypes.Params) error { - return nil -} - func genTxWithFeeGranter(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, feeGranter sdk.AccAddress, priv ...cryptotypes.PrivKey, ) (sdk.Tx, error) { diff --git a/x/auth/vesting/fuzz_test.go b/x/auth/vesting/fuzz_test.go index 4406ef647e55..4b6020b79630 100644 --- a/x/auth/vesting/fuzz_test.go +++ b/x/auth/vesting/fuzz_test.go @@ -5,11 +5,10 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/golang/mock/gomock" fuzz "github.com/google/gofuzz" + "cosmossdk.io/core/header" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -118,8 +117,7 @@ func FuzzMsgServerCreateVestingAccount(f *testing.F) { msgServer := NewMsgServerImpl(accountKeeper, bankKeeper) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()}) - + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) _, _ = msgServer.CreateVestingAccount(ctx, va) }) } diff --git a/x/auth/vesting/msg_server_test.go b/x/auth/vesting/msg_server_test.go index 7ca30a1a7f91..df4daedc2374 100644 --- a/x/auth/vesting/msg_server_test.go +++ b/x/auth/vesting/msg_server_test.go @@ -4,11 +4,10 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/header" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -46,7 +45,8 @@ func (s *VestingTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(authtypes.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) - s.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()}) + s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) + encCfg := moduletestutil.MakeTestEncodingConfig() maccPerms := map[string][]string{} diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index df50603c9b0c..22b969a2c87e 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1459,7 +1459,7 @@ func (suite *KeeperTestSuite) TestSpendableCoins() { acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1526,7 +1526,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() { } acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1558,7 +1558,7 @@ func (suite *KeeperTestSuite) TestVestingAccountReceive() { acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1596,7 +1596,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() { vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, } - vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), periods) + vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) diff --git a/x/genutil/types/genesis.go b/x/genutil/types/genesis.go index 3c322fa086fd..b5b335ca1337 100644 --- a/x/genutil/types/genesis.go +++ b/x/genutil/types/genesis.go @@ -14,7 +14,6 @@ import ( cmtjson "github.com/cometbft/cometbft/libs/json" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/cosmos/cosmos-sdk/version" ) @@ -68,7 +67,7 @@ func (ag *AppGenesis) ValidateAndComplete() error { } if ag.GenesisTime.IsZero() { - ag.GenesisTime = cmttime.Now() + ag.GenesisTime = time.Now().Round(0).UTC() } if err := ag.Consensus.ValidateAndComplete(); err != nil { diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 98ef2f089294..02e2ae0de01e 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - cmttime "github.com/cometbft/cometbft/types/time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" @@ -48,7 +47,7 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - s.blockTime = cmttime.Now() + s.blockTime = time.Now() key := storetypes.NewKVStoreKey(group.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) From bb5d0b11305aa8f47833f2c287ffec91bad3e0d1 Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 10:04:21 +0200 Subject: [PATCH 11/17] remove AdvanceBlock --- testutil/sims/app_helpers.go | 5 ----- x/slashing/simulation/operations.go | 1 - x/slashing/simulation/operations_test.go | 6 ++++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 00cc9b2e775d..04abc34fac3a 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -181,11 +181,6 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon return app, nil } -func AdvanceBlock(app *runtime.App, blockTime time.Time) error { - _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Hash: app.LastCommitID().Hash, Time: blockTime}) - return err -} - // GenesisStateWithValSet returns a new genesis state with the validator set func GenesisStateWithValSet( codec codec.Codec, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 53df7054a32a..c10b682911b5 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -156,7 +156,6 @@ func SimulateMsgUnjail( } if err != nil { - panic(err) return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, errors.New(res.Log) } diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 2e5b639b01df..9ed68f4ec316 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + abci "github.com/cometbft/cometbft/abci/types" cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -183,8 +184,9 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(suite.stakingKeeper.SetDelegation(ctx, selfDelegation)) suite.Require().NoError(suite.distrKeeper.DelegatorStartingInfo.Set(ctx, collections.Join(val0AccAddress, sdk.AccAddress(val0AccAddress)), distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))) - // Skip to next block with a new block time - simtestutil.AdvanceBlock(suite.app, blockTime) + // begin a new block + _, err = suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: suite.app.LastBlockHeight() + 1, Hash: suite.app.LastCommitID().Hash, Time: blockTime}) + suite.Require().NoError(err) // execute operation op := simulation.SimulateMsgUnjail(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper) From 0df3017b800db635b3daef0b10860d0e0499ae5a Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 10:12:45 +0200 Subject: [PATCH 12/17] more cleanup --- x/auth/vesting/types/vesting_account_test.go | 43 ++++++++++---------- x/authz/keeper/genesis_test.go | 5 ++- x/distribution/keeper/allocation_test.go | 8 ++-- x/distribution/keeper/keeper_test.go | 4 +- x/evidence/keeper/keeper_test.go | 4 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index b0776c1d6d95..3366d1ea5a30 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - tmtime "github.com/cometbft/cometbft/types/time" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -66,7 +65,7 @@ func (s *VestingAccountTestSuite) SetupTest() { } func TestGetVestedCoinsContVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) @@ -102,7 +101,7 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) { } func TestGetVestingCoinsContVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) @@ -134,7 +133,7 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) { } func TestSpendableCoinsContVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) @@ -166,7 +165,7 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { } func TestTrackDelegationContVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -207,7 +206,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { } func TestTrackUndelegationContVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -255,7 +254,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { } func TestGetVestedCoinsDelVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -272,7 +271,7 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) { } func TestGetVestingCoinsDelVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -289,7 +288,7 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) { } func TestSpendableCoinsDelVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -319,7 +318,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { } func TestTrackDelegationDelVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -357,7 +356,7 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) { } func TestTrackUndelegationDelVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -406,7 +405,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { } func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) periods := types.Periods{ types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, @@ -451,7 +450,7 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { } func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) { - now := tmtime.Now() + now := time.Now() tests := []struct { name string periods []types.Period @@ -502,7 +501,7 @@ func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) { } func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) periods := types.Periods{ types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, @@ -540,7 +539,7 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { } func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) periods := types.Periods{ types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, @@ -568,7 +567,7 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { } func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) periods := types.Periods{ types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, @@ -630,7 +629,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { } func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(24 * time.Hour) periods := types.Periods{ types.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, @@ -691,7 +690,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { } func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -708,7 +707,7 @@ func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) { } func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -725,7 +724,7 @@ func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) { } func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -750,7 +749,7 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) { } func TestTrackDelegationPermLockedVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) bacc, origCoins := initBaseAccount() @@ -780,7 +779,7 @@ func TestTrackDelegationPermLockedVestingAcc(t *testing.T) { } func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { - now := tmtime.Now() + now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) bacc, origCoins := initBaseAccount() diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index 67b3611e7af8..58c7cdcc092a 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/header" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -46,7 +46,8 @@ func (suite *GenesisTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(keeper.StoreKey) storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(suite.T(), key, storetypes.NewTransientStoreKey("transient_test")) - suite.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) + suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}) // gomock initializations diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 8b9bf449ab13..54e5c34c44c6 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -4,12 +4,12 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/collections" "cosmossdk.io/core/comet" + "cosmossdk.io/core/header" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -32,7 +32,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -91,7 +91,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -221,7 +221,7 @@ func TestAllocateTokensTruncation(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 69359ab91d28..48a79196ab8c 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" @@ -39,7 +39,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now()}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) addrs := simtestutil.CreateIncrementalAccounts(2) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index 7e10dba12722..714472e6eeca 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -6,11 +6,11 @@ import ( "fmt" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" "cosmossdk.io/collections" + "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/evidence" "cosmossdk.io/x/evidence/exported" @@ -113,7 +113,7 @@ func (suite *KeeperTestSuite) SetupTest() { router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(evidenceKeeper)) evidenceKeeper.SetRouter(router) - suite.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + suite.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) suite.encCfg = moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{}) suite.accountKeeper = accountKeeper From bf098e1815e01d954bb6d038084f062789536145 Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 10:43:21 +0200 Subject: [PATCH 13/17] some fixes --- x/group/keeper/keeper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 02e2ae0de01e..488537aa002d 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -47,7 +47,7 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - s.blockTime = time.Now() + s.blockTime = time.Now().Round(0).UTC() key := storetypes.NewKVStoreKey(group.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) From 77eea9f32332a88afc8b74260ff896b095cbb590 Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 10:47:35 +0200 Subject: [PATCH 14/17] go mod tidy --- x/nft/go.mod | 2 +- x/protocolpool/go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/nft/go.mod b/x/nft/go.mod index 4a2371d67d8e..d16106c29148 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/math v1.1.3-rc.1 cosmossdk.io/store v1.0.0-rc.0 cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 - github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.51.0 github.com/cosmos/gogoproto v1.4.11 @@ -41,6 +40,7 @@ require ( github.com/cockroachdb/pebble v0.0.0-20230824192853-9bb0864bdb98 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft v0.38.0 // indirect github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.0 // indirect diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index e3ddac6e1c2a..5b85d9be80f2 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/x/distribution v0.0.0-20230925135524-a1bc045b3190 cosmossdk.io/x/gov v0.0.0-20230925135524-a1bc045b3190 cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 - github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.51.0 github.com/cosmos/gogoproto v1.4.11 @@ -45,6 +44,7 @@ require ( github.com/cockroachdb/pebble v0.0.0-20230824192853-9bb0864bdb98 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft v0.38.0 // indirect github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.0 // indirect From ebaf4231a08faf4cdfe5f116389a5668cfffbf3f Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 10:52:40 +0200 Subject: [PATCH 15/17] go mod tidy --- x/distribution/keeper/delegation_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index e004d36ca2e5..8a17df9eaa94 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -3,11 +3,11 @@ package keeper_test import ( "testing" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/collections" + "cosmossdk.io/core/header" "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/distribution" @@ -30,7 +30,7 @@ func TestCalculateRewardsBasic(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -132,7 +132,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -237,7 +237,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -363,7 +363,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -462,7 +462,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -539,7 +539,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -657,7 +657,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -796,7 +796,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) @@ -997,7 +997,7 @@ func Test100PercentCommissionReward(t *testing.T) { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) - ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Height: 1}) + ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 1}) bankKeeper := distrtestutil.NewMockBankKeeper(ctrl) stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl) From 88134a7c0e881fa0933e8db17867b3095cb206fa Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 11:37:08 +0200 Subject: [PATCH 16/17] a bit more --- tests/integration/bank/app_test.go | 12 ++++++------ testutil/sims/tx_helpers.go | 4 ++-- x/evidence/genesis_test.go | 3 +-- x/feegrant/simulation/operations_test.go | 3 +-- x/slashing/app_test.go | 6 +++--- x/staking/app_test.go | 18 +++++++++--------- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index 62ce4c7b629f..68c39dd9d150 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -4,10 +4,10 @@ import ( "testing" abci "github.com/cometbft/cometbft/abci/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" @@ -168,7 +168,7 @@ func TestSendNotEnoughBalance(t *testing.T) { origSeq := res1.GetSequence() sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) - header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1} + header := header.Info{Height: baseApp.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() _, _, err = simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) @@ -248,7 +248,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { t.Logf("testing %s", tc.desc) - header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1} + header := header.Info{Height: baseApp.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { @@ -300,7 +300,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { } for _, tc := range testCases { - header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1} + header := header.Info{Height: baseApp.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) @@ -355,7 +355,7 @@ func TestMsgMultiSendDependent(t *testing.T) { } for _, tc := range testCases { - header := cmtproto.Header{Height: baseApp.LastBlockHeight() + 1} + header := header.Info{Height: baseApp.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() _, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) @@ -434,7 +434,7 @@ func TestMsgSetSendEnabled(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(tt *testing.T) { - header := cmtproto.Header{Height: s.App.LastBlockHeight() + 1} + header := header.Info{Height: s.App.LastBlockHeight() + 1} txGen := moduletestutil.MakeTestTxConfig() _, _, err = simtestutil.SignCheckDeliver(tt, txGen, s.App.BaseApp, header, tc.msgs, "", []uint64{0}, tc.accSeqs, tc.expSimPass, tc.expPass, priv1) if len(tc.expInError) > 0 { diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index f334925bcec1..96a2054f638a 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -7,9 +7,9 @@ import ( "time" types2 "github.com/cometbft/cometbft/abci/types" - "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/baseapp" @@ -93,7 +93,7 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee // the parameter 'expPass' against the result. A corresponding result is // returned. func SignCheckDeliver( - t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header types.Header, msgs []sdk.Msg, + t *testing.T, txCfg client.TxConfig, app *baseapp.BaseApp, header header.Info, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { t.Helper() diff --git a/x/evidence/genesis_test.go b/x/evidence/genesis_test.go index 600f61cad7d1..2a1c542166d5 100644 --- a/x/evidence/genesis_test.go +++ b/x/evidence/genesis_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -40,7 +39,7 @@ func (suite *GenesisTestSuite) SetupTest() { &evidenceKeeper) require.NoError(suite.T(), err) - suite.ctx = app.BaseApp.NewContextLegacy(false, cmtproto.Header{Height: 1}) + suite.ctx = app.BaseApp.NewContext(false) suite.keeper = evidenceKeeper } diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index e6ea488752d1..72b2196d75d7 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -77,7 +76,7 @@ func (suite *SimTestSuite) SetupTest() { ) suite.Require().NoError(err) - suite.ctx = suite.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()}) + suite.ctx = suite.app.BaseApp.NewContext(false).WithHeaderInfo(header.Info{Time: time.Now()}) } func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index e5e250b2fc2b..5fad89778dbe 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -4,9 +4,9 @@ import ( "errors" "testing" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/math" @@ -90,7 +90,7 @@ func TestSlashingMsgs(t *testing.T) { ) require.NoError(t, err) - header := cmtproto.Header{Height: app.LastBlockHeight() + 1} + header := header.Info{Height: app.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) @@ -110,7 +110,7 @@ func TestSlashingMsgs(t *testing.T) { require.NoError(t, err) // unjail should fail with unknown validator - header = cmtproto.Header{Height: app.LastBlockHeight() + 1} + header = header.Info{Height: app.LastBlockHeight() + 1} _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 4fa34021b861..921648d7c501 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -3,10 +3,10 @@ package staking_test import ( "testing" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" "cosmossdk.io/collections" + "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/math" @@ -73,9 +73,9 @@ func TestStakingMsgs(t *testing.T) { ) require.NoError(t, err) - header := cmtproto.Header{Height: app.LastBlockHeight() + 1} + headerInfo := header.Info{Height: app.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() - _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) + _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1))) @@ -91,8 +91,8 @@ func TestStakingMsgs(t *testing.T) { description = types.NewDescription("bar_moniker", "", "", "", "") editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1).String(), description, nil, nil) - header = cmtproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, priv1) + headerInfo = header.Info{Height: app.LastBlockHeight() + 1} + _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{editValidatorMsg}, "", []uint64{0}, []uint64{1}, true, true, priv1) require.NoError(t, err) ctxCheck = app.BaseApp.NewContext(true) @@ -104,8 +104,8 @@ func TestStakingMsgs(t *testing.T) { require.True(t, sdk.Coins{genCoin}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr2))) delegateMsg := types.NewMsgDelegate(addr2.String(), sdk.ValAddress(addr1).String(), bondCoin) - header = cmtproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2) + headerInfo = header.Info{Height: app.LastBlockHeight() + 1} + _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{delegateMsg}, "", []uint64{1}, []uint64{0}, true, true, priv2) require.NoError(t, err) ctxCheck = app.BaseApp.NewContext(true) @@ -115,8 +115,8 @@ func TestStakingMsgs(t *testing.T) { // begin unbonding beginUnbondingMsg := types.NewMsgUndelegate(addr2.String(), sdk.ValAddress(addr1).String(), bondCoin) - header = cmtproto.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, "", []uint64{1}, []uint64{1}, true, true, priv2) + headerInfo = header.Info{Height: app.LastBlockHeight() + 1} + _, _, err = simtestutil.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{beginUnbondingMsg}, "", []uint64{1}, []uint64{1}, true, true, priv2) require.NoError(t, err) // delegation should exist anymore From 608d377c9856d52dab73bbfd2338a69d32831ba6 Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 26 Oct 2023 11:50:25 +0200 Subject: [PATCH 17/17] fix --- x/slashing/app_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 5fad89778dbe..502255de1f42 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -90,9 +90,9 @@ func TestSlashingMsgs(t *testing.T) { ) require.NoError(t, err) - header := header.Info{Height: app.LastBlockHeight() + 1} + headerInfo := header.Info{Height: app.LastBlockHeight() + 1} txConfig := moduletestutil.MakeTestTxConfig() - _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) + _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1))) @@ -110,8 +110,8 @@ func TestSlashingMsgs(t *testing.T) { require.NoError(t, err) // unjail should fail with unknown validator - header = header.Info{Height: app.LastBlockHeight() + 1} - _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) + headerInfo = header.Info{Height: app.LastBlockHeight() + 1} + _, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) }