diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bed8dce1df..40eee7d9afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1671](https://github.com/osmosis-labs/osmosis/pull/1671) Add hourly epochs to `x/epochs` DefaultGenesis. * [#1665](https://github.com/osmosis-labs/osmosis/pull/1665) Delete app/App interface, instead use simapp.App * [#1630](https://github.com/osmosis-labs/osmosis/pull/1630) Delete the v043_temp module, now that we're on an updated SDK version. - +* [#1667](https://github.com/osmosis-labs/osmosis/pull/1673) Move wasm-bindings code out of app . ### Features diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index d3c3387eb43..f563ae5ec6c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -51,8 +51,8 @@ import ( bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types" bech32ics20keeper "github.com/osmosis-labs/bech32-ibc/x/bech32ics20/keeper" - owasm "github.com/osmosis-labs/osmosis/v7/app/wasm" _ "github.com/osmosis-labs/osmosis/v7/client/docs/statik" + owasm "github.com/osmosis-labs/osmosis/v7/wasmbinding" epochskeeper "github.com/osmosis-labs/osmosis/v7/x/epochs/keeper" epochstypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types" gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" diff --git a/simapp/params.json b/simapp/params.json index 47767a13761..8906d3a3efb 100644 --- a/simapp/params.json +++ b/simapp/params.json @@ -1,3 +1,3 @@ { - "op_reflect_contract_path": "../app/wasm/testdata/reflect.wasm" + "op_reflect_contract_path": "../wasmbinding/testdata/reflect.wasm" } diff --git a/app/wasm/README.md b/wasmbinding/README.md similarity index 92% rename from app/wasm/README.md rename to wasmbinding/README.md index 2f0b86de93d..0ec1bc01de6 100644 --- a/app/wasm/README.md +++ b/wasmbinding/README.md @@ -12,7 +12,7 @@ This package provides first class support for: - Minting / controlling of new native tokens - Swap -### Command line interface (CLI) +## Command line interface (CLI) - Commands @@ -26,7 +26,7 @@ This package provides first class support for: osmosisd query wasm -h ``` -### Tests +## Tests This contains a few high level tests that `x/wasm` is properly integrated. diff --git a/app/wasm/bindings/msg.go b/wasmbinding/bindings/msg.go similarity index 98% rename from app/wasm/bindings/msg.go rename to wasmbinding/bindings/msg.go index 483b479523f..6739d2dac6b 100644 --- a/app/wasm/bindings/msg.go +++ b/wasmbinding/bindings/msg.go @@ -1,4 +1,4 @@ -package wasmbindings +package bindings import sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/app/wasm/bindings/pool.go b/wasmbinding/bindings/pool.go similarity index 84% rename from app/wasm/bindings/pool.go rename to wasmbinding/bindings/pool.go index 7a3e545a93b..e7c78b8c40d 100644 --- a/app/wasm/bindings/pool.go +++ b/wasmbinding/bindings/pool.go @@ -1,4 +1,4 @@ -package wasmbindings +package bindings import sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/app/wasm/bindings/query.go b/wasmbinding/bindings/query.go similarity index 99% rename from app/wasm/bindings/query.go rename to wasmbinding/bindings/query.go index dd5dddb1a72..31748737f4d 100644 --- a/app/wasm/bindings/query.go +++ b/wasmbinding/bindings/query.go @@ -1,4 +1,4 @@ -package wasmbindings +package bindings import ( wasmvmtypes "github.com/CosmWasm/wasmvm/types" diff --git a/app/wasm/bindings/types.go b/wasmbinding/bindings/types.go similarity index 98% rename from app/wasm/bindings/types.go rename to wasmbinding/bindings/types.go index 716207e7b81..2f3d89a48f3 100644 --- a/app/wasm/bindings/types.go +++ b/wasmbinding/bindings/types.go @@ -1,4 +1,4 @@ -package wasmbindings +package bindings import ( "math" diff --git a/app/wasm/bindings/types_test.go b/wasmbinding/bindings/types_test.go similarity index 99% rename from app/wasm/bindings/types_test.go rename to wasmbinding/bindings/types_test.go index ae2c9ce154c..859c264d54b 100644 --- a/app/wasm/bindings/types_test.go +++ b/wasmbinding/bindings/types_test.go @@ -1,4 +1,4 @@ -package wasmbindings +package bindings import ( "encoding/json" diff --git a/app/wasm/message_plugin.go b/wasmbinding/message_plugin.go similarity index 89% rename from app/wasm/message_plugin.go rename to wasmbinding/message_plugin.go index b82f5c70526..6995bec723a 100644 --- a/app/wasm/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "encoding/json" @@ -9,7 +9,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" @@ -41,7 +41,7 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre if msg.Custom != nil { // only handle the happy path where this is really creating / minting / swapping ... // leave everything else for the wrapped version - var contractMsg wasmbindings.OsmosisMsg + var contractMsg bindings.OsmosisMsg if err := json.Unmarshal(msg.Custom, &contractMsg); err != nil { return nil, nil, sdkerrors.Wrap(err, "osmosis msg") } @@ -64,7 +64,7 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) } -func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *wasmbindings.CreateDenom) ([]sdk.Event, [][]byte, error) { +func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *bindings.CreateDenom) ([]sdk.Event, [][]byte, error) { err := PerformCreateDenom(m.tokenFactory, m.bank, ctx, contractAddr, createDenom) if err != nil { return nil, nil, sdkerrors.Wrap(err, "perform create denom") @@ -72,7 +72,7 @@ func (m *CustomMessenger) createDenom(ctx sdk.Context, contractAddr sdk.AccAddre return nil, nil, nil } -func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *wasmbindings.CreateDenom) error { +func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, createDenom *bindings.CreateDenom) error { if createDenom == nil { return wasmvmtypes.InvalidRequest{Err: "create denom null create denom"} } @@ -96,7 +96,7 @@ func PerformCreateDenom(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, return nil } -func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddress, mint *wasmbindings.MintTokens) ([]sdk.Event, [][]byte, error) { +func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) ([]sdk.Event, [][]byte, error) { err := PerformMint(m.tokenFactory, m.bank, ctx, contractAddr, mint) if err != nil { return nil, nil, sdkerrors.Wrap(err, "perform mint") @@ -104,7 +104,7 @@ func (m *CustomMessenger) mintTokens(ctx sdk.Context, contractAddr sdk.AccAddres return nil, nil, nil } -func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *wasmbindings.MintTokens) error { +func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk.Context, contractAddr sdk.AccAddress, mint *bindings.MintTokens) error { if mint == nil { return wasmvmtypes.InvalidRequest{Err: "mint token null mint"} } @@ -132,7 +132,7 @@ func PerformMint(f *tokenfactorykeeper.Keeper, b *bankkeeper.BaseKeeper, ctx sdk return nil } -func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *wasmbindings.ChangeAdmin) ([]sdk.Event, [][]byte, error) { +func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *bindings.ChangeAdmin) ([]sdk.Event, [][]byte, error) { err := ChangeAdmin(m.tokenFactory, ctx, contractAddr, changeAdmin) if err != nil { return nil, nil, sdkerrors.Wrap(err, "failed to change admin") @@ -140,7 +140,7 @@ func (m *CustomMessenger) changeAdmin(ctx sdk.Context, contractAddr sdk.AccAddre return nil, nil, nil } -func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *wasmbindings.ChangeAdmin) error { +func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, changeAdmin *bindings.ChangeAdmin) error { if changeAdmin == nil { return wasmvmtypes.InvalidRequest{Err: "changeAdmin is nil"} } @@ -162,7 +162,7 @@ func ChangeAdmin(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk return nil } -func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddress, burn *wasmbindings.BurnTokens) ([]sdk.Event, [][]byte, error) { +func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddress, burn *bindings.BurnTokens) ([]sdk.Event, [][]byte, error) { err := PerformBurn(m.tokenFactory, ctx, contractAddr, burn) if err != nil { return nil, nil, sdkerrors.Wrap(err, "perform burn") @@ -170,7 +170,7 @@ func (m *CustomMessenger) burnTokens(ctx sdk.Context, contractAddr sdk.AccAddres return nil, nil, nil } -func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, burn *wasmbindings.BurnTokens) error { +func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, burn *bindings.BurnTokens) error { if burn == nil { return wasmvmtypes.InvalidRequest{Err: "burn token null mint"} } @@ -193,7 +193,7 @@ func PerformBurn(f *tokenfactorykeeper.Keeper, ctx sdk.Context, contractAddr sdk return nil } -func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddress, swap *wasmbindings.SwapMsg) ([]sdk.Event, [][]byte, error) { +func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddress, swap *bindings.SwapMsg) ([]sdk.Event, [][]byte, error) { _, err := PerformSwap(m.gammKeeper, ctx, contractAddr, swap) if err != nil { return nil, nil, sdkerrors.Wrap(err, "perform swap") @@ -202,7 +202,7 @@ func (m *CustomMessenger) swapTokens(ctx sdk.Context, contractAddr sdk.AccAddres } // PerformSwap can be used both for the real swap, and the EstimateSwap query -func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, swap *wasmbindings.SwapMsg) (*wasmbindings.SwapAmount, error) { +func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, swap *bindings.SwapMsg) (*bindings.SwapAmount, error) { if swap == nil { return nil, wasmvmtypes.InvalidRequest{Err: "gamm perform swap null swap"} } @@ -229,7 +229,7 @@ func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.Ac if err != nil { return nil, sdkerrors.Wrap(err, "gamm perform swap exact amount in") } - return &wasmbindings.SwapAmount{Out: &tokenOutAmount}, nil + return &bindings.SwapAmount{Out: &tokenOutAmount}, nil } else if swap.Amount.ExactOut != nil { routes := []gammtypes.SwapAmountOutRoute{{ PoolId: swap.First.PoolId, @@ -255,7 +255,7 @@ func PerformSwap(keeper *gammkeeper.Keeper, ctx sdk.Context, contractAddr sdk.Ac if err != nil { return nil, sdkerrors.Wrap(err, "gamm perform swap exact amount out") } - return &wasmbindings.SwapAmount{In: &tokenInAmount}, nil + return &bindings.SwapAmount{In: &tokenInAmount}, nil } else { return nil, wasmvmtypes.UnsupportedRequest{Kind: "must support either Swap.ExactIn or Swap.ExactOut"} } diff --git a/app/wasm/queries.go b/wasmbinding/queries.go similarity index 84% rename from app/wasm/queries.go rename to wasmbinding/queries.go index e0a8972a91c..8136b5005a0 100644 --- a/app/wasm/queries.go +++ b/wasmbinding/queries.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "fmt" @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" gammkeeper "github.com/osmosis-labs/osmosis/v7/x/gamm/keeper" gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" tokenfactorykeeper "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/keeper" @@ -26,22 +26,22 @@ func NewQueryPlugin(gk *gammkeeper.Keeper, tfk *tokenfactorykeeper.Keeper) *Quer } } -func (qp QueryPlugin) GetDenomAdmin(ctx sdk.Context, denom string) (*wasmbindings.DenomAdminResponse, error) { +func (qp QueryPlugin) GetDenomAdmin(ctx sdk.Context, denom string) (*bindings.DenomAdminResponse, error) { metadata, err := qp.tokenFactoryKeeper.GetAuthorityMetadata(ctx, denom) if err != nil { return nil, fmt.Errorf("failed to get admin for denom: %s", denom) } - return &wasmbindings.DenomAdminResponse{Admin: metadata.Admin}, nil + return &bindings.DenomAdminResponse{Admin: metadata.Admin}, nil } -func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*wasmbindings.PoolAssets, error) { +func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*bindings.PoolAssets, error) { poolData, err := qp.gammKeeper.GetPoolAndPoke(ctx, poolID) if err != nil { return nil, sdkerrors.Wrap(err, "gamm get pool") } - return &wasmbindings.PoolAssets{ + return &bindings.PoolAssets{ Assets: poolData.GetTotalPoolLiquidity(ctx), Shares: sdk.Coin{ Denom: gammtypes.GetPoolShareDenom(poolID), @@ -50,7 +50,7 @@ func (qp QueryPlugin) GetPoolState(ctx sdk.Context, poolID uint64) (*wasmbinding }, nil } -func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *wasmbindings.SpotPrice) (*sdk.Dec, error) { +func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *bindings.SpotPrice) (*sdk.Dec, error) { if spotPrice == nil { return nil, wasmvmtypes.InvalidRequest{Err: "gamm spot price null"} } @@ -77,7 +77,7 @@ func (qp QueryPlugin) GetSpotPrice(ctx sdk.Context, spotPrice *wasmbindings.Spot return &price, nil } -func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *wasmbindings.EstimateSwap) (*wasmbindings.SwapAmount, error) { +func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *bindings.EstimateSwap) (*bindings.SwapAmount, error) { if estimateSwap == nil { return nil, wasmvmtypes.InvalidRequest{Err: "gamm estimate swap null"} } @@ -92,7 +92,7 @@ func (qp QueryPlugin) EstimateSwap(ctx sdk.Context, estimateSwap *wasmbindings.E return nil, sdkerrors.Wrap(err, "gamm estimate swap sender address") } - if estimateSwap.Amount == (wasmbindings.SwapAmount{}) { + if estimateSwap.Amount == (bindings.SwapAmount{}) { return nil, wasmvmtypes.InvalidRequest{Err: "gamm estimate swap empty swap"} } diff --git a/app/wasm/query_plugin.go b/wasmbinding/query_plugin.go similarity index 97% rename from app/wasm/query_plugin.go rename to wasmbinding/query_plugin.go index 1bda7004db0..d23567b1f1c 100644 --- a/app/wasm/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "encoding/json" @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - bindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" ) func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { diff --git a/app/wasm/test/custom_msg_test.go b/wasmbinding/test/custom_msg_test.go similarity index 78% rename from app/wasm/test/custom_msg_test.go rename to wasmbinding/test/custom_msg_test.go index a2ee4b388de..be4b81a8699 100644 --- a/app/wasm/test/custom_msg_test.go +++ b/wasmbinding/test/custom_msg_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "encoding/json" @@ -14,7 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/v7/app" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" ) func TestCreateDenomMsg(t *testing.T) { @@ -29,20 +29,20 @@ 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, osmosis, reflect, reflectAmount) - msg := wasmbindings.OsmosisMsg{CreateDenom: &wasmbindings.CreateDenom{ + msg := bindings.OsmosisMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, osmosis, reflect, lucky, msg, sdk.Coin{}) require.NoError(t, err) // query the denom and see if it matches - query := wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query := bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", }, } - resp := wasmbindings.FullDenomResponse{} + resp := bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.Equal(t, resp.Denom, fmt.Sprintf("factory/%s/SUN", reflect.String())) @@ -65,7 +65,7 @@ func TestMintMsg(t *testing.T) { require.Empty(t, balances) // Create denom for minting - msg := wasmbindings.OsmosisMsg{CreateDenom: &wasmbindings.CreateDenom{ + msg := bindings.OsmosisMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, osmosis, reflect, lucky, msg, sdk.Coin{}) @@ -74,7 +74,7 @@ func TestMintMsg(t *testing.T) { amount, ok := sdk.NewIntFromString("808010808") require.True(t, ok) - msg = wasmbindings.OsmosisMsg{MintTokens: &wasmbindings.MintTokens{ + msg = bindings.OsmosisMsg{MintTokens: &bindings.MintTokens{ Denom: sunDenom, Amount: amount, MintToAddress: lucky.String(), @@ -89,13 +89,13 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query := wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query := bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", }, } - resp := wasmbindings.FullDenomResponse{} + resp := bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.Equal(t, resp.Denom, coin.Denom) @@ -111,20 +111,20 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query = bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", }, } - resp = wasmbindings.FullDenomResponse{} + resp = bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.Equal(t, resp.Denom, coin.Denom) // now mint another amount / denom // create it first - msg = wasmbindings.OsmosisMsg{CreateDenom: &wasmbindings.CreateDenom{ + msg = bindings.OsmosisMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "MOON", }} err = executeCustom(t, ctx, osmosis, reflect, lucky, msg, sdk.Coin{}) @@ -132,7 +132,7 @@ func TestMintMsg(t *testing.T) { moonDenom := fmt.Sprintf("factory/%s/%s", reflect.String(), msg.CreateDenom.Subdenom) amount = amount.SubRaw(1) - msg = wasmbindings.OsmosisMsg{MintTokens: &wasmbindings.MintTokens{ + msg = bindings.OsmosisMsg{MintTokens: &bindings.MintTokens{ Denom: moonDenom, Amount: amount, MintToAddress: lucky.String(), @@ -147,13 +147,13 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query = bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "MOON", }, } - resp = wasmbindings.FullDenomResponse{} + resp = bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.Equal(t, resp.Denom, coin.Denom) @@ -164,13 +164,13 @@ func TestMintMsg(t *testing.T) { require.Contains(t, coin.Denom, "factory/") // query the denom and see if it matches - query = wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query = bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "SUN", }, } - resp = wasmbindings.FullDenomResponse{} + resp = bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.Equal(t, resp.Denom, coin.Denom) @@ -193,7 +193,7 @@ func TestBurnMsg(t *testing.T) { require.Empty(t, balances) // Create denom for minting - msg := wasmbindings.OsmosisMsg{CreateDenom: &wasmbindings.CreateDenom{ + msg := bindings.OsmosisMsg{CreateDenom: &bindings.CreateDenom{ Subdenom: "SUN", }} err := executeCustom(t, ctx, osmosis, reflect, lucky, msg, sdk.Coin{}) @@ -203,7 +203,7 @@ func TestBurnMsg(t *testing.T) { amount, ok := sdk.NewIntFromString("808010808") require.True(t, ok) - msg = wasmbindings.OsmosisMsg{MintTokens: &wasmbindings.MintTokens{ + msg = bindings.OsmosisMsg{MintTokens: &bindings.MintTokens{ Denom: sunDenom, Amount: amount, MintToAddress: lucky.String(), @@ -212,7 +212,7 @@ func TestBurnMsg(t *testing.T) { require.NoError(t, err) // can't burn from different address - msg = wasmbindings.OsmosisMsg{BurnTokens: &wasmbindings.BurnTokens{ + msg = bindings.OsmosisMsg{BurnTokens: &bindings.BurnTokens{ Denom: sunDenom, Amount: amount, BurnFromAddress: lucky.String(), @@ -225,7 +225,7 @@ func TestBurnMsg(t *testing.T) { err = osmosis.BankKeeper.SendCoins(ctx, lucky, reflect, luckyBalance) require.NoError(t, err) - msg = wasmbindings.OsmosisMsg{BurnTokens: &wasmbindings.BurnTokens{ + msg = bindings.OsmosisMsg{BurnTokens: &bindings.BurnTokens{ Denom: sunDenom, Amount: amount, BurnFromAddress: reflect.String(), @@ -244,24 +244,24 @@ func TestSwapMsg(t *testing.T) { // table tests with this setup cases := []struct { name string - msg func(BaseState) *wasmbindings.SwapMsg + msg func(BaseState) *bindings.SwapMsg expectErr bool initFunds sdk.Coin finalFunds []sdk.Coin }{ { name: "exact in: simple swap works", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "uosmo", DenomOut: "ustar", }, // Note: you must use empty array, not nil, for valid Rust JSON - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(12000000), MinOutput: sdk.NewInt(5000000), }, @@ -276,17 +276,17 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact in: price too low", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "uosmo", DenomOut: "ustar", }, // Note: you must use empty array, not nil, for valid Rust JSON - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(12000000), MinOutput: sdk.NewInt(555000000), }, @@ -298,17 +298,17 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact in: not enough funds to swap", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "uosmo", DenomOut: "ustar", }, // Note: you must use empty array, not nil, for valid Rust JSON - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(12000000), MinOutput: sdk.NewInt(5000000), }, @@ -320,17 +320,17 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact in: invalidPool", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "uosmo", DenomOut: "uatom", }, // Note: you must use empty array, not nil, for valid Rust JSON - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(12000000), MinOutput: sdk.NewInt(100000), }, @@ -344,17 +344,17 @@ func TestSwapMsg(t *testing.T) { // FIXME: this panics in GAMM module !?! hits a known TODO // https://github.com/osmosis-labs/osmosis/blob/a380ab2fcd39fb94c2b10411e07daf664911257a/osmomath/math.go#L47-L51 //"exact out: panics if too much swapped": { - // msg: func(state BaseState) *wasmbindings.SwapMsg { - // return &wasmbindings.SwapMsg{ - // First: wasmbindings.Swap{ + // msg: func(state BaseState) *bindings.SwapMsg { + // return &bindings.SwapMsg{ + // First: bindings.Swap{ // PoolId: state.StarPool, // DenomIn: "uosmo", // DenomOut: "ustar", // }, // // Note: you must use empty array, not nil, for valid Rust JSON - // Route: []wasmbindings.Step{}, - // Amount: wasmbindings.SwapAmountWithLimit{ - // ExactOut: &wasmbindings.ExactOut{ + // Route: []bindings.Step{}, + // Amount: bindings.SwapAmountWithLimit{ + // ExactOut: &bindings.ExactOut{ // MaxInput: sdk.NewInt(22000000), // Output: sdk.NewInt(120000000), // }, @@ -369,17 +369,17 @@ func TestSwapMsg(t *testing.T) { //}, { name: "exact out: simple swap works", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.AtomPool, DenomIn: "uosmo", DenomOut: "uatom", }, // Note: you must use empty array, not nil, for valid Rust JSON - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactOut: &wasmbindings.ExactOut{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmountWithLimit{ + ExactOut: &bindings.ExactOut{ // 12 OSMO * 6 ATOM == 18 OSMO * 4 ATOM (+6 OSMO, -2 ATOM) MaxInput: sdk.NewInt(7000000), Output: sdk.NewInt(2000000), @@ -395,19 +395,19 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact in: 2 step multi-hop", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: state.AtomPool, DenomOut: "uatom", }}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(240000000), MinOutput: sdk.NewInt(1999000), }, @@ -423,19 +423,19 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact out: 2 step multi-hop", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.AtomPool, DenomIn: "uosmo", DenomOut: "uatom", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: state.RegenPool, DenomOut: "uregen", }}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactOut: &wasmbindings.ExactOut{ + Amount: bindings.SwapAmountWithLimit{ + ExactOut: &bindings.ExactOut{ MaxInput: sdk.NewInt(2000000), Output: sdk.NewInt(12000000 - 12), }, @@ -454,19 +454,19 @@ func TestSwapMsg(t *testing.T) { // https://github.com/osmosis-labs/osmosis/blob/a380ab2fcd39fb94c2b10411e07daf664911257a/osmomath/math.go#L47-L51 // { // name: "exact out: panics on math power stuff", - // msg: func(state BaseState) *wasmbindings.SwapMsg { - // return &wasmbindings.SwapMsg{ - // First: wasmbindings.Swap{ + // msg: func(state BaseState) *bindings.SwapMsg { + // return &bindings.SwapMsg{ + // First: bindings.Swap{ // PoolId: state.StarPool, // DenomIn: "ustar", // DenomOut: "uosmo", // }, - // Route: []wasmbindings.Step{{ + // Route: []bindings.Step{{ // PoolId: state.AtomPool, // DenomOut: "uatom", // }}, - // Amount: wasmbindings.SwapAmountWithLimit{ - // ExactOut: &wasmbindings.ExactOut{ + // Amount: bindings.SwapAmountWithLimit{ + // ExactOut: &bindings.ExactOut{ // MaxInput: sdk.NewInt(240005000), // Output: sdk.NewInt(2000000), // }, @@ -483,22 +483,22 @@ func TestSwapMsg(t *testing.T) { // }, { name: "exact in: 3 step multi-hop", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: state.AtomPool, DenomOut: "uatom", }, { PoolId: state.RegenPool, DenomOut: "uregen", }}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactIn: &wasmbindings.ExactIn{ + Amount: bindings.SwapAmountWithLimit{ + ExactIn: &bindings.ExactIn{ Input: sdk.NewInt(240000000), MinOutput: sdk.NewInt(23900000), }, @@ -515,22 +515,22 @@ func TestSwapMsg(t *testing.T) { }, { name: "exact out: 3 step multi-hop", - msg: func(state BaseState) *wasmbindings.SwapMsg { - return &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + msg: func(state BaseState) *bindings.SwapMsg { + return &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: state.StarPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: state.AtomPool, DenomOut: "uatom", }, { PoolId: state.RegenPool, DenomOut: "uregen", }}, - Amount: wasmbindings.SwapAmountWithLimit{ - ExactOut: &wasmbindings.ExactOut{ + Amount: bindings.SwapAmountWithLimit{ + ExactOut: &bindings.ExactOut{ MaxInput: sdk.NewInt(50000000), Output: sdk.NewInt(12000000), }, @@ -559,7 +559,7 @@ func TestSwapMsg(t *testing.T) { reflect := instantiateReflectContract(t, ctx, osmosis, trader) require.NotEmpty(t, reflect) - msg := wasmbindings.OsmosisMsg{Swap: tc.msg(state)} + msg := bindings.OsmosisMsg{Swap: tc.msg(state)} err := executeCustom(t, ctx, osmosis, reflect, trader, msg, tc.initFunds) if tc.expectErr { require.Error(t, err) @@ -628,7 +628,7 @@ type ReflectSubMsgs struct { Msgs []wasmvmtypes.SubMsg `json:"msgs"` } -func executeCustom(t *testing.T, ctx sdk.Context, osmosis *app.OsmosisApp, contract sdk.AccAddress, sender sdk.AccAddress, msg wasmbindings.OsmosisMsg, funds sdk.Coin) error { +func executeCustom(t *testing.T, ctx sdk.Context, osmosis *app.OsmosisApp, contract sdk.AccAddress, sender sdk.AccAddress, msg bindings.OsmosisMsg, funds sdk.Coin) error { customBz, err := json.Marshal(msg) require.NoError(t, err) reflectMsg := ReflectExec{ diff --git a/app/wasm/test/custom_query_test.go b/wasmbinding/test/custom_query_test.go similarity index 85% rename from app/wasm/test/custom_query_test.go rename to wasmbinding/test/custom_query_test.go index 1fb88e354a4..2a1bcd2c29a 100644 --- a/app/wasm/test/custom_query_test.go +++ b/wasmbinding/test/custom_query_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "encoding/json" @@ -16,8 +16,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/v7/app" - "github.com/osmosis-labs/osmosis/v7/app/wasm" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" ) @@ -50,13 +50,13 @@ func TestQueryFullDenom(t *testing.T) { require.NotEmpty(t, reflect) // query full denom - query := wasmbindings.OsmosisQuery{ - FullDenom: &wasmbindings.FullDenom{ + query := bindings.OsmosisQuery{ + FullDenom: &bindings.FullDenom{ CreatorAddr: reflect.String(), Subdenom: "ustart", }, } - resp := wasmbindings.FullDenomResponse{} + resp := bindings.FullDenomResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) expected := fmt.Sprintf("factory/%s/ustart", reflect.String()) @@ -87,22 +87,22 @@ func TestQueryPool(t *testing.T) { require.NotEmpty(t, reflect) // query pool state - query := wasmbindings.OsmosisQuery{ - PoolState: &wasmbindings.PoolState{PoolId: starPool}, + query := bindings.OsmosisQuery{ + PoolState: &bindings.PoolState{PoolId: starPool}, } - resp := wasmbindings.PoolStateResponse{} + resp := bindings.PoolStateResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) - expected := wasm.ConvertSdkCoinsToWasmCoins(poolFunds) + expected := wasmbinding.ConvertSdkCoinsToWasmCoins(poolFunds) require.EqualValues(t, expected, resp.Assets) assertValidShares(t, resp.Shares, starPool) // query second pool state - query = wasmbindings.OsmosisQuery{ - PoolState: &wasmbindings.PoolState{PoolId: atomPool}, + query = bindings.OsmosisQuery{ + PoolState: &bindings.PoolState{PoolId: atomPool}, } - resp = wasmbindings.PoolStateResponse{} + resp = bindings.PoolStateResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) - expected = wasm.ConvertSdkCoinsToWasmCoins(pool2Funds) + expected = wasmbinding.ConvertSdkCoinsToWasmCoins(pool2Funds) require.EqualValues(t, expected, resp.Assets) assertValidShares(t, resp.Shares, atomPool) } @@ -126,9 +126,9 @@ func TestQuerySpotPrice(t *testing.T) { require.NotEmpty(t, reflect) // query spot price - query := wasmbindings.OsmosisQuery{ - SpotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + query := bindings.OsmosisQuery{ + SpotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", @@ -136,7 +136,7 @@ func TestQuerySpotPrice(t *testing.T) { WithSwapFee: false, }, } - resp := wasmbindings.SpotPriceResponse{} + resp := bindings.SpotPriceResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) price, err := strconv.ParseFloat(resp.Price, 64) @@ -152,9 +152,9 @@ func TestQuerySpotPrice(t *testing.T) { // and the reverse conversion (with swap fee) // query spot price - query = wasmbindings.OsmosisQuery{ - SpotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + query = bindings.OsmosisQuery{ + SpotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", @@ -162,7 +162,7 @@ func TestQuerySpotPrice(t *testing.T) { WithSwapFee: true, }, } - resp = wasmbindings.SpotPriceResponse{} + resp = bindings.SpotPriceResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) price, err = strconv.ParseFloat(resp.Price, 32) @@ -201,21 +201,21 @@ func TestQueryEstimateSwap(t *testing.T) { // Query estimate cost (Exact in. No route) amountIn := sdk.NewInt(10000) - query := wasmbindings.OsmosisQuery{ - EstimateSwap: &wasmbindings.EstimateSwap{ + query := bindings.OsmosisQuery{ + EstimateSwap: &bindings.EstimateSwap{ Sender: reflect.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmount{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmount{ In: &amountIn, }, }, } - resp := wasmbindings.EstimatePriceResponse{} + resp := bindings.EstimatePriceResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.NotNil(t, resp.Amount.Out) require.Nil(t, resp.Amount.In) @@ -230,21 +230,21 @@ func TestQueryEstimateSwap(t *testing.T) { // And the other way around // Query estimate cost (Exact out. No route) amountOut := sdk.NewInt(10000) - query = wasmbindings.OsmosisQuery{ - EstimateSwap: &wasmbindings.EstimateSwap{ + query = bindings.OsmosisQuery{ + EstimateSwap: &bindings.EstimateSwap{ Sender: reflect.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, - Route: []wasmbindings.Step{}, - Amount: wasmbindings.SwapAmount{ + Route: []bindings.Step{}, + Amount: bindings.SwapAmount{ Out: &amountOut, }, }, } - resp = wasmbindings.EstimatePriceResponse{} + resp = bindings.EstimatePriceResponse{} queryCustom(t, ctx, osmosis, reflect, query, &resp) require.NotNil(t, resp.Amount.In) require.Nil(t, resp.Amount.Out) @@ -269,7 +269,7 @@ type ChainResponse struct { Data []byte `json:"data"` } -func queryCustom(t *testing.T, ctx sdk.Context, osmosis *app.OsmosisApp, contract sdk.AccAddress, request wasmbindings.OsmosisQuery, response interface{}) { +func queryCustom(t *testing.T, ctx sdk.Context, osmosis *app.OsmosisApp, contract sdk.AccAddress, request bindings.OsmosisQuery, response interface{}) { msgBz, err := json.Marshal(request) require.NoError(t, err) diff --git a/app/wasm/test/helpers_test.go b/wasmbinding/test/helpers_test.go similarity index 98% rename from app/wasm/test/helpers_test.go rename to wasmbinding/test/helpers_test.go index bebc1938ef0..b4e0b9b34a3 100644 --- a/app/wasm/test/helpers_test.go +++ b/wasmbinding/test/helpers_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "testing" diff --git a/app/wasm/test/messages_test.go b/wasmbinding/test/messages_test.go similarity index 74% rename from app/wasm/test/messages_test.go rename to wasmbinding/test/messages_test.go index 3ddc75a9666..e5288d4db58 100644 --- a/app/wasm/test/messages_test.go +++ b/wasmbinding/test/messages_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "fmt" @@ -7,8 +7,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v7/app/wasm" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" "github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types" "github.com/stretchr/testify/assert" @@ -24,22 +24,22 @@ func TestCreateDenom(t *testing.T) { fundAccount(t, ctx, osmosis, actor, actorAmount) specs := map[string]struct { - createDenom *wasmbindings.CreateDenom + createDenom *bindings.CreateDenom expErr bool }{ "valid sub-denom": { - createDenom: &wasmbindings.CreateDenom{ + createDenom: &bindings.CreateDenom{ Subdenom: "MOON", }, }, "empty sub-denom": { - createDenom: &wasmbindings.CreateDenom{ + createDenom: &bindings.CreateDenom{ Subdenom: "", }, expErr: false, }, "invalid sub-denom": { - createDenom: &wasmbindings.CreateDenom{ + createDenom: &bindings.CreateDenom{ Subdenom: "sub-denom_2", }, expErr: true, @@ -52,7 +52,7 @@ func TestCreateDenom(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { // when - gotErr := wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, actor, spec.createDenom) + gotErr := wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, actor, spec.createDenom) // then if spec.expErr { require.Error(t, gotErr) @@ -70,19 +70,19 @@ func TestChangeAdmin(t *testing.T) { specs := map[string]struct { actor sdk.AccAddress - changeAdmin *wasmbindings.ChangeAdmin + changeAdmin *bindings.ChangeAdmin expErrMsg string }{ "valid": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", tokenCreator.String(), validDenom), NewAdminAddress: RandomBech32AccountAddress(), }, actor: tokenCreator, }, "typo in factory in denom name": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("facory/%s/%s", tokenCreator.String(), validDenom), NewAdminAddress: RandomBech32AccountAddress(), }, @@ -90,7 +90,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: "denom prefix is incorrect. Is: facory. Should be: factory: invalid denom", }, "invalid address in denom": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", RandomBech32AccountAddress(), validDenom), NewAdminAddress: RandomBech32AccountAddress(), }, @@ -98,7 +98,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: "failed changing admin from message: unauthorized account", }, "other denom name in 3 part name": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", tokenCreator.String(), "invalid denom"), NewAdminAddress: RandomBech32AccountAddress(), }, @@ -106,7 +106,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: fmt.Sprintf("invalid denom: factory/%s/invalid denom", tokenCreator.String()), }, "empty denom": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: "", NewAdminAddress: RandomBech32AccountAddress(), }, @@ -114,7 +114,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: "invalid denom: ", }, "empty address": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", tokenCreator.String(), validDenom), NewAdminAddress: "", }, @@ -122,7 +122,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: "address from bech32: empty address string is not allowed", }, "creator is a different address": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", tokenCreator.String(), validDenom), NewAdminAddress: RandomBech32AccountAddress(), }, @@ -130,7 +130,7 @@ func TestChangeAdmin(t *testing.T) { expErrMsg: "failed changing admin from message: unauthorized account", }, "change to the same address": { - changeAdmin: &wasmbindings.ChangeAdmin{ + changeAdmin: &bindings.ChangeAdmin{ Denom: fmt.Sprintf("factory/%s/%s", tokenCreator.String(), validDenom), NewAdminAddress: tokenCreator.String(), }, @@ -150,12 +150,12 @@ func TestChangeAdmin(t *testing.T) { actorAmount := sdk.NewCoins(sdk.NewCoin(types.DefaultParams().DenomCreationFee[0].Denom, types.DefaultParams().DenomCreationFee[0].Amount.MulRaw(100))) fundAccount(t, ctx, osmosis, tokenCreator, actorAmount) - err := wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, tokenCreator, &wasmbindings.CreateDenom{ + err := wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, tokenCreator, &bindings.CreateDenom{ Subdenom: validDenom, }) require.NoError(t, err) - err = wasm.ChangeAdmin(osmosis.TokenFactoryKeeper, ctx, spec.actor, spec.changeAdmin) + err = wasmbinding.ChangeAdmin(osmosis.TokenFactoryKeeper, ctx, spec.actor, spec.changeAdmin) if len(spec.expErrMsg) > 0 { require.Error(t, err) actualErrMsg := err.Error() @@ -176,16 +176,16 @@ func TestMint(t *testing.T) { fundAccount(t, ctx, osmosis, creator, tokenCreationFeeAmt) // Create denoms for valid mint tests - validDenom := wasmbindings.CreateDenom{ + validDenom := bindings.CreateDenom{ Subdenom: "MOON", } - err := wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &validDenom) + err := wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &validDenom) require.NoError(t, err) - emptyDenom := wasmbindings.CreateDenom{ + emptyDenom := bindings.CreateDenom{ Subdenom: "", } - err = wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &emptyDenom) + err = wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &emptyDenom) require.NoError(t, err) validDenomStr := fmt.Sprintf("factory/%s/%s", creator.String(), validDenom.Subdenom) @@ -201,18 +201,18 @@ func TestMint(t *testing.T) { require.True(t, ok) specs := map[string]struct { - mint *wasmbindings.MintTokens + mint *bindings.MintTokens expErr bool }{ "valid mint": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: validDenomStr, Amount: amount, MintToAddress: lucky.String(), }, }, "empty sub-denom": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: emptyDenomStr, Amount: amount, MintToAddress: lucky.String(), @@ -220,7 +220,7 @@ func TestMint(t *testing.T) { expErr: false, }, "nonexistent sub-denom": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: fmt.Sprintf("factory/%s/%s", creator.String(), "SUN"), Amount: amount, MintToAddress: lucky.String(), @@ -228,7 +228,7 @@ func TestMint(t *testing.T) { expErr: true, }, "invalid sub-denom": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: "sub-denom_2", Amount: amount, MintToAddress: lucky.String(), @@ -236,7 +236,7 @@ func TestMint(t *testing.T) { expErr: true, }, "zero amount": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: validDenomStr, Amount: sdk.ZeroInt(), MintToAddress: lucky.String(), @@ -244,7 +244,7 @@ func TestMint(t *testing.T) { expErr: true, }, "negative amount": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: validDenomStr, Amount: amount.Neg(), MintToAddress: lucky.String(), @@ -252,7 +252,7 @@ func TestMint(t *testing.T) { expErr: true, }, "empty recipient": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: validDenomStr, Amount: amount, MintToAddress: "", @@ -260,7 +260,7 @@ func TestMint(t *testing.T) { expErr: true, }, "invalid recipient": { - mint: &wasmbindings.MintTokens{ + mint: &bindings.MintTokens{ Denom: validDenomStr, Amount: amount, MintToAddress: "invalid", @@ -275,7 +275,7 @@ func TestMint(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { // when - gotErr := wasm.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, spec.mint) + gotErr := wasmbinding.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, spec.mint) // then if spec.expErr { require.Error(t, gotErr) @@ -295,16 +295,16 @@ func TestBurn(t *testing.T) { fundAccount(t, ctx, osmosis, creator, tokenCreationFeeAmt) // Create denoms for valid burn tests - validDenom := wasmbindings.CreateDenom{ + validDenom := bindings.CreateDenom{ Subdenom: "MOON", } - err := wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &validDenom) + err := wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &validDenom) require.NoError(t, err) - emptyDenom := wasmbindings.CreateDenom{ + emptyDenom := bindings.CreateDenom{ Subdenom: "", } - err = wasm.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &emptyDenom) + err = wasmbinding.PerformCreateDenom(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, &emptyDenom) require.NoError(t, err) lucky := RandomAccountAddress() @@ -319,11 +319,11 @@ func TestBurn(t *testing.T) { require.True(t, ok) specs := map[string]struct { - burn *wasmbindings.BurnTokens + burn *bindings.BurnTokens expErr bool }{ "valid burn": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: validDenomStr, Amount: mintAmount, BurnFromAddress: creator.String(), @@ -331,7 +331,7 @@ func TestBurn(t *testing.T) { expErr: false, }, "non admin address": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: validDenomStr, Amount: mintAmount, BurnFromAddress: lucky.String(), @@ -339,7 +339,7 @@ func TestBurn(t *testing.T) { expErr: true, }, "empty sub-denom": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: emptyDenomStr, Amount: mintAmount, BurnFromAddress: creator.String(), @@ -347,7 +347,7 @@ func TestBurn(t *testing.T) { expErr: false, }, "invalid sub-denom": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: "sub-denom_2", Amount: mintAmount, BurnFromAddress: creator.String(), @@ -355,7 +355,7 @@ func TestBurn(t *testing.T) { expErr: true, }, "non-minted denom": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: fmt.Sprintf("factory/%s/%s", creator.String(), "SUN"), Amount: mintAmount, BurnFromAddress: creator.String(), @@ -363,7 +363,7 @@ func TestBurn(t *testing.T) { expErr: true, }, "zero amount": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: validDenomStr, Amount: sdk.ZeroInt(), BurnFromAddress: creator.String(), @@ -375,7 +375,7 @@ func TestBurn(t *testing.T) { expErr: true, }, "null burn": { - burn: &wasmbindings.BurnTokens{ + burn: &bindings.BurnTokens{ Denom: validDenomStr, Amount: mintAmount.Neg(), BurnFromAddress: creator.String(), @@ -387,24 +387,24 @@ func TestBurn(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { // Mint valid denom str and empty denom string for burn test - mintBinding := &wasmbindings.MintTokens{ + mintBinding := &bindings.MintTokens{ Denom: validDenomStr, Amount: mintAmount, MintToAddress: creator.String(), } - err := wasm.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, mintBinding) + err := wasmbinding.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, mintBinding) require.NoError(t, err) - emptyDenomMintBinding := &wasmbindings.MintTokens{ + emptyDenomMintBinding := &bindings.MintTokens{ Denom: emptyDenomStr, Amount: mintAmount, MintToAddress: creator.String(), } - err = wasm.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, emptyDenomMintBinding) + err = wasmbinding.PerformMint(osmosis.TokenFactoryKeeper, osmosis.BankKeeper, ctx, creator, emptyDenomMintBinding) require.NoError(t, err) // when - gotErr := wasm.PerformBurn(osmosis.TokenFactoryKeeper, ctx, creator, spec.burn) + gotErr := wasmbinding.PerformBurn(osmosis.TokenFactoryKeeper, ctx, creator, spec.burn) // then if spec.expErr { require.Error(t, gotErr) @@ -434,7 +434,7 @@ func TestSwap(t *testing.T) { ustar := poolFunds[1].Amount.ToDec().MustFloat64() swapRate := ustar / uosmo - amountIn := wasmbindings.ExactIn{ + amountIn := bindings.ExactIn{ Input: sdk.NewInt(10000), MinOutput: sdk.OneInt(), } @@ -443,7 +443,7 @@ func TestSwap(t *testing.T) { negativeAmountIn := amountIn negativeAmountIn.Input = negativeAmountIn.Input.Neg() - amountOut := wasmbindings.ExactOut{ + amountOut := bindings.ExactOut{ MaxInput: sdk.NewInt(math.MaxInt64), Output: sdk.NewInt(10000), } @@ -455,106 +455,106 @@ func TestSwap(t *testing.T) { amount := amountIn.Input.ToDec().MustFloat64() starAmount := sdk.NewInt(int64(amount * swapRate)) - starSwapAmount := wasmbindings.SwapAmount{Out: &starAmount} + starSwapAmount := bindings.SwapAmount{Out: &starAmount} specs := map[string]struct { - swap *wasmbindings.SwapMsg - expCost *wasmbindings.SwapAmount + swap *bindings.SwapMsg + expCost *bindings.SwapAmount expErr bool }{ "valid swap (exact in)": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expCost: &starSwapAmount, }, "non-existent pool id": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool + 4, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "zero pool id": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: 0, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "invalid denom in": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "invalid", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "empty denom in": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "invalid denom out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "invalid", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "empty denom out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, @@ -565,68 +565,68 @@ func TestSwap(t *testing.T) { expErr: true, }, "empty swap amount": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{}, + Amount: bindings.SwapAmountWithLimit{}, }, expErr: true, }, "zero amount in": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &zeroAmountIn, }, }, expErr: true, }, "zero amount out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactOut: &zeroAmountOut, }, }, expErr: true, }, "negative amount in": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &negativeAmountIn, }, }, expErr: true, }, "negative amount out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactOut: &negativeAmountOut, }, }, @@ -636,7 +636,7 @@ func TestSwap(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { // when - gotAmount, gotErr := wasm.PerformSwap(osmosis.GAMMKeeper, ctx, actor, spec.swap) + gotAmount, gotErr := wasmbinding.PerformSwap(osmosis.GAMMKeeper, ctx, actor, spec.swap) // then if spec.expErr { require.Error(t, gotErr) @@ -669,7 +669,7 @@ func TestSwapMultiHop(t *testing.T) { } atomPool := preparePool(t, ctx, osmosis, actor, poolFunds2) - amountIn := wasmbindings.ExactIn{ + amountIn := bindings.ExactIn{ Input: sdk.NewInt(1_000_000), MinOutput: sdk.NewInt(20_000), } @@ -686,127 +686,127 @@ func TestSwapMultiHop(t *testing.T) { expectedOut2 := uatom2 - uosmo2*uatom2/(uosmo2+expectedOut1) atomAmount := sdk.NewInt(int64(expectedOut2)) - atomSwapAmount := wasmbindings.SwapAmount{Out: &atomAmount} + atomSwapAmount := bindings.SwapAmount{Out: &atomAmount} specs := map[string]struct { - swap *wasmbindings.SwapMsg - expCost *wasmbindings.SwapAmount + swap *bindings.SwapMsg + expCost *bindings.SwapAmount expErr bool }{ "valid swap (exact in, 2 step multi-hop)": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool, DenomOut: "uatom", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expCost: &atomSwapAmount, }, "non-existent step pool id": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool + 2, DenomOut: "uatom", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "zero step pool id": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: 0, DenomOut: "uatom", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "wrong step denom out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool, DenomOut: "ATOM", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "self-swap not allowed": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool, DenomOut: "uosmo", // this is same as the input (output of first swap) }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "invalid step denom out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool, DenomOut: "invalid", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, expErr: true, }, "empty step denom out": { - swap: &wasmbindings.SwapMsg{ - First: wasmbindings.Swap{ + swap: &bindings.SwapMsg{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "uosmo", }, - Route: []wasmbindings.Step{{ + Route: []bindings.Step{{ PoolId: atomPool, DenomOut: "", }}, - Amount: wasmbindings.SwapAmountWithLimit{ + Amount: bindings.SwapAmountWithLimit{ ExactIn: &amountIn, }, }, @@ -818,7 +818,7 @@ func TestSwapMultiHop(t *testing.T) { // use scratch context to avoid interference between tests subCtx, _ := ctx.CacheContext() // when - gotAmount, gotErr := wasm.PerformSwap(osmosis.GAMMKeeper, subCtx, actor, spec.swap) + gotAmount, gotErr := wasmbinding.PerformSwap(osmosis.GAMMKeeper, subCtx, actor, spec.swap) // then if spec.expErr { require.Error(t, gotErr) diff --git a/app/wasm/test/queries_test.go b/wasmbinding/test/queries_test.go similarity index 78% rename from app/wasm/test/queries_test.go rename to wasmbinding/test/queries_test.go index d3e82c644af..b87bcefef92 100644 --- a/app/wasm/test/queries_test.go +++ b/wasmbinding/test/queries_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "fmt" @@ -9,8 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v7/app/wasm" - wasmbindings "github.com/osmosis-labs/osmosis/v7/app/wasm/bindings" + "github.com/osmosis-labs/osmosis/v7/wasmbinding" + "github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings" ) func TestFullDenom(t *testing.T) { @@ -51,7 +51,7 @@ func TestFullDenom(t *testing.T) { for name, spec := range specs { t.Run(name, func(t *testing.T) { // when - gotFullDenom, gotErr := wasm.GetFullDenom(spec.addr, spec.subdenom) + gotFullDenom, gotErr := wasmbinding.GetFullDenom(spec.addr, spec.subdenom) // then if spec.expErr { require.Error(t, gotErr) @@ -78,7 +78,7 @@ func TestDenomAdmin(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, tfDenom) - queryPlugin := wasm.NewQueryPlugin(app.GAMMKeeper, app.TokenFactoryKeeper) + queryPlugin := wasmbinding.NewQueryPlugin(app.GAMMKeeper, app.TokenFactoryKeeper) testCases := []struct { name string @@ -132,16 +132,16 @@ func TestPoolState(t *testing.T) { starSharesDenom := fmt.Sprintf("gamm/pool/%d", starPool) starSharedAmount, _ := sdk.NewIntFromString("100_000_000_000_000_000_000") - queryPlugin := wasm.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) + queryPlugin := wasmbinding.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) specs := map[string]struct { poolId uint64 - expPoolState *wasmbindings.PoolAssets + expPoolState *bindings.PoolAssets expErr bool }{ "existent pool id": { poolId: starPool, - expPoolState: &wasmbindings.PoolAssets{ + expPoolState: &bindings.PoolAssets{ Assets: poolFunds, Shares: sdk.NewCoin(starSharesDenom, starSharedAmount), }, @@ -192,16 +192,16 @@ func TestSpotPrice(t *testing.T) { starFee := sdk.MustNewDecFromStr(fmt.Sprintf("%f", swapFee)) starPriceWithFee := starPrice.Add(starFee) - queryPlugin := wasm.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) + queryPlugin := wasmbinding.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) specs := map[string]struct { - spotPrice *wasmbindings.SpotPrice + spotPrice *bindings.SpotPrice expPrice *sdk.Dec expErr bool }{ "valid spot price": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", @@ -211,8 +211,8 @@ func TestSpotPrice(t *testing.T) { expPrice: &starPrice, }, "valid spot price with fee": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", @@ -222,8 +222,8 @@ func TestSpotPrice(t *testing.T) { expPrice: &starPriceWithFee, }, "non-existent pool id": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool + 2, DenomIn: "uosmo", DenomOut: "ustar", @@ -233,8 +233,8 @@ func TestSpotPrice(t *testing.T) { expErr: true, }, "zero pool id": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: 0, DenomIn: "uosmo", DenomOut: "ustar", @@ -244,8 +244,8 @@ func TestSpotPrice(t *testing.T) { expErr: true, }, "invalid denom in": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "invalid", DenomOut: "ustar", @@ -255,8 +255,8 @@ func TestSpotPrice(t *testing.T) { expErr: true, }, "empty denom in": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "", DenomOut: "ustar", @@ -266,8 +266,8 @@ func TestSpotPrice(t *testing.T) { expErr: true, }, "invalid denom out": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "invalid", @@ -277,8 +277,8 @@ func TestSpotPrice(t *testing.T) { expErr: true, }, "empty denom out": { - spotPrice: &wasmbindings.SpotPrice{ - Swap: wasmbindings.Swap{ + spotPrice: &bindings.SpotPrice{ + Swap: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "", @@ -333,115 +333,115 @@ func TestEstimateSwap(t *testing.T) { amount := amountIn.ToDec().MustFloat64() starAmount := sdk.NewInt(int64(amount * swapRate)) - starSwapAmount := wasmbindings.SwapAmount{Out: &starAmount} + starSwapAmount := bindings.SwapAmount{Out: &starAmount} - queryPlugin := wasm.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) + queryPlugin := wasmbinding.NewQueryPlugin(osmosis.GAMMKeeper, osmosis.TokenFactoryKeeper) specs := map[string]struct { - estimateSwap *wasmbindings.EstimateSwap - expCost *wasmbindings.SwapAmount + estimateSwap *bindings.EstimateSwap + expCost *bindings.SwapAmount expErr bool }{ "valid estimate swap (exact in)": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expCost: &starSwapAmount, }, "non-existent pool id": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool + 3, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expErr: true, }, "zero pool id": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: 0, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expErr: true, }, "invalid denom in": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "invalid", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expErr: true, }, "empty denom in": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expErr: true, }, "invalid denom out": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "invalid", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, expErr: true, }, "empty denom out": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "ustar", DenomOut: "", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &amountIn, }, }, @@ -452,73 +452,73 @@ func TestEstimateSwap(t *testing.T) { expErr: true, }, "empty swap amount": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{}, + Amount: bindings.SwapAmount{}, }, expErr: true, }, "zero amount in": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &zeroAmount, }, }, expErr: true, }, "zero amount out": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ Out: &zeroAmount, }, }, expErr: true, }, "negative amount in": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ In: &negativeAmount, }, }, expErr: true, }, "negative amount out": { - estimateSwap: &wasmbindings.EstimateSwap{ + estimateSwap: &bindings.EstimateSwap{ Sender: actor.String(), - First: wasmbindings.Swap{ + First: bindings.Swap{ PoolId: starPool, DenomIn: "uosmo", DenomOut: "ustar", }, Route: nil, - Amount: wasmbindings.SwapAmount{ + Amount: bindings.SwapAmount{ Out: &negativeAmount, }, }, diff --git a/app/wasm/test/store_run_test.go b/wasmbinding/test/store_run_test.go similarity index 99% rename from app/wasm/test/store_run_test.go rename to wasmbinding/test/store_run_test.go index 92c44d385f7..9a6059183b2 100644 --- a/app/wasm/test/store_run_test.go +++ b/wasmbinding/test/store_run_test.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "encoding/json" diff --git a/app/wasm/testdata/download_releases.sh b/wasmbinding/testdata/download_releases.sh similarity index 100% rename from app/wasm/testdata/download_releases.sh rename to wasmbinding/testdata/download_releases.sh diff --git a/app/wasm/testdata/hackatom.wasm b/wasmbinding/testdata/hackatom.wasm similarity index 100% rename from app/wasm/testdata/hackatom.wasm rename to wasmbinding/testdata/hackatom.wasm diff --git a/app/wasm/testdata/osmo_reflect.wasm b/wasmbinding/testdata/osmo_reflect.wasm similarity index 100% rename from app/wasm/testdata/osmo_reflect.wasm rename to wasmbinding/testdata/osmo_reflect.wasm diff --git a/app/wasm/testdata/reflect.wasm b/wasmbinding/testdata/reflect.wasm similarity index 100% rename from app/wasm/testdata/reflect.wasm rename to wasmbinding/testdata/reflect.wasm diff --git a/app/wasm/testdata/version.txt b/wasmbinding/testdata/version.txt similarity index 100% rename from app/wasm/testdata/version.txt rename to wasmbinding/testdata/version.txt diff --git a/app/wasm/wasm.go b/wasmbinding/wasm.go similarity index 97% rename from app/wasm/wasm.go rename to wasmbinding/wasm.go index 01009777029..af3fdd55bd2 100644 --- a/app/wasm/wasm.go +++ b/wasmbinding/wasm.go @@ -1,4 +1,4 @@ -package wasm +package wasmbinding import ( "github.com/CosmWasm/wasmd/x/wasm"