From cd8d5a0573d06c14f87ecc4ae4a3e63560419a26 Mon Sep 17 00:00:00 2001 From: Akhil Kumar P <36399231+akhilkumarpilli@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:42:15 +0530 Subject: [PATCH] test(accounts): fix integration tests (#22418) (cherry picked from commit 78f08e8cacd902a28a0e283b2ed9f5f47a00a6d2) --- simapp/app_di.go | 23 ++++++++++++------- .../integration/accounts/base_account_test.go | 21 +++++++++++++++-- tests/integration/accounts/wiring_test.go | 2 -- tests/integration/baseapp/block_gas_test.go | 2 +- .../testing/account_abstraction/minimal.go | 4 ++++ x/accounts/testing/counter/counter.go | 4 ++++ x/validate/depinject.go | 17 +++++++------- 7 files changed, 52 insertions(+), 21 deletions(-) diff --git a/simapp/app_di.go b/simapp/app_di.go index 84fc11b063a4..4597ff8be733 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -21,6 +21,8 @@ import ( basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject" multisigdepinject "cosmossdk.io/x/accounts/defaults/multisig/depinject" + "cosmossdk.io/x/accounts/testing/account_abstraction" + "cosmossdk.io/x/accounts/testing/counter" bankkeeper "cosmossdk.io/x/bank/keeper" circuitkeeper "cosmossdk.io/x/circuit/keeper" consensuskeeper "cosmossdk.io/x/consensus/keeper" @@ -184,6 +186,10 @@ func NewSimApp( // return fmt.Errorf("invalid pub key size") // } // }) + + // TESTING: do not add below account types + counter.ProvideAccount, + account_abstraction.ProvideAccount, ), ) ) @@ -300,14 +306,15 @@ func (app *SimApp) setCustomAnteHandler() { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ - AccountKeeper: app.AuthKeeper, - BankKeeper: app.BankKeeper, - ConsensusKeeper: app.ConsensusParamsKeeper, - SignModeHandler: app.txConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - UnorderedTxManager: app.UnorderedTxManager, - Environment: app.AuthKeeper.Environment, + AccountKeeper: app.AuthKeeper, + BankKeeper: app.BankKeeper, + ConsensusKeeper: app.ConsensusParamsKeeper, + SignModeHandler: app.txConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + UnorderedTxManager: app.UnorderedTxManager, + Environment: app.AuthKeeper.Environment, + AccountAbstractionKeeper: app.AccountsKeeper, }, &app.CircuitBreakerKeeper, }, diff --git a/tests/integration/accounts/base_account_test.go b/tests/integration/accounts/base_account_test.go index bfaee8bbb357..367f099984d4 100644 --- a/tests/integration/accounts/base_account_test.go +++ b/tests/integration/accounts/base_account_test.go @@ -1,5 +1,3 @@ -//go:build app_v1 - package accounts import ( @@ -15,12 +13,18 @@ import ( banktypes "cosmossdk.io/x/bank/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) +var ( + privKey = secp256k1.GenPrivKey() + accCreator = []byte("creator") +) + func TestBaseAccount(t *testing.T) { app := setupApp(t) ak := app.AccountsKeeper @@ -95,3 +99,16 @@ func toAnyPb(t *testing.T, pm gogoproto.Message) *codectypes.Any { require.NoError(t, err) return pb } + +func coins(t *testing.T, s string) sdk.Coins { + t.Helper() + coins, err := sdk.ParseCoinsNormalized(s) + require.NoError(t, err) + return coins +} + +func setupApp(t *testing.T) *simapp.SimApp { + t.Helper() + app := simapp.Setup(t, false) + return app +} diff --git a/tests/integration/accounts/wiring_test.go b/tests/integration/accounts/wiring_test.go index 86e86779408b..466bfbc2b765 100644 --- a/tests/integration/accounts/wiring_test.go +++ b/tests/integration/accounts/wiring_test.go @@ -1,5 +1,3 @@ -//go:build app_v1 - package accounts import ( diff --git a/tests/integration/baseapp/block_gas_test.go b/tests/integration/baseapp/block_gas_test.go index f883b68db9f4..97086e20db0f 100644 --- a/tests/integration/baseapp/block_gas_test.go +++ b/tests/integration/baseapp/block_gas_test.go @@ -172,7 +172,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(38142) // baseGas is the gas consumed before tx msg + baseGas := uint64(39205) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) { // capped by gasLimit diff --git a/x/accounts/testing/account_abstraction/minimal.go b/x/accounts/testing/account_abstraction/minimal.go index 30775e984261..d9a34ae9d1b4 100644 --- a/x/accounts/testing/account_abstraction/minimal.go +++ b/x/accounts/testing/account_abstraction/minimal.go @@ -74,3 +74,7 @@ func (a MinimalAbstractedAccount) RegisterExecuteHandlers(builder *accountstd.Ex func (a MinimalAbstractedAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) { accountstd.RegisterQueryHandler(builder, a.QueryAuthenticateMethods) // implements account_abstraction } + +func ProvideAccount() accountstd.DepinjectAccount { + return accountstd.DIAccount("aa_minimal", NewMinimalAbstractedAccount) +} diff --git a/x/accounts/testing/counter/counter.go b/x/accounts/testing/counter/counter.go index 33ed5128f62b..b1f8397dc960 100644 --- a/x/accounts/testing/counter/counter.go +++ b/x/accounts/testing/counter/counter.go @@ -149,3 +149,7 @@ func (a Account) RegisterExecuteHandlers(builder *accountstd.ExecuteBuilder) { func (a Account) RegisterQueryHandlers(builder *accountstd.QueryBuilder) { accountstd.RegisterQueryHandler(builder, a.QueryCounter) } + +func ProvideAccount() accountstd.DepinjectAccount { + return accountstd.DIAccount("counter", NewAccount) +} diff --git a/x/validate/depinject.go b/x/validate/depinject.go index 0c383f457abe..e0e6e14f3a0e 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -138,14 +138,15 @@ func newBaseAppOption(in ModuleInputs) func(app *baseapp.BaseApp) { func newAnteHandler(in ModuleInputs) (sdk.AnteHandler, error) { anteHandler, err := ante.NewAnteHandler( ante.HandlerOptions{ - Environment: in.Environment, - AccountKeeper: in.AccountKeeper, - ConsensusKeeper: in.ConsensusKeeper, - BankKeeper: in.BankKeeper, - SignModeHandler: in.TxConfig.SignModeHandler(), - FeegrantKeeper: in.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - UnorderedTxManager: in.UnorderedTxManager, + Environment: in.Environment, + AccountKeeper: in.AccountKeeper, + ConsensusKeeper: in.ConsensusKeeper, + BankKeeper: in.BankKeeper, + SignModeHandler: in.TxConfig.SignModeHandler(), + FeegrantKeeper: in.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + UnorderedTxManager: in.UnorderedTxManager, + AccountAbstractionKeeper: in.AccountAbstractionKeeper, }, ) if err != nil {