Skip to content

Commit

Permalink
added test for updateTxHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 4, 2024
1 parent 08771d4 commit 7549699
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
47 changes: 47 additions & 0 deletions x/smartaccount/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions x/smartaccount/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 36 in x/smartaccount/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/smartaccount/types/msgs.go#L33-L36

Added lines #L33 - L36 were not covered by tests
}
}

// GetSignBytes implements the LegacyMsg interface.
func (m MsgCreateSmartAccount) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))

Check warning on line 42 in x/smartaccount/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/smartaccount/types/msgs.go#L42

Added line #L42 was not covered by tests
Expand Down

0 comments on commit 7549699

Please sign in to comment.