From 25cf6ad9a050d42a5bdcc28f46e7f8f80279c825 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sun, 21 Aug 2022 21:24:02 -0500 Subject: [PATCH 1/9] tokenfactory mutation test changes --- app/apptesting/test_suite.go | 5 -- x/tokenfactory/keeper/createdenom.go | 12 +++- x/tokenfactory/keeper/createdenom_test.go | 69 ++++++++++++++++++----- x/tokenfactory/keeper/genesis.go | 5 +- x/tokenfactory/keeper/genesis_test.go | 11 ++++ x/tokenfactory/keeper/keeper_test.go | 4 +- x/tokenfactory/types/expected_keepers.go | 2 + 7 files changed, 80 insertions(+), 28 deletions(-) diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index f1a18ce4d1a..943ac9d3129 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -142,11 +142,6 @@ func (s *KeeperTestHelper) SetupValidator(bondStatus stakingtypes.BondStatus) sd return valAddr } -// SetupTokenFactory sets up a token module account for the TokenFactoryKeeper. -func (s *KeeperTestHelper) SetupTokenFactory() { - s.App.TokenFactoryKeeper.CreateModuleAccount(s.Ctx) -} - // BeginNewBlock starts a new block. func (s *KeeperTestHelper) BeginNewBlock(executeNextEpoch bool) { var valAddr []byte diff --git a/x/tokenfactory/keeper/createdenom.go b/x/tokenfactory/keeper/createdenom.go index 5f452a9c197..ecccce48f15 100644 --- a/x/tokenfactory/keeper/createdenom.go +++ b/x/tokenfactory/keeper/createdenom.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" @@ -11,12 +12,12 @@ import ( // ConvertToBaseToken converts a fee amount in a whitelisted fee token to the base fee token amount func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, subdenom string) (newTokenDenom string, err error) { - err = k.chargeForCreateDenom(ctx, creatorAddr, subdenom) + denom, err := k.validateCreateDenom(ctx, creatorAddr, subdenom) if err != nil { return "", err } - denom, err := k.validateCreateDenom(ctx, creatorAddr, subdenom) + err = k.chargeForCreateDenom(ctx, creatorAddr, subdenom) if err != nil { return "", err } @@ -77,7 +78,12 @@ func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string, subden if err != nil { return err } - if len(creationFee) > 0 { + if creationFee != nil { + for _, coin := range creationFee { + if !k.bankKeeper.HasBalance(ctx, accAddr, coin) { + return sdkerrors.ErrInsufficientFunds + } + } if err := k.communityPoolKeeper.FundCommunityPool(ctx, creationFee, accAddr); err != nil { return err } diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index 77963f99d15..0a30c4cf16a 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" ) @@ -57,19 +58,26 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() { } func (suite *KeeperTestSuite) TestCreateDenom() { + defaultDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} + twoDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + nilCreationFee := types.Params{DenomCreationFee: nil} + largeCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(5000000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} for _, tc := range []struct { - desc string - setup func() - subdenom string - valid bool + desc string + denomCreationFee types.Params + setup func() + subdenom string + valid bool }{ { - desc: "subdenom too long", - subdenom: "assadsadsadasdasdsadsadsadsadsadsadsklkadaskkkdasdasedskhanhassyeunganassfnlksdflksafjlkasd", - valid: false, + desc: "subdenom too long", + denomCreationFee: defaultDenomCreationFee, + subdenom: "assadsadsadasdasdsadsadsadsadsadsadsklkadaskkkdasdasedskhanhassyeunganassfnlksdflksafjlkasd", + valid: false, }, { - desc: "subdenom and creator pair already exists", + desc: "subdenom and creator pair already exists", + denomCreationFee: defaultDenomCreationFee, setup: func() { _, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) suite.Require().NoError(err) @@ -78,24 +86,53 @@ func (suite *KeeperTestSuite) TestCreateDenom() { valid: false, }, { - desc: "success case", - subdenom: "evmos", - valid: true, + desc: "success case: defaultDenomCreationFee", + denomCreationFee: defaultDenomCreationFee, + subdenom: "evmos", + valid: true, }, { - desc: "subdenom having invalid characters", - subdenom: "bit/***///&&&/coin", - valid: false, + desc: "success case: twoDenomCreationFee", + denomCreationFee: twoDenomCreationFee, + subdenom: "catcoin", + valid: true, + }, + { + desc: "success case: nilCreationFee", + denomCreationFee: nilCreationFee, + subdenom: "czcoin", + valid: true, + }, + { + desc: "account doesn't have enough to pay for denom creation fee", + denomCreationFee: largeCreationFee, + subdenom: "tooexpensive", + valid: false, + }, + { + desc: "subdenom having invalid characters", + denomCreationFee: defaultDenomCreationFee, + subdenom: "bit/***///&&&/coin", + valid: false, }, } { + suite.SetupTest() suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { if tc.setup != nil { tc.setup() } - // Create a denom + // Set denom creation fee in params + keeper.Keeper.SetParams(*suite.App.TokenFactoryKeeper, suite.Ctx, tc.denomCreationFee) + denomCreationFee := suite.App.TokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee + suite.Require().Equal(tc.denomCreationFee.DenomCreationFee, denomCreationFee) + + // note balance, create a tokenfactory denom, then note balance again + preCreateBalance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) + postCreateBalance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) if tc.valid { suite.Require().NoError(err) + suite.Require().True(preCreateBalance.Sub(postCreateBalance).IsEqual(denomCreationFee)) // Make sure that the admin is set correctly queryRes, err := suite.queryClient.DenomAuthorityMetadata(suite.Ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ @@ -107,6 +144,8 @@ func (suite *KeeperTestSuite) TestCreateDenom() { } else { suite.Require().Error(err) + // Ensure we don't charge if we expect an error + suite.Require().True(preCreateBalance.IsEqual(postCreateBalance)) } }) } diff --git a/x/tokenfactory/keeper/genesis.go b/x/tokenfactory/keeper/genesis.go index 23c2322a94c..f7cbe55e80b 100644 --- a/x/tokenfactory/keeper/genesis.go +++ b/x/tokenfactory/keeper/genesis.go @@ -9,13 +9,14 @@ import ( // InitGenesis initializes the tokenfactory module's state from a provided genesis // state. func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { - k.CreateModuleAccount(ctx) - if genState.Params.DenomCreationFee == nil { genState.Params.DenomCreationFee = sdk.NewCoins() } k.SetParams(ctx, genState.Params) + // The call to GetModuleAccount creates a module account if it does not exist. + k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) + for _, genDenom := range genState.GetFactoryDenoms() { creator, _, err := types.DeconstructDenom(genDenom.GetDenom()) if err != nil { diff --git a/x/tokenfactory/keeper/genesis_test.go b/x/tokenfactory/keeper/genesis_test.go index 549708e2e80..e8f63cc26d3 100644 --- a/x/tokenfactory/keeper/genesis_test.go +++ b/x/tokenfactory/keeper/genesis_test.go @@ -32,6 +32,9 @@ func (suite *KeeperTestSuite) TestGenesis() { }, } app := suite.App + // remove module account to ensure initGenesis initializes it on its own + tokenfactoryModuleAccount := app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + app.AccountKeeper.RemoveAccount(suite.Ctx, tokenfactoryModuleAccount) suite.Ctx = app.BaseApp.NewContext(false, tmproto.Header{}) // Test both with bank denom metadata set, and not set. for i, denom := range genesisState.FactoryDenoms { @@ -40,9 +43,17 @@ func (suite *KeeperTestSuite) TestGenesis() { app.BankKeeper.SetDenomMetaData(suite.Ctx, banktypes.Metadata{Base: denom.GetDenom()}) } } + // check before initGenesis that the module account is nil + tokenfactoryModuleAccount = app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + suite.Require().Nil(tokenfactoryModuleAccount) app.TokenFactoryKeeper.SetParams(suite.Ctx, types.Params{DenomCreationFee: sdk.Coins{sdk.NewInt64Coin("uosmo", 100)}}) app.TokenFactoryKeeper.InitGenesis(suite.Ctx, genesisState) + + // check that the module account is now initialized + tokenfactoryModuleAccount = app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + suite.Require().NotNil(tokenfactoryModuleAccount) + exportedGenesis := app.TokenFactoryKeeper.ExportGenesis(suite.Ctx) suite.Require().NotNil(exportedGenesis) suite.Require().Equal(genesisState, *exportedGenesis) diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index ffd7a2885e2..943f4d29f97 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -28,13 +28,11 @@ func (suite *KeeperTestSuite) SetupTest() { suite.Setup() // Fund every TestAcc with 100 denom creation fees. - fundAccsAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100))) + fundAccsAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100)), sdk.NewCoin("uion", sdk.NewInt(100000000))) for _, acc := range suite.TestAccs { suite.FundAcc(acc, fundAccsAmount) } - suite.SetupTokenFactory() - suite.queryClient = types.NewQueryClient(suite.QueryHelper) suite.msgServer = keeper.NewMsgServerImpl(*suite.App.TokenFactoryKeeper) } diff --git a/x/tokenfactory/types/expected_keepers.go b/x/tokenfactory/types/expected_keepers.go index e1f8561b98e..66102218483 100644 --- a/x/tokenfactory/types/expected_keepers.go +++ b/x/tokenfactory/types/expected_keepers.go @@ -19,10 +19,12 @@ type BankKeeper interface { BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool } type AccountKeeper interface { SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI) + GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI } // CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions. From 6fdc6ed6b2c86aac28b4b7fd9cf2c15f087f01ce Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 22 Aug 2022 09:30:33 -0500 Subject: [PATCH 2/9] rev tests should now pass --- x/twap/store_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/twap/store_test.go b/x/twap/store_test.go index cdae2ebc2d7..597a8b911eb 100644 --- a/x/twap/store_test.go +++ b/x/twap/store_test.go @@ -143,7 +143,7 @@ func (s *TestSuite) TestGetRecordAtOrBeforeTime() { }{ "no entries": {[]types.TwapRecord{}, defaultInputAt(baseTime), baseRecord, true}, "get at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultInputAt(baseTime), baseRecord, false}, - "rev at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultRevInputAt(baseTime), baseRecord, true}, + "rev at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultRevInputAt(baseTime), baseRecord, false}, "get latest (exact) w/ past entries": { []types.TwapRecord{tMin1Record, baseRecord}, defaultInputAt(baseTime), baseRecord, false}, @@ -152,7 +152,7 @@ func (s *TestSuite) TestGetRecordAtOrBeforeTime() { "get sandwitched entry (exact)": { []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultInputAt(baseTime), baseRecord, false}, "rev sandwitched entry (exact)": { - []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultRevInputAt(baseTime), baseRecord, true}, + []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultRevInputAt(baseTime), baseRecord, false}, "get future": {[]types.TwapRecord{baseRecord}, defaultInputAt(tPlus1), baseRecord, false}, "get future w/ past entries": {[]types.TwapRecord{tMin1Record, baseRecord}, defaultInputAt(tPlus1), baseRecord, false}, From 79178af4a539c9b9a71f81ba1d1b0993b8333900 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 22 Aug 2022 09:32:36 -0500 Subject: [PATCH 3/9] revert (wrong branch) --- x/twap/store_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/twap/store_test.go b/x/twap/store_test.go index 597a8b911eb..cdae2ebc2d7 100644 --- a/x/twap/store_test.go +++ b/x/twap/store_test.go @@ -143,7 +143,7 @@ func (s *TestSuite) TestGetRecordAtOrBeforeTime() { }{ "no entries": {[]types.TwapRecord{}, defaultInputAt(baseTime), baseRecord, true}, "get at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultInputAt(baseTime), baseRecord, false}, - "rev at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultRevInputAt(baseTime), baseRecord, false}, + "rev at latest (exact)": {[]types.TwapRecord{baseRecord}, defaultRevInputAt(baseTime), baseRecord, true}, "get latest (exact) w/ past entries": { []types.TwapRecord{tMin1Record, baseRecord}, defaultInputAt(baseTime), baseRecord, false}, @@ -152,7 +152,7 @@ func (s *TestSuite) TestGetRecordAtOrBeforeTime() { "get sandwitched entry (exact)": { []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultInputAt(baseTime), baseRecord, false}, "rev sandwitched entry (exact)": { - []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultRevInputAt(baseTime), baseRecord, false}, + []types.TwapRecord{tMin1Record, baseRecord, tPlus1Record}, defaultRevInputAt(baseTime), baseRecord, true}, "get future": {[]types.TwapRecord{baseRecord}, defaultInputAt(tPlus1), baseRecord, false}, "get future w/ past entries": {[]types.TwapRecord{tMin1Record, baseRecord}, defaultInputAt(tPlus1), baseRecord, false}, From fd7d74ce9045aa638c134ba102d05e9527d5e363 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 22 Aug 2022 19:04:29 -0500 Subject: [PATCH 4/9] more test improvements --- x/tokenfactory/keeper/genesis.go | 5 +- x/tokenfactory/keeper/keeper_test.go | 21 ++ x/tokenfactory/keeper/msg_server_test.go | 430 +++++++++++++++++++++++ 3 files changed, 453 insertions(+), 3 deletions(-) create mode 100644 x/tokenfactory/keeper/msg_server_test.go diff --git a/x/tokenfactory/keeper/genesis.go b/x/tokenfactory/keeper/genesis.go index f7cbe55e80b..23c2322a94c 100644 --- a/x/tokenfactory/keeper/genesis.go +++ b/x/tokenfactory/keeper/genesis.go @@ -9,14 +9,13 @@ import ( // InitGenesis initializes the tokenfactory module's state from a provided genesis // state. func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + k.CreateModuleAccount(ctx) + if genState.Params.DenomCreationFee == nil { genState.Params.DenomCreationFee = sdk.NewCoins() } k.SetParams(ctx, genState.Params) - // The call to GetModuleAccount creates a module account if it does not exist. - k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) - for _, genDenom := range genState.GetFactoryDenoms() { creator, _, err := types.DeconstructDenom(genDenom.GetDenom()) if err != nil { diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index 943f4d29f97..e16ee0b192b 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/osmosis-labs/osmosis/v11/app/apptesting" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" @@ -41,3 +42,23 @@ func (suite *KeeperTestSuite) CreateDefaultDenom() { res, _ := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) suite.defaultDenom = res.GetNewTokenDenom() } + +func (suite *KeeperTestSuite) TestCreateModuleAccount() { + app := suite.App + + // remove module account + tokenfactoryModuleAccount := app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + app.AccountKeeper.RemoveAccount(suite.Ctx, tokenfactoryModuleAccount) + + // ensure module account was removed + suite.Ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + tokenfactoryModuleAccount = app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + suite.Require().Nil(tokenfactoryModuleAccount) + + // create module account + app.TokenFactoryKeeper.CreateModuleAccount(suite.Ctx) + + // check that the module account is now initialized + tokenfactoryModuleAccount = app.AccountKeeper.GetAccount(suite.Ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)) + suite.Require().NotNil(tokenfactoryModuleAccount) +} diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go new file mode 100644 index 00000000000..a9b57ad25bc --- /dev/null +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -0,0 +1,430 @@ +package keeper_test + +import ( + "fmt" + + "github.com/stretchr/testify/suite" + + "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" + "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +var _ = suite.TestingSuite(nil) + +// TestMintDenom ensures the following properties of the MintMessage: +// * Noone can mint tokens for a denom that doesn't exist +// * Only the admin of a denom can mint tokens for it +// * The admin of a denom can mint tokens for it +func (suite *KeeperTestSuite) TestMintDenomMsg() { + var addr0bal int64 + + // Create a denom + suite.CreateDefaultDenom() + + for _, tc := range []struct { + desc string + amount int64 + mintDenom string + admin string + valid bool + expectedMessageEvents int + }{ + { + desc: "denom does not exist", + amount: 10, + mintDenom: "factory/osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44/evmos", + admin: suite.TestAccs[0].String(), + valid: false, + }, + { + desc: "mint is not by the admin", + amount: 10, + mintDenom: suite.defaultDenom, + admin: suite.TestAccs[1].String(), + valid: false, + }, + { + desc: "success case", + amount: 10, + mintDenom: suite.defaultDenom, + admin: suite.TestAccs[0].String(), + valid: true, + expectedMessageEvents: 1, + }, + } { + suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) + suite.Require().Equal(0, len(ctx.EventManager().Events())) + // Test minting to admins own account + response, err := suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))) + if tc.valid { + addr0bal += 10 + suite.Require().NoError(err) + suite.Require().NotNil(response) + suite.Require().Equal(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64(), addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) + } else { + suite.Require().Error(err) + + } + suite.AssertEventEmitted(ctx, types.TypeMsgMint, tc.expectedMessageEvents) + }) + } +} + +func (suite *KeeperTestSuite) TestBurnDenomMsg() { + var addr0bal int64 + + // Create a denom. + suite.CreateDefaultDenom() + + // mint 10 default token for testAcc[0] + suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) + addr0bal += 10 + + for _, tc := range []struct { + desc string + amount int64 + burnDenom string + admin string + valid bool + expectedMessageEvents int + }{ + { + desc: "denom does not exist", + amount: 10, + burnDenom: "factory/osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44/evmos", + admin: suite.TestAccs[0].String(), + valid: false, + }, + { + desc: "burn is not by the admin", + amount: 10, + burnDenom: suite.defaultDenom, + admin: suite.TestAccs[1].String(), + valid: false, + }, + { + desc: "burn amount is bigger than minted amount", + amount: 1000, + burnDenom: suite.defaultDenom, + admin: suite.TestAccs[1].String(), + valid: false, + }, + { + desc: "success case", + amount: 10, + burnDenom: suite.defaultDenom, + admin: suite.TestAccs[0].String(), + valid: true, + expectedMessageEvents: 2, // TODO: why is this two + }, + } { + suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) + suite.Require().Equal(0, len(ctx.EventManager().Events())) + // Test minting to admins own account + response, err := suite.msgServer.Burn(sdk.WrapSDKContext(ctx), types.NewMsgBurn(tc.admin, sdk.NewInt64Coin(tc.burnDenom, 10))) + if tc.valid { + addr0bal -= 10 + suite.Require().NoError(err) + suite.Require().NotNil(response) + suite.Require().True(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) + } else { + suite.Require().Error(err) + suite.Require().True(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) + } + suite.AssertEventEmitted(ctx, types.TypeMsgBurn, tc.expectedMessageEvents) + }) + } +} + +func (suite *KeeperTestSuite) TestCreateDenomMsg() { + defaultDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} + for _, tc := range []struct { + desc string + denomCreationFee types.Params + subdenom string + valid bool + expectedMessageEvents int + }{ + { + desc: "subdenom too long", + denomCreationFee: defaultDenomCreationFee, + subdenom: "assadsadsadasdasdsadsadsadsadsadsadsklkadaskkkdasdasedskhanhassyeunganassfnlksdflksafjlkasd", + valid: false, + }, + { + desc: "success case: defaultDenomCreationFee", + denomCreationFee: defaultDenomCreationFee, + subdenom: "evmos", + valid: true, + expectedMessageEvents: 1, + }, + } { + suite.SetupTest() + suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) + suite.Require().Equal(0, len(ctx.EventManager().Events())) + // Set denom creation fee in params + keeper.Keeper.SetParams(*suite.App.TokenFactoryKeeper, ctx, tc.denomCreationFee) + denomCreationFee := suite.App.TokenFactoryKeeper.GetParams(ctx).DenomCreationFee + suite.Require().Equal(tc.denomCreationFee.DenomCreationFee, denomCreationFee) + + // note balance, create a tokenfactory denom, then note balance again + preCreateBalance := suite.App.BankKeeper.GetAllBalances(ctx, suite.TestAccs[0]) + res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) + postCreateBalance := suite.App.BankKeeper.GetAllBalances(ctx, suite.TestAccs[0]) + if tc.valid { + suite.Require().NoError(err) + suite.Require().True(preCreateBalance.Sub(postCreateBalance).IsEqual(denomCreationFee)) + + // Make sure that the admin is set correctly + queryRes, err := suite.queryClient.DenomAuthorityMetadata(ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ + Denom: res.GetNewTokenDenom(), + }) + + suite.Require().NoError(err) + suite.Require().Equal(suite.TestAccs[0].String(), queryRes.AuthorityMetadata.Admin) + + } else { + suite.Require().Error(err) + // Ensure we don't charge if we expect an error + suite.Require().True(preCreateBalance.IsEqual(postCreateBalance)) + } + suite.AssertEventEmitted(ctx, types.TypeMsgCreateDenom, tc.expectedMessageEvents) + }) + } +} + +func (suite *KeeperTestSuite) TestChangeAdminDenomMsg() { + for _, tc := range []struct { + desc string + msgChangeAdmin func(denom string) *types.MsgChangeAdmin + expectedChangeAdminPass bool + expectedAdminIndex int + msgMint func(denom string) *types.MsgMint + expectedMintPass bool + expectedMessageEvents int + }{ + { + desc: "creator admin can't mint after setting to '' ", + msgChangeAdmin: func(denom string) *types.MsgChangeAdmin { + return types.NewMsgChangeAdmin(suite.TestAccs[0].String(), denom, "") + }, + expectedChangeAdminPass: true, + expectedMessageEvents: 1, + expectedAdminIndex: -1, + msgMint: func(denom string) *types.MsgMint { + return types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(denom, 5)) + }, + expectedMintPass: false, + }, + { + desc: "non-admins can't change the existing admin", + msgChangeAdmin: func(denom string) *types.MsgChangeAdmin { + return types.NewMsgChangeAdmin(suite.TestAccs[1].String(), denom, suite.TestAccs[2].String()) + }, + expectedChangeAdminPass: false, + expectedAdminIndex: 0, + }, + { + desc: "success change admin", + msgChangeAdmin: func(denom string) *types.MsgChangeAdmin { + return types.NewMsgChangeAdmin(suite.TestAccs[0].String(), denom, suite.TestAccs[1].String()) + }, + expectedAdminIndex: 1, + expectedChangeAdminPass: true, + expectedMessageEvents: 1, + msgMint: func(denom string) *types.MsgMint { + return types.NewMsgMint(suite.TestAccs[1].String(), sdk.NewInt64Coin(denom, 5)) + }, + expectedMintPass: true, + }, + } { + suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + // setup test + suite.SetupTest() + ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) + suite.Require().Equal(0, len(ctx.EventManager().Events())) + + // Create a denom and mint + res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) + suite.Require().NoError(err) + + testDenom := res.GetNewTokenDenom() + + _, err = suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(testDenom, 10))) + suite.Require().NoError(err) + + response, err := suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(ctx), tc.msgChangeAdmin(testDenom)) + if tc.expectedChangeAdminPass { + suite.Require().NoError(err) + suite.Require().NotNil(response) + } else { + suite.Require().Error(err) + } + + suite.AssertEventEmitted(ctx, types.TypeMsgChangeAdmin, tc.expectedMessageEvents) + + queryRes, err := suite.queryClient.DenomAuthorityMetadata(ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ + Denom: testDenom, + }) + suite.Require().NoError(err) + + // expectedAdminIndex with negative value is assumed as admin with value of "" + const emptyStringAdminIndexFlag = -1 + if tc.expectedAdminIndex == emptyStringAdminIndexFlag { + suite.Require().Equal("", queryRes.AuthorityMetadata.Admin) + } else { + suite.Require().Equal(suite.TestAccs[tc.expectedAdminIndex].String(), queryRes.AuthorityMetadata.Admin) + } + + // we test mint to test if admin authority is performed properly after admin change. + if tc.msgMint != nil { + _, err := suite.msgServer.Mint(sdk.WrapSDKContext(ctx), tc.msgMint(testDenom)) + if tc.expectedMintPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + } + }) + } +} + +func (suite *KeeperTestSuite) TestSetDenomMetaDataMsg() { + + // setup test + suite.SetupTest() + suite.CreateDefaultDenom() + + for _, tc := range []struct { + desc string + msgSetDenomMetadata types.MsgSetDenomMetadata + expectedPass bool + expectedMessageEvents int + }{ + { + desc: "successful set denom metadata", + msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ + Description: "yeehaw", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: suite.defaultDenom, + Exponent: 0, + }, + { + Denom: "uosmo", + Exponent: 6, + }, + }, + Base: suite.defaultDenom, + Display: "uosmo", + Name: "OSMO", + Symbol: "OSMO", + }), + expectedPass: true, + expectedMessageEvents: 1, + }, + { + desc: "non existent factory denom name", + msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ + Description: "yeehaw", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: fmt.Sprintf("factory/%s/litecoin", suite.TestAccs[0].String()), + Exponent: 0, + }, + { + Denom: "uosmo", + Exponent: 6, + }, + }, + Base: fmt.Sprintf("factory/%s/litecoin", suite.TestAccs[0].String()), + Display: "uosmo", + Name: "OSMO", + Symbol: "OSMO", + }), + expectedPass: false, + }, + { + desc: "non-factory denom", + msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ + Description: "yeehaw", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "uosmo", + Exponent: 0, + }, + { + Denom: "uosmoo", + Exponent: 6, + }, + }, + Base: "uosmo", + Display: "uosmoo", + Name: "OSMO", + Symbol: "OSMO", + }), + expectedPass: false, + }, + { + desc: "wrong admin", + msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[1].String(), banktypes.Metadata{ + Description: "yeehaw", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: suite.defaultDenom, + Exponent: 0, + }, + { + Denom: "uosmo", + Exponent: 6, + }, + }, + Base: suite.defaultDenom, + Display: "uosmo", + Name: "OSMO", + Symbol: "OSMO", + }), + expectedPass: false, + }, + { + desc: "invalid metadata (missing display denom unit)", + msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ + Description: "yeehaw", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: suite.defaultDenom, + Exponent: 0, + }, + }, + Base: suite.defaultDenom, + Display: "uosmo", + Name: "OSMO", + Symbol: "OSMO", + }), + expectedPass: false, + }, + } { + suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) + suite.Require().Equal(0, len(ctx.EventManager().Events())) + response, err := suite.msgServer.SetDenomMetadata(sdk.WrapSDKContext(ctx), &tc.msgSetDenomMetadata) + if tc.expectedPass { + suite.Require().NoError(err) + suite.Require().NotNil(response) + + md, found := suite.App.BankKeeper.GetDenomMetaData(ctx, suite.defaultDenom) + suite.Require().True(found) + suite.Require().Equal(tc.msgSetDenomMetadata.Metadata.Name, md.Name) + } else { + suite.Require().Error(err) + } + suite.AssertEventEmitted(ctx, types.TypeMsgSetDenomMetadata, tc.expectedMessageEvents) + }) + } +} From 118875d12d05314987bc3251bb8236fcc1bf93a5 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 22 Aug 2022 19:15:52 -0500 Subject: [PATCH 5/9] only test message emission --- x/tokenfactory/keeper/msg_server_test.go | 223 +++-------------------- 1 file changed, 21 insertions(+), 202 deletions(-) diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index a9b57ad25bc..98e2961f8a9 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -3,8 +3,6 @@ package keeper_test import ( "fmt" - "github.com/stretchr/testify/suite" - "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" @@ -12,15 +10,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) -var _ = suite.TestingSuite(nil) - -// TestMintDenom ensures the following properties of the MintMessage: -// * Noone can mint tokens for a denom that doesn't exist -// * Only the admin of a denom can mint tokens for it -// * The admin of a denom can mint tokens for it +// TestMintDenomMsg tests TypeMsgMint message is emitted on a successful mint func (suite *KeeperTestSuite) TestMintDenomMsg() { - var addr0bal int64 - // Create a denom suite.CreateDefaultDenom() @@ -39,13 +30,6 @@ func (suite *KeeperTestSuite) TestMintDenomMsg() { admin: suite.TestAccs[0].String(), valid: false, }, - { - desc: "mint is not by the admin", - amount: 10, - mintDenom: suite.defaultDenom, - admin: suite.TestAccs[1].String(), - valid: false, - }, { desc: "success case", amount: 10, @@ -58,28 +42,19 @@ func (suite *KeeperTestSuite) TestMintDenomMsg() { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) - // Test minting to admins own account - response, err := suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))) - if tc.valid { - addr0bal += 10 - suite.Require().NoError(err) - suite.Require().NotNil(response) - suite.Require().Equal(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64(), addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) - } else { - suite.Require().Error(err) - - } + // Test mint message + suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))) + // Ensure current number and type of event is emitted suite.AssertEventEmitted(ctx, types.TypeMsgMint, tc.expectedMessageEvents) }) } } +// TestBurnDenomMsg tests TypeMsgBurn message is emitted on a successful burn func (suite *KeeperTestSuite) TestBurnDenomMsg() { var addr0bal int64 - // Create a denom. suite.CreateDefaultDenom() - // mint 10 default token for testAcc[0] suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) addr0bal += 10 @@ -94,28 +69,12 @@ func (suite *KeeperTestSuite) TestBurnDenomMsg() { }{ { desc: "denom does not exist", - amount: 10, burnDenom: "factory/osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44/evmos", admin: suite.TestAccs[0].String(), valid: false, }, - { - desc: "burn is not by the admin", - amount: 10, - burnDenom: suite.defaultDenom, - admin: suite.TestAccs[1].String(), - valid: false, - }, - { - desc: "burn amount is bigger than minted amount", - amount: 1000, - burnDenom: suite.defaultDenom, - admin: suite.TestAccs[1].String(), - valid: false, - }, { desc: "success case", - amount: 10, burnDenom: suite.defaultDenom, admin: suite.TestAccs[0].String(), valid: true, @@ -125,22 +84,15 @@ func (suite *KeeperTestSuite) TestBurnDenomMsg() { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) - // Test minting to admins own account - response, err := suite.msgServer.Burn(sdk.WrapSDKContext(ctx), types.NewMsgBurn(tc.admin, sdk.NewInt64Coin(tc.burnDenom, 10))) - if tc.valid { - addr0bal -= 10 - suite.Require().NoError(err) - suite.Require().NotNil(response) - suite.Require().True(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) - } else { - suite.Require().Error(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(ctx, suite.TestAccs[0], suite.defaultDenom)) - } + // Test burn message + suite.msgServer.Burn(sdk.WrapSDKContext(ctx), types.NewMsgBurn(tc.admin, sdk.NewInt64Coin(tc.burnDenom, 10))) + // Ensure current number and type of event is emitted suite.AssertEventEmitted(ctx, types.TypeMsgBurn, tc.expectedMessageEvents) }) } } +// TestCreateDenomMsg tests TypeMsgCreateDenom message is emitted on a successful denom creation func (suite *KeeperTestSuite) TestCreateDenomMsg() { defaultDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} for _, tc := range []struct { @@ -170,35 +122,15 @@ func (suite *KeeperTestSuite) TestCreateDenomMsg() { suite.Require().Equal(0, len(ctx.EventManager().Events())) // Set denom creation fee in params keeper.Keeper.SetParams(*suite.App.TokenFactoryKeeper, ctx, tc.denomCreationFee) - denomCreationFee := suite.App.TokenFactoryKeeper.GetParams(ctx).DenomCreationFee - suite.Require().Equal(tc.denomCreationFee.DenomCreationFee, denomCreationFee) - - // note balance, create a tokenfactory denom, then note balance again - preCreateBalance := suite.App.BankKeeper.GetAllBalances(ctx, suite.TestAccs[0]) - res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) - postCreateBalance := suite.App.BankKeeper.GetAllBalances(ctx, suite.TestAccs[0]) - if tc.valid { - suite.Require().NoError(err) - suite.Require().True(preCreateBalance.Sub(postCreateBalance).IsEqual(denomCreationFee)) - - // Make sure that the admin is set correctly - queryRes, err := suite.queryClient.DenomAuthorityMetadata(ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ - Denom: res.GetNewTokenDenom(), - }) - - suite.Require().NoError(err) - suite.Require().Equal(suite.TestAccs[0].String(), queryRes.AuthorityMetadata.Admin) - - } else { - suite.Require().Error(err) - // Ensure we don't charge if we expect an error - suite.Require().True(preCreateBalance.IsEqual(postCreateBalance)) - } + // Test create denom message + suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) + // Ensure current number and type of event is emitted suite.AssertEventEmitted(ctx, types.TypeMsgCreateDenom, tc.expectedMessageEvents) }) } } +// TestChangeAdminDenomMsg tests TypeMsgChangeAdmin message is emitted on a successful admin change func (suite *KeeperTestSuite) TestChangeAdminDenomMsg() { for _, tc := range []struct { desc string @@ -209,19 +141,6 @@ func (suite *KeeperTestSuite) TestChangeAdminDenomMsg() { expectedMintPass bool expectedMessageEvents int }{ - { - desc: "creator admin can't mint after setting to '' ", - msgChangeAdmin: func(denom string) *types.MsgChangeAdmin { - return types.NewMsgChangeAdmin(suite.TestAccs[0].String(), denom, "") - }, - expectedChangeAdminPass: true, - expectedMessageEvents: 1, - expectedAdminIndex: -1, - msgMint: func(denom string) *types.MsgMint { - return types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(denom, 5)) - }, - expectedMintPass: false, - }, { desc: "non-admins can't change the existing admin", msgChangeAdmin: func(denom string) *types.MsgChangeAdmin { @@ -249,54 +168,21 @@ func (suite *KeeperTestSuite) TestChangeAdminDenomMsg() { suite.SetupTest() ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) - // Create a denom and mint res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) suite.Require().NoError(err) - testDenom := res.GetNewTokenDenom() - - _, err = suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(testDenom, 10))) - suite.Require().NoError(err) - - response, err := suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(ctx), tc.msgChangeAdmin(testDenom)) - if tc.expectedChangeAdminPass { - suite.Require().NoError(err) - suite.Require().NotNil(response) - } else { - suite.Require().Error(err) - } - + suite.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(testDenom, 10))) + // Test change admin message + suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(ctx), tc.msgChangeAdmin(testDenom)) + // Ensure current number and type of event is emitted suite.AssertEventEmitted(ctx, types.TypeMsgChangeAdmin, tc.expectedMessageEvents) - - queryRes, err := suite.queryClient.DenomAuthorityMetadata(ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ - Denom: testDenom, - }) - suite.Require().NoError(err) - - // expectedAdminIndex with negative value is assumed as admin with value of "" - const emptyStringAdminIndexFlag = -1 - if tc.expectedAdminIndex == emptyStringAdminIndexFlag { - suite.Require().Equal("", queryRes.AuthorityMetadata.Admin) - } else { - suite.Require().Equal(suite.TestAccs[tc.expectedAdminIndex].String(), queryRes.AuthorityMetadata.Admin) - } - - // we test mint to test if admin authority is performed properly after admin change. - if tc.msgMint != nil { - _, err := suite.msgServer.Mint(sdk.WrapSDKContext(ctx), tc.msgMint(testDenom)) - if tc.expectedMintPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - } }) } } +// TestSetDenomMetaDataMsg tests TypeMsgSetDenomMetadata message is emitted on a successful denom metadata change func (suite *KeeperTestSuite) TestSetDenomMetaDataMsg() { - // setup test suite.SetupTest() suite.CreateDefaultDenom() @@ -350,80 +236,13 @@ func (suite *KeeperTestSuite) TestSetDenomMetaDataMsg() { }), expectedPass: false, }, - { - desc: "non-factory denom", - msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ - Description: "yeehaw", - DenomUnits: []*banktypes.DenomUnit{ - { - Denom: "uosmo", - Exponent: 0, - }, - { - Denom: "uosmoo", - Exponent: 6, - }, - }, - Base: "uosmo", - Display: "uosmoo", - Name: "OSMO", - Symbol: "OSMO", - }), - expectedPass: false, - }, - { - desc: "wrong admin", - msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[1].String(), banktypes.Metadata{ - Description: "yeehaw", - DenomUnits: []*banktypes.DenomUnit{ - { - Denom: suite.defaultDenom, - Exponent: 0, - }, - { - Denom: "uosmo", - Exponent: 6, - }, - }, - Base: suite.defaultDenom, - Display: "uosmo", - Name: "OSMO", - Symbol: "OSMO", - }), - expectedPass: false, - }, - { - desc: "invalid metadata (missing display denom unit)", - msgSetDenomMetadata: *types.NewMsgSetDenomMetadata(suite.TestAccs[0].String(), banktypes.Metadata{ - Description: "yeehaw", - DenomUnits: []*banktypes.DenomUnit{ - { - Denom: suite.defaultDenom, - Exponent: 0, - }, - }, - Base: suite.defaultDenom, - Display: "uosmo", - Name: "OSMO", - Symbol: "OSMO", - }), - expectedPass: false, - }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) - response, err := suite.msgServer.SetDenomMetadata(sdk.WrapSDKContext(ctx), &tc.msgSetDenomMetadata) - if tc.expectedPass { - suite.Require().NoError(err) - suite.Require().NotNil(response) - - md, found := suite.App.BankKeeper.GetDenomMetaData(ctx, suite.defaultDenom) - suite.Require().True(found) - suite.Require().Equal(tc.msgSetDenomMetadata.Metadata.Name, md.Name) - } else { - suite.Require().Error(err) - } + // Test set denom metadata message + suite.msgServer.SetDenomMetadata(sdk.WrapSDKContext(ctx), &tc.msgSetDenomMetadata) + // Ensure current number and type of event is emitted suite.AssertEventEmitted(ctx, types.TypeMsgSetDenomMetadata, tc.expectedMessageEvents) }) } From 6252df7f2608841c759aa62f8663c9a00c57c821 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 23 Aug 2022 15:00:33 -0500 Subject: [PATCH 6/9] address Roman's comments --- app/apptesting/test_suite.go | 5 ++++ x/tokenfactory/keeper/admins_test.go | 23 +++++++++------- x/tokenfactory/keeper/createdenom_test.go | 32 ++++++++++++++--------- x/tokenfactory/keeper/keeper_test.go | 5 ++-- x/tokenfactory/keeper/msg_server_test.go | 4 +-- x/tokenfactory/types/expected_keepers.go | 1 - 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index 943ac9d3129..eb2dc3c8164 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -46,6 +46,11 @@ type KeeperTestHelper struct { TestAccs []sdk.AccAddress } +var ( + SecondaryDenom = "uion" + SecondaryAmount = sdk.NewInt(100000000) +) + // Setup sets up basic environment for suite (App, Ctx, and test accounts) func (s *KeeperTestHelper) Setup() { s.App = app.Setup(false) diff --git a/x/tokenfactory/keeper/admins_test.go b/x/tokenfactory/keeper/admins_test.go index 6c324c374f6..c725cf4ca68 100644 --- a/x/tokenfactory/keeper/admins_test.go +++ b/x/tokenfactory/keeper/admins_test.go @@ -13,6 +13,8 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { addr0bal := int64(0) addr1bal := int64(0) + bankKeeper := suite.App.BankKeeper + suite.CreateDefaultDenom() // Make sure that the admin is set correctly queryRes, err := suite.queryClient.DenomAuthorityMetadata(suite.Ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ @@ -25,19 +27,19 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { _, err = suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) addr0bal += 10 suite.Require().NoError(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) + suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) // // Test force transferring // _, err = suite.msgServer.ForceTransfer(sdk.WrapSDKContext(suite.Ctx), types.NewMsgForceTransfer(suite.TestAccs[0].String(), sdk.NewInt64Coin(denom, 5), suite.TestAccs[1].String(), suite.TestAccs[0].String())) // suite.Require().NoError(err) - // suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], denom).IsEqual(sdk.NewInt64Coin(denom, 15))) - // suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], denom).IsEqual(sdk.NewInt64Coin(denom, 5))) + // suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], denom).IsEqual(sdk.NewInt64Coin(denom, 15))) + // suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], denom).IsEqual(sdk.NewInt64Coin(denom, 5))) // Test burning from own account _, err = suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), types.NewMsgBurn(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 5))) addr0bal -= 5 suite.Require().NoError(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) + suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) // Test Change Admin _, err = suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(suite.Ctx), types.NewMsgChangeAdmin(suite.TestAccs[0].String(), suite.defaultDenom, suite.TestAccs[1].String())) @@ -55,7 +57,7 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { _, err = suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[1].String(), sdk.NewInt64Coin(suite.defaultDenom, 5))) addr1bal += 5 suite.Require().NoError(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) + suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) // Try setting admin to empty _, err = suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(suite.Ctx), types.NewMsgChangeAdmin(suite.TestAccs[1].String(), suite.defaultDenom, "")) @@ -108,11 +110,12 @@ func (suite *KeeperTestSuite) TestMintDenom() { } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { // Test minting to admins own account + bankKeeper := suite.App.BankKeeper _, err := suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))) if tc.valid { addr0bal += 10 suite.Require().NoError(err) - suite.Require().Equal(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64(), addr0bal, suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) + suite.Require().Equal(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64(), addr0bal, bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) } else { suite.Require().Error(err) } @@ -168,14 +171,15 @@ func (suite *KeeperTestSuite) TestBurnDenom() { } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { // Test minting to admins own account + bankKeeper := suite.App.BankKeeper _, err := suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), types.NewMsgBurn(tc.admin, sdk.NewInt64Coin(tc.burnDenom, 10))) if tc.valid { addr0bal -= 10 suite.Require().NoError(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) + suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) } else { suite.Require().Error(err) - suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) + suite.Require().True(bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) } }) } @@ -383,12 +387,13 @@ func (suite *KeeperTestSuite) TestSetDenomMetaData() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + bankKeeper := suite.App.BankKeeper res, err := suite.msgServer.SetDenomMetadata(sdk.WrapSDKContext(suite.Ctx), &tc.msgSetDenomMetadata) if tc.expectedPass { suite.Require().NoError(err) suite.Require().NotNil(res) - md, found := suite.App.BankKeeper.GetDenomMetaData(suite.Ctx, suite.defaultDenom) + md, found := bankKeeper.GetDenomMetaData(suite.Ctx, suite.defaultDenom) suite.Require().True(found) suite.Require().Equal(tc.msgSetDenomMetadata.Metadata.Name, md.Name) } else { diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index 0a30c4cf16a..b9aca4510ae 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -5,15 +5,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" ) func (suite *KeeperTestSuite) TestMsgCreateDenom() { - denomCreationFee := suite.App.TokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee + var ( + tokenFactoryKeeper = suite.App.TokenFactoryKeeper + bankKeeper = suite.App.BankKeeper + denomCreationFee = tokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee + ) // Get balance of acc 0 before creating a denom - preCreateBalance := suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], denomCreationFee[0].Denom) + preCreateBalance := bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], denomCreationFee[0].Denom) // Creating a denom should work res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) @@ -28,7 +31,7 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() { suite.Require().Equal(suite.TestAccs[0].String(), queryRes.AuthorityMetadata.Admin) // Make sure that creation fee was deducted - postCreateBalance := suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.App.TokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee[0].Denom) + postCreateBalance := bankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], tokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee[0].Denom) suite.Require().True(preCreateBalance.Sub(postCreateBalance).IsEqual(denomCreationFee[0])) // Make sure that a second version of the same denom can't be recreated @@ -58,10 +61,13 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() { } func (suite *KeeperTestSuite) TestCreateDenom() { - defaultDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} - twoDenomCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} - nilCreationFee := types.Params{DenomCreationFee: nil} - largeCreationFee := types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(5000000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + var ( + defaultDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} + twoDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + nilCreationFee = types.Params{DenomCreationFee: nil} + largeCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(5000000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + ) + for _, tc := range []struct { desc string denomCreationFee types.Params @@ -121,15 +127,17 @@ func (suite *KeeperTestSuite) TestCreateDenom() { if tc.setup != nil { tc.setup() } + tokenFactoryKeeper := suite.App.TokenFactoryKeeper + bankKeeper := suite.App.BankKeeper // Set denom creation fee in params - keeper.Keeper.SetParams(*suite.App.TokenFactoryKeeper, suite.Ctx, tc.denomCreationFee) - denomCreationFee := suite.App.TokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee + tokenFactoryKeeper.SetParams(suite.Ctx, tc.denomCreationFee) + denomCreationFee := tokenFactoryKeeper.GetParams(suite.Ctx).DenomCreationFee suite.Require().Equal(tc.denomCreationFee.DenomCreationFee, denomCreationFee) // note balance, create a tokenfactory denom, then note balance again - preCreateBalance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) + preCreateBalance := bankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) - postCreateBalance := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) + postCreateBalance := bankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[0]) if tc.valid { suite.Require().NoError(err) suite.Require().True(preCreateBalance.Sub(postCreateBalance).IsEqual(denomCreationFee)) diff --git a/x/tokenfactory/keeper/keeper_test.go b/x/tokenfactory/keeper/keeper_test.go index e16ee0b192b..ef31545b0d2 100644 --- a/x/tokenfactory/keeper/keeper_test.go +++ b/x/tokenfactory/keeper/keeper_test.go @@ -27,9 +27,8 @@ func TestKeeperTestSuite(t *testing.T) { func (suite *KeeperTestSuite) SetupTest() { suite.Setup() - - // Fund every TestAcc with 100 denom creation fees. - fundAccsAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100)), sdk.NewCoin("uion", sdk.NewInt(100000000))) + // Fund every TestAcc with two denoms, one of which is the denom creation fee + fundAccsAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100)), sdk.NewCoin(apptesting.SecondaryDenom, apptesting.SecondaryAmount)) for _, acc := range suite.TestAccs { suite.FundAcc(acc, fundAccsAmount) } diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index 98e2961f8a9..f8b3c7a276f 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "fmt" - "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/keeper" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -118,10 +117,11 @@ func (suite *KeeperTestSuite) TestCreateDenomMsg() { } { suite.SetupTest() suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tokenFactoryKeeper := suite.App.TokenFactoryKeeper ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) // Set denom creation fee in params - keeper.Keeper.SetParams(*suite.App.TokenFactoryKeeper, ctx, tc.denomCreationFee) + tokenFactoryKeeper.SetParams(suite.Ctx, tc.denomCreationFee) // Test create denom message suite.msgServer.CreateDenom(sdk.WrapSDKContext(ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), tc.subdenom)) // Ensure current number and type of event is emitted diff --git a/x/tokenfactory/types/expected_keepers.go b/x/tokenfactory/types/expected_keepers.go index 66102218483..4dfa4edc765 100644 --- a/x/tokenfactory/types/expected_keepers.go +++ b/x/tokenfactory/types/expected_keepers.go @@ -24,7 +24,6 @@ type BankKeeper interface { type AccountKeeper interface { SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI) - GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI } // CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions. From 83bd44e30067d5c5a147361696a413f45134b708 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 23 Aug 2022 15:37:34 -0500 Subject: [PATCH 7/9] address Roman's comments --- x/tokenfactory/keeper/createdenom_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index b9aca4510ae..9355d5af6df 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v11/app/apptesting" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" ) @@ -62,10 +63,12 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() { func (suite *KeeperTestSuite) TestCreateDenom() { var ( - defaultDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)))} - twoDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(50000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + primaryDenom = types.DefaultParams().DenomCreationFee[0].Denom + secondaryDenom = apptesting.SecondaryDenom + defaultDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(50000000)))} + twoDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(50000000)), sdk.NewCoin(secondaryDenom, sdk.NewInt(50000000)))} nilCreationFee = types.Params{DenomCreationFee: nil} - largeCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(5000000000)), sdk.NewCoin("uion", sdk.NewInt(50000000)))} + largeCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(5000000000)), sdk.NewCoin(secondaryDenom, sdk.NewInt(50000000)))} ) for _, tc := range []struct { From 6bcf5a3a96cc4fe3d1095aadaedbea9dccf6e36d Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Tue, 23 Aug 2022 16:54:20 -0500 Subject: [PATCH 8/9] fix burn message emit name clash --- CHANGELOG.md | 3 +++ x/tokenfactory/keeper/msg_server_test.go | 4 +--- x/tokenfactory/types/msgs.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5cbafa8a92..6e51f5269c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes +* [#2477](https://github.com/osmosis-labs/osmosis/pull/2477) Tokenfactory burn msg clash with sdk + * TypeMsgBurn: from "burn" to "tf_burn" + * TypeMsgMint: from "mint" to "tf_mint" * [#2222](https://github.com/osmosis-labs/osmosis/pull/2222) Add scaling factors to MsgCreateStableswapPool * [#1889](https://github.com/osmosis-labs/osmosis/pull/1825) Add proto responses to gamm LP messages: * MsgJoinPoolResponse: share_out_amount and token_in fields diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index f8b3c7a276f..f21f1915ad3 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -51,12 +51,10 @@ func (suite *KeeperTestSuite) TestMintDenomMsg() { // TestBurnDenomMsg tests TypeMsgBurn message is emitted on a successful burn func (suite *KeeperTestSuite) TestBurnDenomMsg() { - var addr0bal int64 // Create a denom. suite.CreateDefaultDenom() // mint 10 default token for testAcc[0] suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) - addr0bal += 10 for _, tc := range []struct { desc string @@ -77,7 +75,7 @@ func (suite *KeeperTestSuite) TestBurnDenomMsg() { burnDenom: suite.defaultDenom, admin: suite.TestAccs[0].String(), valid: true, - expectedMessageEvents: 2, // TODO: why is this two + expectedMessageEvents: 1, }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { diff --git a/x/tokenfactory/types/msgs.go b/x/tokenfactory/types/msgs.go index 79474686cc3..9c78328e13f 100644 --- a/x/tokenfactory/types/msgs.go +++ b/x/tokenfactory/types/msgs.go @@ -9,8 +9,8 @@ import ( // constants const ( TypeMsgCreateDenom = "create_denom" - TypeMsgMint = "mint" - TypeMsgBurn = "burn" + TypeMsgMint = "tf_mint" + TypeMsgBurn = "tf_burn" TypeMsgForceTransfer = "force_transfer" TypeMsgChangeAdmin = "change_admin" TypeMsgSetDenomMetadata = "set_denom_metadata" From 3653a492a0187ccf08531372ccb2bceba68b836c Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 24 Aug 2022 14:23:14 -0500 Subject: [PATCH 9/9] address Dev comment --- x/tokenfactory/keeper/createdenom.go | 6 ------ x/tokenfactory/keeper/createdenom_test.go | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/x/tokenfactory/keeper/createdenom.go b/x/tokenfactory/keeper/createdenom.go index ecccce48f15..636ec250fd9 100644 --- a/x/tokenfactory/keeper/createdenom.go +++ b/x/tokenfactory/keeper/createdenom.go @@ -4,7 +4,6 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/osmosis-labs/osmosis/v11/x/tokenfactory/types" @@ -79,11 +78,6 @@ func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string, subden return err } if creationFee != nil { - for _, coin := range creationFee { - if !k.bankKeeper.HasBalance(ctx, accAddr, coin) { - return sdkerrors.ErrInsufficientFunds - } - } if err := k.communityPoolKeeper.FundCommunityPool(ctx, creationFee, accAddr); err != nil { return err } diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index 9355d5af6df..81572fecd03 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -68,7 +68,7 @@ func (suite *KeeperTestSuite) TestCreateDenom() { defaultDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(50000000)))} twoDenomCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(50000000)), sdk.NewCoin(secondaryDenom, sdk.NewInt(50000000)))} nilCreationFee = types.Params{DenomCreationFee: nil} - largeCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(5000000000)), sdk.NewCoin(secondaryDenom, sdk.NewInt(50000000)))} + largeCreationFee = types.Params{DenomCreationFee: sdk.NewCoins(sdk.NewCoin(primaryDenom, sdk.NewInt(5000000000)))} ) for _, tc := range []struct {