diff --git a/interchaintest/contracts/tokenfactory_core.wasm b/interchaintest/contracts/tokenfactory_core.wasm index b6994d28f..532d536c0 100644 Binary files a/interchaintest/contracts/tokenfactory_core.wasm and b/interchaintest/contracts/tokenfactory_core.wasm differ diff --git a/interchaintest/module_tokenfactory_test.go b/interchaintest/module_tokenfactory_test.go index 69d855612..86004c45c 100644 --- a/interchaintest/module_tokenfactory_test.go +++ b/interchaintest/module_tokenfactory_test.go @@ -51,7 +51,7 @@ func TestJunoTokenFactory(t *testing.T) { } // This allows the uaddr here to mint tokens on behalf of the contract. Typically you only allow a contract here, but this is testing. - coreInitMsg := fmt.Sprintf(`{"allowed_mint_addresses":["%s"],"denoms":["%s"]}`, uaddr, tfDenom) + coreInitMsg := fmt.Sprintf(`{"allowed_mint_addresses":["%s"],"existing_denoms":["%s"]}`, uaddr, tfDenom) _, coreTFContract := helpers.SetupContract(t, ctx, juno, user.KeyName(), "contracts/tokenfactory_core.wasm", coreInitMsg) t.Log("coreContract", coreTFContract) diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index 99f81b284..016747707 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -77,6 +77,7 @@ func TestRandomizedGenState1(t *testing.T) { } for _, tt := range tests { + tt := tt require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) } } diff --git a/x/tokenfactory/bindings/custom_msg_test.go b/x/tokenfactory/bindings/custom_msg_test.go index a094db501..373c6fd0d 100644 --- a/x/tokenfactory/bindings/custom_msg_test.go +++ b/x/tokenfactory/bindings/custom_msg_test.go @@ -28,14 +28,14 @@ func TestCreateDenomMsg(t *testing.T) { reflectAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100))) fundAccount(t, ctx, junoapp, reflect, reflectAmount) - msg := bindings.TokenMsg{CreateDenom: &bindings.CreateDenom{ + msg := bindings.TokenFactoryMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, junoapp, reflect, lucky, msg, sdk.Coin{}) require.NoError(t, err) // query the denom and see if it matches - query := bindings.TokenQuery{ + query := bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", @@ -64,7 +64,7 @@ func TestMintMsg(t *testing.T) { require.Empty(t, balances) // Create denom for minting - msg := bindings.TokenMsg{CreateDenom: &bindings.CreateDenom{ + msg := bindings.TokenFactoryMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, junoapp, reflect, lucky, msg, sdk.Coin{}) @@ -73,7 +73,7 @@ func TestMintMsg(t *testing.T) { amount, ok := sdk.NewIntFromString("808010808") require.True(t, ok) - msg = bindings.TokenMsg{MintTokens: &bindings.MintTokens{ + msg = bindings.TokenFactoryMsg{MintTokens: &bindings.MintTokens{ Denom: sunDenom, Amount: amount, MintToAddress: lucky.String(), @@ -88,7 +88,7 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query := bindings.TokenQuery{ + query := bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", @@ -110,7 +110,7 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = bindings.TokenQuery{ + query = bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", @@ -123,7 +123,7 @@ func TestMintMsg(t *testing.T) { // now mint another amount / denom // create it first - msg = bindings.TokenMsg{CreateDenom: &bindings.CreateDenom{ + msg = bindings.TokenFactoryMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "MOON", }} err = executeCustom(t, ctx, junoapp, reflect, lucky, msg, sdk.Coin{}) @@ -131,7 +131,7 @@ func TestMintMsg(t *testing.T) { moonDenom := fmt.Sprintf("factory/%s/%s", reflect.String(), msg.CreateDenom.Subdenom) amount = amount.SubRaw(1) - msg = bindings.TokenMsg{MintTokens: &bindings.MintTokens{ + msg = bindings.TokenFactoryMsg{MintTokens: &bindings.MintTokens{ Denom: moonDenom, Amount: amount, MintToAddress: lucky.String(), @@ -146,7 +146,7 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = bindings.TokenQuery{ + query = bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "MOON", @@ -163,7 +163,7 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = bindings.TokenQuery{ + query = bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", @@ -193,7 +193,7 @@ func TestForceTransfer(t *testing.T) { require.Empty(t, balances) // Create denom for minting - msg := bindings.TokenMsg{CreateDenom: &bindings.CreateDenom{ + msg := bindings.TokenFactoryMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, junoapp, reflect, lucky, msg, sdk.Coin{}) @@ -204,7 +204,7 @@ func TestForceTransfer(t *testing.T) { require.True(t, ok) // Mint new tokens to lucky - msg = bindings.TokenMsg{MintTokens: &bindings.MintTokens{ + msg = bindings.TokenFactoryMsg{MintTokens: &bindings.MintTokens{ Denom: sunDenom, Amount: amount, MintToAddress: lucky.String(), @@ -213,7 +213,7 @@ func TestForceTransfer(t *testing.T) { require.NoError(t, err) // Force move 100 tokens from lucky to rcpt - msg = bindings.TokenMsg{ForceTransfer: &bindings.ForceTransfer{ + msg = bindings.TokenFactoryMsg{ForceTransfer: &bindings.ForceTransfer{ Denom: sunDenom, Amount: sdk.NewInt(100), FromAddress: lucky.String(), @@ -246,7 +246,7 @@ func TestBurnMsg(t *testing.T) { require.Empty(t, balances) // Create denom for minting - msg := bindings.TokenMsg{CreateDenom: &bindings.CreateDenom{ + msg := bindings.TokenFactoryMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, junoapp, reflect, lucky, msg, sdk.Coin{}) @@ -256,7 +256,7 @@ func TestBurnMsg(t *testing.T) { amount, ok := sdk.NewIntFromString("808010809") require.True(t, ok) - msg = bindings.TokenMsg{MintTokens: &bindings.MintTokens{ + msg = bindings.TokenFactoryMsg{MintTokens: &bindings.MintTokens{ Denom: sunDenom, Amount: amount, MintToAddress: lucky.String(), @@ -267,7 +267,7 @@ func TestBurnMsg(t *testing.T) { // can burn from different address with burnFrom amt, ok := sdk.NewIntFromString("1") require.True(t, ok) - msg = bindings.TokenMsg{BurnTokens: &bindings.BurnTokens{ + msg = bindings.TokenFactoryMsg{BurnTokens: &bindings.BurnTokens{ Denom: sunDenom, Amount: amt, BurnFromAddress: lucky.String(), @@ -280,7 +280,7 @@ func TestBurnMsg(t *testing.T) { err = junoapp.AppKeepers.BankKeeper.SendCoins(ctx, lucky, reflect, luckyBalance) require.NoError(t, err) - msg = bindings.TokenMsg{BurnTokens: &bindings.BurnTokens{ + msg = bindings.TokenFactoryMsg{BurnTokens: &bindings.BurnTokens{ Denom: sunDenom, Amount: amount.Abs().Sub(sdk.NewInt(1)), BurnFromAddress: reflect.String(), @@ -302,11 +302,8 @@ type ReflectSubMsgs struct { Msgs []wasmvmtypes.SubMsg `json:"msgs"` } -func executeCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, sender sdk.AccAddress, msg bindings.TokenMsg, funds sdk.Coin) error { //nolint:unparam // funds is always nil but could change in the future. - wrapped := bindings.TokenFactoryMsg{ - Token: &msg, - } - customBz, err := json.Marshal(wrapped) +func executeCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, sender sdk.AccAddress, msg bindings.TokenFactoryMsg, funds sdk.Coin) error { //nolint:unparam // funds is always nil but could change in the future. + customBz, err := json.Marshal(msg) require.NoError(t, err) reflectMsg := ReflectExec{ diff --git a/x/tokenfactory/bindings/custom_query_test.go b/x/tokenfactory/bindings/custom_query_test.go index 77711a8e0..926c68656 100644 --- a/x/tokenfactory/bindings/custom_query_test.go +++ b/x/tokenfactory/bindings/custom_query_test.go @@ -22,7 +22,7 @@ func TestQueryFullDenom(t *testing.T) { require.NotEmpty(t, reflect) // query full denom - query := bindings.TokenQuery{ + query := bindings.TokenFactoryQuery{ FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "ustart", @@ -47,11 +47,8 @@ type ChainResponse struct { Data []byte `json:"data"` } -func queryCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, request bindings.TokenQuery, response interface{}) { - wrapped := bindings.TokenFactoryQuery{ - Token: &request, - } - msgBz, err := json.Marshal(wrapped) +func queryCustom(t *testing.T, ctx sdk.Context, junoapp *app.App, contract sdk.AccAddress, request bindings.TokenFactoryQuery, response interface{}) { + msgBz, err := json.Marshal(request) require.NoError(t, err) fmt.Println("queryCustom1", string(msgBz)) diff --git a/x/tokenfactory/bindings/message_plugin.go b/x/tokenfactory/bindings/message_plugin.go index 04e21f714..d5de403e8 100644 --- a/x/tokenfactory/bindings/message_plugin.go +++ b/x/tokenfactory/bindings/message_plugin.go @@ -9,7 +9,6 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -46,28 +45,24 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre if err := json.Unmarshal(msg.Custom, &contractMsg); err != nil { return nil, nil, errorsmod.Wrap(err, "token factory msg") } - if contractMsg.Token == nil { - return nil, nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field") - } - tokenMsg := contractMsg.Token - if tokenMsg.CreateDenom != nil { - return m.createDenom(ctx, contractAddr, tokenMsg.CreateDenom) + if contractMsg.CreateDenom != nil { + return m.createDenom(ctx, contractAddr, contractMsg.CreateDenom) } - if tokenMsg.MintTokens != nil { - return m.mintTokens(ctx, contractAddr, tokenMsg.MintTokens) + if contractMsg.MintTokens != nil { + return m.mintTokens(ctx, contractAddr, contractMsg.MintTokens) } - if tokenMsg.ChangeAdmin != nil { - return m.changeAdmin(ctx, contractAddr, tokenMsg.ChangeAdmin) + if contractMsg.ChangeAdmin != nil { + return m.changeAdmin(ctx, contractAddr, contractMsg.ChangeAdmin) } - if tokenMsg.BurnTokens != nil { - return m.burnTokens(ctx, contractAddr, tokenMsg.BurnTokens) + if contractMsg.BurnTokens != nil { + return m.burnTokens(ctx, contractAddr, contractMsg.BurnTokens) } - if tokenMsg.SetMetadata != nil { - return m.setMetadata(ctx, contractAddr, tokenMsg.SetMetadata) + if contractMsg.SetMetadata != nil { + return m.setMetadata(ctx, contractAddr, contractMsg.SetMetadata) } - if tokenMsg.ForceTransfer != nil { - return m.forceTransfer(ctx, contractAddr, tokenMsg.ForceTransfer) + if contractMsg.ForceTransfer != nil { + return m.forceTransfer(ctx, contractAddr, contractMsg.ForceTransfer) } } return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) diff --git a/x/tokenfactory/bindings/query_plugin.go b/x/tokenfactory/bindings/query_plugin.go index 72d0073b3..3332bc8bb 100644 --- a/x/tokenfactory/bindings/query_plugin.go +++ b/x/tokenfactory/bindings/query_plugin.go @@ -9,7 +9,6 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bindingstypes "github.com/CosmosContracts/juno/v17/x/tokenfactory/bindings/types" ) @@ -21,15 +20,11 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag if err := json.Unmarshal(request, &contractQuery); err != nil { return nil, errorsmod.Wrap(err, "osmosis query") } - if contractQuery.Token == nil { - return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "nil token field") - } - tokenQuery := contractQuery.Token switch { - case tokenQuery.FullDenom != nil: - creator := tokenQuery.FullDenom.CreatorAddr - subdenom := tokenQuery.FullDenom.Subdenom + case contractQuery.FullDenom != nil: + creator := contractQuery.FullDenom.CreatorAddr + subdenom := contractQuery.FullDenom.Subdenom fullDenom, err := GetFullDenom(creator, subdenom) if err != nil { @@ -47,8 +42,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil - case tokenQuery.Admin != nil: - res, err := qp.GetDenomAdmin(ctx, tokenQuery.Admin.Denom) + case contractQuery.Admin != nil: + res, err := qp.GetDenomAdmin(ctx, contractQuery.Admin.Denom) if err != nil { return nil, err } @@ -60,8 +55,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil - case tokenQuery.Metadata != nil: - res, err := qp.GetMetadata(ctx, tokenQuery.Metadata.Denom) + case contractQuery.Metadata != nil: + res, err := qp.GetMetadata(ctx, contractQuery.Metadata.Denom) if err != nil { return nil, err } @@ -73,8 +68,8 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil - case tokenQuery.DenomsByCreator != nil: - res, err := qp.GetDenomsByCreator(ctx, tokenQuery.DenomsByCreator.Creator) + case contractQuery.DenomsByCreator != nil: + res, err := qp.GetDenomsByCreator(ctx, contractQuery.DenomsByCreator.Creator) if err != nil { return nil, err } @@ -86,7 +81,7 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag return bz, nil - case tokenQuery.Params != nil: + case contractQuery.Params != nil: res, err := qp.GetParams(ctx) if err != nil { return nil, err diff --git a/x/tokenfactory/bindings/testdata/README.md b/x/tokenfactory/bindings/testdata/README.md new file mode 100644 index 000000000..221c6518f --- /dev/null +++ b/x/tokenfactory/bindings/testdata/README.md @@ -0,0 +1,5 @@ +# token-reflect-contract + + + +Commit: 834bb36573fb21c74f8e78207308d9001df127a2 diff --git a/x/tokenfactory/bindings/testdata/download_releases.sh b/x/tokenfactory/bindings/testdata/download_releases.sh deleted file mode 100755 index 5413f3bf7..000000000 --- a/x/tokenfactory/bindings/testdata/download_releases.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -o errexit -o nounset -o pipefail -command -v shellcheck > /dev/null && shellcheck "$0" - -if [ $# -ne 1 ]; then - echo "Usage: ./download_releases.sh RELEASE_TAG" - exit 1 -fi - -tag="$1" - -# From CosmosContracts/token-bindings - -url="https://github.com/CosmWasm/token-bindings/releases/download/$tag/token_reflect.wasm" -echo "Downloading $url ..." -wget -O "token_reflect.wasm" "$url" - -rm -f version.txt -echo "$tag" >version.txt \ No newline at end of file diff --git a/x/tokenfactory/bindings/testdata/token_reflect.wasm b/x/tokenfactory/bindings/testdata/token_reflect.wasm index c27ec80a0..0526f1749 100755 Binary files a/x/tokenfactory/bindings/testdata/token_reflect.wasm and b/x/tokenfactory/bindings/testdata/token_reflect.wasm differ diff --git a/x/tokenfactory/bindings/testdata/version.txt b/x/tokenfactory/bindings/testdata/version.txt deleted file mode 100644 index f979adec6..000000000 --- a/x/tokenfactory/bindings/testdata/version.txt +++ /dev/null @@ -1 +0,0 @@ -v0.9.0 diff --git a/x/tokenfactory/bindings/types/msg.go b/x/tokenfactory/bindings/types/msg.go index 538d42651..81d9a68fd 100644 --- a/x/tokenfactory/bindings/types/msg.go +++ b/x/tokenfactory/bindings/types/msg.go @@ -3,10 +3,6 @@ package types import "cosmossdk.io/math" type TokenFactoryMsg struct { - Token *TokenMsg `json:"token,omitempty"` -} - -type TokenMsg struct { /// Contracts can create denoms, namespaced under the contract's address. /// A contract may create any number of independent sub-denoms. CreateDenom *CreateDenom `json:"create_denom,omitempty"` diff --git a/x/tokenfactory/bindings/types/query.go b/x/tokenfactory/bindings/types/query.go index f2dab4994..60f0ac3ed 100644 --- a/x/tokenfactory/bindings/types/query.go +++ b/x/tokenfactory/bindings/types/query.go @@ -1,11 +1,7 @@ package types -type TokenFactoryQuery struct { - Token *TokenQuery `json:"token,omitempty"` -} - // See https://github.com/CosmWasm/token-bindings/blob/main/packages/bindings/src/query.rs -type TokenQuery struct { +type TokenFactoryQuery struct { /// Given a subdenom minted by a contract via `OsmosisMsg::MintTokens`, /// returns the full denom as used by `BankMsg::Send`. FullDenom *FullDenom `json:"full_denom,omitempty"` diff --git a/x/tokenfactory/keeper/admins_test.go b/x/tokenfactory/keeper/admins_test.go index 5e2e54026..3757bb26a 100644 --- a/x/tokenfactory/keeper/admins_test.go +++ b/x/tokenfactory/keeper/admins_test.go @@ -131,6 +131,7 @@ func (suite *KeeperTestSuite) TestMintDenom() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tc := tc _, err := suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), &tc.mintMsg) if tc.expectPass { suite.Require().NoError(err) @@ -207,6 +208,7 @@ func (suite *KeeperTestSuite) TestBurnDenom() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tc := tc _, err := suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), &tc.burnMsg) if tc.expectPass { suite.Require().NoError(err) @@ -281,6 +283,7 @@ func (suite *KeeperTestSuite) TestForceTransferDenom() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tc := tc _, err := suite.msgServer.ForceTransfer(sdk.WrapSDKContext(suite.Ctx), &tc.forceTransferMsg) if tc.expectPass { suite.Require().NoError(err) @@ -505,6 +508,7 @@ func (suite *KeeperTestSuite) TestSetDenomMetaData() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tc := tc bankKeeper := suite.App.AppKeepers.BankKeeper res, err := suite.msgServer.SetDenomMetadata(sdk.WrapSDKContext(suite.Ctx), &tc.msgSetDenomMetadata) if tc.expectedPass { diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index 9cb93d8de..7e99a7773 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -238,6 +238,7 @@ func (suite *KeeperTestSuite) TestSetDenomMetaDataMsg() { }, } { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { + tc := tc ctx := suite.Ctx.WithEventManager(sdk.NewEventManager()) suite.Require().Equal(0, len(ctx.EventManager().Events())) // Test set denom metadata message