From 754969985434f18152ce24959267d6c3cb83e7bc Mon Sep 17 00:00:00 2001 From: freeelancer Date: Tue, 5 Mar 2024 05:29:09 +0800 Subject: [PATCH] added test for updateTxHooks --- x/smartaccount/keeper/msg_server_test.go | 47 ++++++++++++++++++++++++ x/smartaccount/types/msgs.go | 8 ++++ 2 files changed, 55 insertions(+) diff --git a/x/smartaccount/keeper/msg_server_test.go b/x/smartaccount/keeper/msg_server_test.go index 8156733a..3ae7c902 100644 --- a/x/smartaccount/keeper/msg_server_test.go +++ b/x/smartaccount/keeper/msg_server_test.go @@ -78,3 +78,50 @@ func (s *IntegrationTestSuite) TestMsgUpdateAuthorization() { s.Require().Equal(sender.String(), setting.Owner) s.Require().Equal([]*types.AuthorizationMsg{&authorization2}, setting.Authorization) } + +func (s *IntegrationTestSuite) TestMsgUpdateTransactionHooks() { + s.Setup() + sender := s.TestAccs[0] + + // Create a smart account + ms := smartaccountkeeper.NewMsgServer(s.App.Keepers.SmartAccountKeeper) + msg := types.NewMsgCreateSmartAccount(sender.String()) + _, err := ms.CreateSmartAccount(s.Ctx, msg) + s.Require().NoError(err) + + // update transaction hooks + pretx := []string{"hook1", "hook2"} + posttx := []string{"hook3", "hook4"} + msgUpdate := types.NewMsgUpdateTransactionHooks( + sender.String(), + pretx, + posttx, + ) + _, err = ms.UpdateTransactionHooks(s.Ctx, msgUpdate) + s.Require().NoError(err) + + // Ensure that the smart account was updated + setting, err := s.App.Keepers.SmartAccountKeeper.GetSetting(s.Ctx, sender.String()) + s.Require().NoError(err) + s.Require().Equal(sender.String(), setting.Owner) + s.Require().Equal(pretx, setting.PreTransaction) + s.Require().Equal(posttx, setting.PostTransaction) + + // update authorization again + pretx = []string{"hook5", "hook6"} + posttx = []string{"hook7", "hook8"} + msgUpdate = types.NewMsgUpdateTransactionHooks( + sender.String(), + pretx, + posttx, + ) + _, err = ms.UpdateTransactionHooks(s.Ctx, msgUpdate) + s.Require().NoError(err) + + // Ensure that the smart account was updated again + setting, err = s.App.Keepers.SmartAccountKeeper.GetSetting(s.Ctx, sender.String()) + s.Require().NoError(err) + s.Require().Equal(sender.String(), setting.Owner) + s.Require().Equal(pretx, setting.PreTransaction) + s.Require().Equal(posttx, setting.PostTransaction) +} diff --git a/x/smartaccount/types/msgs.go b/x/smartaccount/types/msgs.go index b52f957a..d538fb9f 100644 --- a/x/smartaccount/types/msgs.go +++ b/x/smartaccount/types/msgs.go @@ -29,6 +29,14 @@ func NewMsgUpdateAuthorization(account string, authorizationMsgs []*Authorizatio } } +func NewMsgUpdateTransactionHooks(account string, preTransactionHooks, postTransactionHooks []string) *MsgUpdateTransactionHooks { + return &MsgUpdateTransactionHooks{ + Account: account, + PreTransactionHooks: preTransactionHooks, + PostTransactionHooks: postTransactionHooks, + } +} + // GetSignBytes implements the LegacyMsg interface. func (m MsgCreateSmartAccount) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))