From a859d3a60478b5aa5ee40c4c1bcd74834926c48d Mon Sep 17 00:00:00 2001 From: freeelancer Date: Sat, 2 Mar 2024 08:46:09 +0800 Subject: [PATCH] fix tests --- app/genesis_test.go | 31 +++++++++++++++++++ x/smartaccount/ante/tests/ante_test.go | 12 ++++--- .../ante/tests/pretransaction_test.go | 10 +++--- x/smartaccount/types/codec_test.go | 8 ++--- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/app/genesis_test.go b/app/genesis_test.go index 9ec8bc3a..a128fa7e 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -20,6 +20,7 @@ import ( "github.com/terra-money/alliance/x/alliance" "github.com/terra-money/core/v2/app" "github.com/terra-money/core/v2/x/feeshare" + "github.com/terra-money/core/v2/x/smartaccount" "github.com/terra-money/core/v2/x/tokenfactory" mocktestutils "github.com/cosmos/cosmos-sdk/testutil/mock" @@ -224,6 +225,7 @@ func (s *AppGenesisTestSuite) TestMigration() { "upgrade": upgrade.AppModule{}.ConsensusVersion(), "vesting": vesting.AppModule{}.ConsensusVersion(), "wasm": wasm.AppModule{}.ConsensusVersion(), + "smartaccount": smartaccount.AppModule{}.ConsensusVersion(), }, ) s.Require().NoError(err) @@ -257,6 +259,7 @@ func (s *AppGenesisTestSuite) TestMigration() { "upgrade": 2, "vesting": 1, "wasm": 4, + "smartaccount": 1, }) } @@ -685,6 +688,34 @@ func (s *AppGenesisTestSuite) TestGenesis() { "redelegations": [], "exported": false }, + "smartaccount": { + "params": { + }, + "settings": [ + ] + }, + "staking": { + "delegations": [ + ], + "exported": false, + "last_total_power": "0", + "last_validator_powers": [ + ], + "params": { + "bond_denom": "uluna", + "historical_entries": 10000, + "max_entries": 7, + "max_validators": 100, + "min_commission_rate": "0.000000000000000000", + "unbonding_time": "1814400s" + }, + "redelegations": [ + ], + "unbonding_delegations": [ + ], + "validators": [ + ] + }, "tokenfactory": { "params": { "denom_creation_fee": [ diff --git a/x/smartaccount/ante/tests/ante_test.go b/x/smartaccount/ante/tests/ante_test.go index 8a6d14a5..ef42c946 100644 --- a/x/smartaccount/ante/tests/ante_test.go +++ b/x/smartaccount/ante/tests/ante_test.go @@ -22,8 +22,9 @@ import ( type AnteTestSuite struct { test_helpers.SmartAccountTestSuite - Decorator ante.SmartAccountAuthDecorator - WasmKeeper *wasmkeeper.PermissionedKeeper + AuthDecorator ante.SmartAccountAuthDecorator + PreTxDecorator ante.PreTransactionHookDecorator + WasmKeeper *wasmkeeper.PermissionedKeeper } func TestAnteSuite(t *testing.T) { @@ -33,7 +34,8 @@ func TestAnteSuite(t *testing.T) { func (s *AnteTestSuite) Setup() { s.SmartAccountTestSuite.SetupTests() s.WasmKeeper = wasmkeeper.NewDefaultPermissionKeeper(s.App.Keepers.WasmKeeper) - s.Decorator = ante.NewSmartAccountAuthDecorator(s.SmartAccountKeeper, s.WasmKeeper, s.App.Keepers.AccountKeeper, nil, s.EncodingConfig.TxConfig.SignModeHandler()) + s.AuthDecorator = ante.NewSmartAccountAuthDecorator(s.SmartAccountKeeper, s.WasmKeeper, s.App.Keepers.AccountKeeper, nil, s.EncodingConfig.TxConfig.SignModeHandler()) + s.PreTxDecorator = ante.NewPreTransactionHookDecorator(s.SmartAccountKeeper, s.WasmKeeper) s.Ctx = s.Ctx.WithChainID("test") } @@ -81,7 +83,7 @@ func (s *AnteTestSuite) TestAuthAnteHandler() { ToAddress: acc.String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 1)), }) - _, err = s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err = s.AuthDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.Error(s.T(), err) // signing with testAcc0 pk which should pass @@ -90,7 +92,7 @@ func (s *AnteTestSuite) TestAuthAnteHandler() { ToAddress: acc.String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 1)), }) - _, err = s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err = s.AuthDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.NoError(s.T(), err) } diff --git a/x/smartaccount/ante/tests/pretransaction_test.go b/x/smartaccount/ante/tests/pretransaction_test.go index dee3b642..27e34c76 100644 --- a/x/smartaccount/ante/tests/pretransaction_test.go +++ b/x/smartaccount/ante/tests/pretransaction_test.go @@ -16,7 +16,7 @@ func (s *AnteTestSuite) TestPreTransactionHookWithoutSmartAccount() { ToAddress: s.TestAccs[1].String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)), }) - _, err := s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err := s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.NoError(s.T(), err) } @@ -28,7 +28,7 @@ func (s *AnteTestSuite) TestPreTransactionHookWithEmptySmartAccount() { ToAddress: s.TestAccs[1].String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)), }) - _, err := s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err := s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.NoError(s.T(), err) } @@ -42,7 +42,7 @@ func (s *AnteTestSuite) TestInvalidContractAddress() { ToAddress: s.TestAccs[1].String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)), }) - _, err := s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err := s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.ErrorContainsf(s.T(), err, "no such contract", "error message: %s", err) } @@ -63,7 +63,7 @@ func (s *AnteTestSuite) TestSendCoinsWithLimitSendHook() { ToAddress: acc.String(), Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 100000000)), }) - _, err = s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err = s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.NoError(s.T(), err) } @@ -84,6 +84,6 @@ func (s *AnteTestSuite) TestStakingWithLimitSendHook() { ValidatorAddress: acc.String(), Amount: sdk.NewInt64Coin("uluna", 100000000), }) - _, err = s.Decorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) + _, err = s.PreTxDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{})) require.ErrorContainsf(s.T(), err, "Unauthorized message type", "error message: %s", err) } diff --git a/x/smartaccount/types/codec_test.go b/x/smartaccount/types/codec_test.go index 0aee7ea9..7c54de29 100644 --- a/x/smartaccount/types/codec_test.go +++ b/x/smartaccount/types/codec_test.go @@ -25,9 +25,9 @@ func (suite *CodecTestSuite) TestRegisterInterfaces() { impls := registry.ListImplementations(sdk.MsgInterfaceProtoName) suite.Require().Equal(4, len(impls)) suite.Require().ElementsMatch([]string{ - "/juno.feeshare.v1.MsgRegisterFeeShare", - "/juno.feeshare.v1.MsgCancelFeeShare", - "/juno.feeshare.v1.MsgUpdateFeeShare", - "/juno.feeshare.v1.MsgUpdateParams", + "/terra.smartaccount.v1.MsgCreateSmartAccount", + "/terra.smartaccount.v1.MsgUpdateAuthorization", + "/terra.smartaccount.v1.MsgUpdateTransactionHooks", + "/terra.smartaccount.v1.MsgDisableSmartAccount", }, impls) }