Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: rename to TokenFactoryMsg (match osmosis) #805

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified interchaintest/contracts/tokenfactory_core.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion interchaintest/module_tokenfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
41 changes: 19 additions & 22 deletions x/tokenfactory/bindings/custom_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{})
Expand All @@ -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(),
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -123,15 +123,15 @@ 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{})
require.NoError(t, err)
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(),
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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{})
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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{})
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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{
Expand Down
9 changes: 3 additions & 6 deletions x/tokenfactory/bindings/custom_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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))

Expand Down
29 changes: 12 additions & 17 deletions x/tokenfactory/bindings/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
25 changes: 10 additions & 15 deletions x/tokenfactory/bindings/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions x/tokenfactory/bindings/testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# token-reflect-contract

<https://github.com/CosmosContracts/token-bindings>

Commit: 834bb36573fb21c74f8e78207308d9001df127a2
19 changes: 0 additions & 19 deletions x/tokenfactory/bindings/testdata/download_releases.sh

This file was deleted.

Binary file modified x/tokenfactory/bindings/testdata/token_reflect.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion x/tokenfactory/bindings/testdata/version.txt

This file was deleted.

4 changes: 0 additions & 4 deletions x/tokenfactory/bindings/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 1 addition & 5 deletions x/tokenfactory/bindings/types/query.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
Loading