From 0da01d17cdae69aa38320e679418c929a342d2f8 Mon Sep 17 00:00:00 2001 From: Andrei Zavgorodnii Date: Thu, 13 Jun 2024 16:35:43 +0100 Subject: [PATCH 1/9] fix: add tf checks & tests --- x/tokenfactory/keeper/bankactions.go | 55 ++++++++++++++++------------ x/tokenfactory/keeper/keeper.go | 40 ++++++++++---------- x/tokenfactory/keeper/keeper_test.go | 40 +++++++++++++++++++- x/tokenfactory/types/msgs.go | 7 ++-- 4 files changed, 94 insertions(+), 48 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 3438f29a2..e4627d9e0 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -1,8 +1,6 @@ package keeper import ( - "sort" - sdk "github.com/cosmos/cosmos-sdk/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -17,12 +15,16 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { return err } - err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) + addr, err := sdk.AccAddressFromBech32(mintTo) if err != nil { return err } - addr, err := sdk.AccAddressFromBech32(mintTo) + if k.isModuleAccount(ctx, addr) { + return status.Errorf(codes.Internal, "minting to module accounts is forbidden") + } + + err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) if err != nil { return err } @@ -44,6 +46,10 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } + if k.isModuleAccount(ctx, addr) { + return status.Errorf(codes.Internal, "burning from module accounts is forbidden") + } + err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, @@ -62,37 +68,38 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr return err } - fromAcc, err := sdk.AccAddressFromBech32(fromAddr) + fromSdkAddr, err := sdk.AccAddressFromBech32(fromAddr) + if err != nil { + return err + } + + toSdkAddr, err := sdk.AccAddressFromBech32(toAddr) if err != nil { return err } - sortedPermAddrs := make([]string, 0, len(k.permAddrs)) - for moduleName := range k.permAddrs { - sortedPermAddrs = append(sortedPermAddrs, moduleName) + if k.isModuleAccount(ctx, fromSdkAddr) { + return status.Errorf(codes.Internal, "force transfer from module acc not available") } - sort.Strings(sortedPermAddrs) - for _, moduleName := range sortedPermAddrs { + if k.isModuleAccount(ctx, toSdkAddr) { + return status.Errorf(codes.Internal, "force transfer to module acc not available") + } + + return k.bankKeeper.SendCoins(ctx, fromSdkAddr, toSdkAddr, sdk.NewCoins(amount)) +} + +func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool { + for _, moduleName := range k.knownModuleAddresses { account := k.accountKeeper.GetModuleAccount(ctx, moduleName) if account == nil { - return status.Errorf(codes.NotFound, "account %s not found", moduleName) + return false } - if account.GetAddress().Equals(fromAcc) { - return status.Errorf(codes.Internal, "send from module acc not available") + if account.GetAddress().Equals(addr) { + return true } } - fromSdkAddr, err := sdk.AccAddressFromBech32(fromAddr) - if err != nil { - return err - } - - toSdkAddr, err := sdk.AccAddressFromBech32(toAddr) - if err != nil { - return err - } - - return k.bankKeeper.SendCoins(ctx, fromSdkAddr, toSdkAddr, sdk.NewCoins(amount)) + return false } diff --git a/x/tokenfactory/keeper/keeper.go b/x/tokenfactory/keeper/keeper.go index d4d95f743..0e25e8770 100644 --- a/x/tokenfactory/keeper/keeper.go +++ b/x/tokenfactory/keeper/keeper.go @@ -3,13 +3,12 @@ package keeper import ( "context" "fmt" + "sort" "cosmossdk.io/log" - "github.com/cosmos/cosmos-sdk/codec" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/neutron-org/neutron/v4/x/tokenfactory/types" @@ -17,13 +16,13 @@ import ( type ( Keeper struct { - storeKey storetypes.StoreKey - permAddrs map[string]authtypes.PermissionsForAddress - cdc codec.Codec - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - contractKeeper types.ContractKeeper - authority string + storeKey storetypes.StoreKey + knownModuleAddresses []string + cdc codec.Codec + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + contractKeeper types.ContractKeeper + authority string } ) @@ -37,19 +36,20 @@ func NewKeeper( contractKeeper types.ContractKeeper, authority string, ) Keeper { - permAddrs := make(map[string]authtypes.PermissionsForAddress) - for name, perms := range maccPerms { - permAddrs[name] = authtypes.NewPermissionsForAddress(name, perms) + sortedKnownModuleAddresses := make([]string, 0, len(maccPerms)) + for moduleName := range maccPerms { + sortedKnownModuleAddresses = append(sortedKnownModuleAddresses, moduleName) } + sort.Strings(sortedKnownModuleAddresses) return Keeper{ - cdc: cdc, - storeKey: storeKey, - permAddrs: permAddrs, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - contractKeeper: contractKeeper, - authority: authority, + cdc: cdc, + storeKey: storeKey, + knownModuleAddresses: sortedKnownModuleAddresses, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + contractKeeper: contractKeeper, + authority: authority, } } diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index e86df652c..c6fd3772a 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -125,6 +125,44 @@ func (suite *KeeperTestSuite) TestForceTransferMsg() { suite.Require().NoError(err) _, err = suite.msgServer.ForceTransfer(suite.ChainA.GetContext(), types.NewMsgForceTransfer(suite.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String(), suite.TestAccs[1].String())) - suite.Require().ErrorContains(err, "send from module acc not available") + suite.Require().ErrorContains(err, "force transfer from module acc not available") + }) +} + +func (suite *KeeperTestSuite) TestMintToMsg() { + suite.Setup() + + // Create a denom + suite.CreateDefaultDenom(suite.ChainA.GetContext()) + + suite.Run("test force transfer", func() { + mintAmt := sdktypes.NewInt64Coin(suite.defaultDenom, 10) + + govModAcc := suite.GetNeutronZoneApp(suite.ChainA).AccountKeeper.GetModuleAccount(suite.ChainA.GetContext(), authtypes.FeeCollectorName) + + _, err := suite.msgServer.Mint(suite.ChainA.GetContext(), types.NewMsgMintTo(suite.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String())) + suite.Require().ErrorContains(err, "minting to module accounts is forbidden") + }) +} + +func (suite *KeeperTestSuite) TestBurnFromMsg() { + suite.Setup() + + // Create a denom + suite.CreateDefaultDenom(suite.ChainA.GetContext()) + + suite.Run("test force transfer", func() { + mintAmt := sdktypes.NewInt64Coin(suite.defaultDenom, 10) + + _, err := suite.msgServer.Mint(sdktypes.WrapSDKContext(suite.ChainA.GetContext()), types.NewMsgMint(suite.TestAccs[0].String(), mintAmt)) + suite.Require().NoError(err) + + govModAcc := suite.GetNeutronZoneApp(suite.ChainA).AccountKeeper.GetModuleAccount(suite.ChainA.GetContext(), authtypes.FeeCollectorName) + + err = suite.GetNeutronZoneApp(suite.ChainA).BankKeeper.SendCoins(suite.ChainA.GetContext(), suite.TestAccs[0], govModAcc.GetAddress(), sdktypes.NewCoins(mintAmt)) + suite.Require().NoError(err) + + _, err = suite.msgServer.Burn(suite.ChainA.GetContext(), types.NewMsgBurnFrom(suite.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String())) + suite.Require().ErrorContains(err, "burning from module accounts is forbidden") }) } diff --git a/x/tokenfactory/types/msgs.go b/x/tokenfactory/types/msgs.go index 659346a8b..7207f7247 100644 --- a/x/tokenfactory/types/msgs.go +++ b/x/tokenfactory/types/msgs.go @@ -112,10 +112,11 @@ func NewMsgBurn(sender string, amount sdk.Coin) *MsgBurn { } // NewMsgBurn creates a message to burn tokens -func NewMsgBurnFrom(sender string, amount sdk.Coin, _ string) *MsgBurn { +func NewMsgBurnFrom(sender string, amount sdk.Coin, from string) *MsgBurn { return &MsgBurn{ - Sender: sender, - Amount: amount, + Sender: sender, + Amount: amount, + BurnFromAddress: from, } } From 8cbc03369fd6b8be5b0038d9724f68f3aaaae2d9 Mon Sep 17 00:00:00 2001 From: Andrei Zavgorodnii Date: Thu, 13 Jun 2024 17:48:41 +0100 Subject: [PATCH 2/9] renaming --- x/tokenfactory/keeper/bankactions.go | 2 +- x/tokenfactory/keeper/keeper.go | 34 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index e4627d9e0..284728258 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -90,7 +90,7 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr } func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool { - for _, moduleName := range k.knownModuleAddresses { + for _, moduleName := range k.knownModules { account := k.accountKeeper.GetModuleAccount(ctx, moduleName) if account == nil { return false diff --git a/x/tokenfactory/keeper/keeper.go b/x/tokenfactory/keeper/keeper.go index 0e25e8770..593e977a7 100644 --- a/x/tokenfactory/keeper/keeper.go +++ b/x/tokenfactory/keeper/keeper.go @@ -16,13 +16,13 @@ import ( type ( Keeper struct { - storeKey storetypes.StoreKey - knownModuleAddresses []string - cdc codec.Codec - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - contractKeeper types.ContractKeeper - authority string + storeKey storetypes.StoreKey + knownModules []string + cdc codec.Codec + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + contractKeeper types.ContractKeeper + authority string } ) @@ -36,20 +36,20 @@ func NewKeeper( contractKeeper types.ContractKeeper, authority string, ) Keeper { - sortedKnownModuleAddresses := make([]string, 0, len(maccPerms)) + sortedKnownModules := make([]string, 0, len(maccPerms)) for moduleName := range maccPerms { - sortedKnownModuleAddresses = append(sortedKnownModuleAddresses, moduleName) + sortedKnownModules = append(sortedKnownModules, moduleName) } - sort.Strings(sortedKnownModuleAddresses) + sort.Strings(sortedKnownModules) return Keeper{ - cdc: cdc, - storeKey: storeKey, - knownModuleAddresses: sortedKnownModuleAddresses, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - contractKeeper: contractKeeper, - authority: authority, + cdc: cdc, + storeKey: storeKey, + knownModules: sortedKnownModules, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + contractKeeper: contractKeeper, + authority: authority, } } From 138eb4555195031b8e9226ffc71edecf18bca378 Mon Sep 17 00:00:00 2001 From: Andrei Zavgorodnii Date: Thu, 13 Jun 2024 19:25:14 +0100 Subject: [PATCH 3/9] comments & refactoring --- x/tokenfactory/keeper/bankactions.go | 2 +- x/tokenfactory/keeper/keeper_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 284728258..630b14eca 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -93,7 +93,7 @@ func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool { for _, moduleName := range k.knownModules { account := k.accountKeeper.GetModuleAccount(ctx, moduleName) if account == nil { - return false + continue } if account.GetAddress().Equals(addr) { diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index c6fd3772a..b4864b641 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -126,6 +126,9 @@ func (suite *KeeperTestSuite) TestForceTransferMsg() { _, err = suite.msgServer.ForceTransfer(suite.ChainA.GetContext(), types.NewMsgForceTransfer(suite.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String(), suite.TestAccs[1].String())) suite.Require().ErrorContains(err, "force transfer from module acc not available") + + _, err = suite.msgServer.ForceTransfer(suite.ChainA.GetContext(), types.NewMsgForceTransfer(suite.TestAccs[0].String(), mintAmt, suite.TestAccs[1].String(), govModAcc.GetAddress().String())) + suite.Require().ErrorContains(err, "force transfer to module acc not available") }) } @@ -135,7 +138,7 @@ func (suite *KeeperTestSuite) TestMintToMsg() { // Create a denom suite.CreateDefaultDenom(suite.ChainA.GetContext()) - suite.Run("test force transfer", func() { + suite.Run("test mint to", func() { mintAmt := sdktypes.NewInt64Coin(suite.defaultDenom, 10) govModAcc := suite.GetNeutronZoneApp(suite.ChainA).AccountKeeper.GetModuleAccount(suite.ChainA.GetContext(), authtypes.FeeCollectorName) @@ -151,7 +154,7 @@ func (suite *KeeperTestSuite) TestBurnFromMsg() { // Create a denom suite.CreateDefaultDenom(suite.ChainA.GetContext()) - suite.Run("test force transfer", func() { + suite.Run("test burn from", func() { mintAmt := sdktypes.NewInt64Coin(suite.defaultDenom, 10) _, err := suite.msgServer.Mint(sdktypes.WrapSDKContext(suite.ChainA.GetContext()), types.NewMsgMint(suite.TestAccs[0].String(), mintAmt)) From 6a2c9c14f06bae8937f795cd81ae4529076f1f61 Mon Sep 17 00:00:00 2001 From: Andrei Zavgorodnii Date: Fri, 14 Jun 2024 10:17:35 +0100 Subject: [PATCH 4/9] fixed PerformMint --- wasmbinding/message_plugin.go | 7 +------ x/tokenfactory/keeper/bankactions.go | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index dd3564787..fc27ca932 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -692,7 +692,7 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk } coin := sdk.Coin{Denom: mint.Denom, Amount: mint.Amount} - sdkMsg := tokenfactorytypes.NewMsgMint(contractAddr.String(), coin) + sdkMsg := tokenfactorytypes.NewMsgMintTo(contractAddr.String(), coin, rcpt.String()) // Mint through token factory / message server msgServer := tokenfactorykeeper.NewMsgServerImpl(*f) @@ -701,11 +701,6 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk return errors.Wrap(err, "minting coins from message") } - err = b.SendCoins(ctx, contractAddr, rcpt, sdk.NewCoins(coin)) - if err != nil { - return errors.Wrap(err, "sending newly minted coins from message") - } - return nil } diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 630b14eca..9398f7ed7 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -41,17 +41,17 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } - addr, err := sdk.AccAddressFromBech32(burnFrom) + burnFromAddr, err := sdk.AccAddressFromBech32(burnFrom) if err != nil { return err } - if k.isModuleAccount(ctx, addr) { + if k.isModuleAccount(ctx, burnFromAddr) { return status.Errorf(codes.Internal, "burning from module accounts is forbidden") } err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, - addr, + burnFromAddr, types.ModuleName, sdk.NewCoins(amount)) if err != nil { From b2447ae9471fb5faa9ac9b4eb92e542347f220af Mon Sep 17 00:00:00 2001 From: Andrei Zavgorodnii Date: Fri, 14 Jun 2024 13:09:50 +0100 Subject: [PATCH 5/9] lint --- wasmbinding/message_plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index fc27ca932..a22c5e78d 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -685,7 +685,7 @@ func (m *CustomMessenger) setBeforeSendHook(ctx sdk.Context, contractAddr sdk.Ac } // PerformMint used with mintTokens to validate the mint message and mint through token factory. -func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error { +func PerformMint(f *tokenfactorykeeper.Keeper, _ *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error { rcpt, err := parseAddress(mint.MintToAddress) if err != nil { return err From 7fd552493303904a1d399e89b38bb56df52000a4 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 14 Jun 2024 15:32:54 +0300 Subject: [PATCH 6/9] rm deprecated sdktypes.WrapSDKContext usage --- x/tokenfactory/keeper/keeper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index b4864b641..96fcbebda 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -157,7 +157,7 @@ func (suite *KeeperTestSuite) TestBurnFromMsg() { suite.Run("test burn from", func() { mintAmt := sdktypes.NewInt64Coin(suite.defaultDenom, 10) - _, err := suite.msgServer.Mint(sdktypes.WrapSDKContext(suite.ChainA.GetContext()), types.NewMsgMint(suite.TestAccs[0].String(), mintAmt)) + _, err := suite.msgServer.Mint(suite.ChainA.GetContext(), types.NewMsgMint(suite.TestAccs[0].String(), mintAmt)) suite.Require().NoError(err) govModAcc := suite.GetNeutronZoneApp(suite.ChainA).AccountKeeper.GetModuleAccount(suite.ChainA.GetContext(), authtypes.FeeCollectorName) From db871ba0800eb17176509ab1eacc2bc3a0100814 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 14 Jun 2024 17:09:02 +0300 Subject: [PATCH 7/9] clean up var names in tokenfactory bank actions --- x/tokenfactory/keeper/bankactions.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 9398f7ed7..bb3e21faa 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -15,12 +15,12 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { return err } - addr, err := sdk.AccAddressFromBech32(mintTo) + mintToAcc, err := sdk.AccAddressFromBech32(mintTo) if err != nil { return err } - if k.isModuleAccount(ctx, addr) { + if k.isModuleAccount(ctx, mintToAcc) { return status.Errorf(codes.Internal, "minting to module accounts is forbidden") } @@ -30,7 +30,7 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { } return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, - addr, + mintToAcc, sdk.NewCoins(amount)) } @@ -41,17 +41,17 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } - burnFromAddr, err := sdk.AccAddressFromBech32(burnFrom) + burnFromAcc, err := sdk.AccAddressFromBech32(burnFrom) if err != nil { return err } - if k.isModuleAccount(ctx, burnFromAddr) { + if k.isModuleAccount(ctx, burnFromAcc) { return status.Errorf(codes.Internal, "burning from module accounts is forbidden") } err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, - burnFromAddr, + burnFromAcc, types.ModuleName, sdk.NewCoins(amount)) if err != nil { @@ -68,25 +68,25 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr return err } - fromSdkAddr, err := sdk.AccAddressFromBech32(fromAddr) + transferFromAcc, err := sdk.AccAddressFromBech32(fromAddr) if err != nil { return err } - toSdkAddr, err := sdk.AccAddressFromBech32(toAddr) + transferToAcc, err := sdk.AccAddressFromBech32(toAddr) if err != nil { return err } - if k.isModuleAccount(ctx, fromSdkAddr) { + if k.isModuleAccount(ctx, transferFromAcc) { return status.Errorf(codes.Internal, "force transfer from module acc not available") } - if k.isModuleAccount(ctx, toSdkAddr) { + if k.isModuleAccount(ctx, transferToAcc) { return status.Errorf(codes.Internal, "force transfer to module acc not available") } - return k.bankKeeper.SendCoins(ctx, fromSdkAddr, toSdkAddr, sdk.NewCoins(amount)) + return k.bankKeeper.SendCoins(ctx, transferFromAcc, transferToAcc, sdk.NewCoins(amount)) } func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool { From e32aa4fc03e4aa85f54d096afdeb27929e6bb8d3 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 14 Jun 2024 17:23:12 +0300 Subject: [PATCH 8/9] improve wording in tokenfactory force transfer errors --- x/tokenfactory/keeper/bankactions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index bb3e21faa..5e7b650f9 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -79,11 +79,11 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr, toAddr } if k.isModuleAccount(ctx, transferFromAcc) { - return status.Errorf(codes.Internal, "force transfer from module acc not available") + return status.Errorf(codes.Internal, "force transfer from module accounts is forbidden") } if k.isModuleAccount(ctx, transferToAcc) { - return status.Errorf(codes.Internal, "force transfer to module acc not available") + return status.Errorf(codes.Internal, "force transfer to module accounts is forbidden") } return k.bankKeeper.SendCoins(ctx, transferFromAcc, transferToAcc, sdk.NewCoins(amount)) From 8db652f6dc6fff52560f1d787f448acb3c565005 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 14 Jun 2024 17:32:09 +0300 Subject: [PATCH 9/9] fix force transfer error msgs in tokenfactory tests --- x/tokenfactory/keeper/keeper_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index 96fcbebda..335ff509e 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -125,10 +125,10 @@ func (suite *KeeperTestSuite) TestForceTransferMsg() { suite.Require().NoError(err) _, err = suite.msgServer.ForceTransfer(suite.ChainA.GetContext(), types.NewMsgForceTransfer(suite.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String(), suite.TestAccs[1].String())) - suite.Require().ErrorContains(err, "force transfer from module acc not available") + suite.Require().ErrorContains(err, "force transfer from module accounts is forbidden") _, err = suite.msgServer.ForceTransfer(suite.ChainA.GetContext(), types.NewMsgForceTransfer(suite.TestAccs[0].String(), mintAmt, suite.TestAccs[1].String(), govModAcc.GetAddress().String())) - suite.Require().ErrorContains(err, "force transfer to module acc not available") + suite.Require().ErrorContains(err, "force transfer to module accounts is forbidden") }) }