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

Bump cosmwasm to v0.14.x #465

Merged
merged 18 commits into from
Apr 26, 2021
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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ RUN apk add git
WORKDIR /code
COPY . /code/

# See https://github.com/terra-project/go-cosmwasm/releases
ADD https://github.com/terra-project/go-cosmwasm/releases/download/v0.10.4/libgo_cosmwasm_muslc.a /lib/libgo_cosmwasm_muslc.a
RUN sha256sum /lib/libgo_cosmwasm_muslc.a | grep 2aa7b034b9340fecaa928adf3e8c093893fd6a3986a569ce7cae7528845a0951
# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v0.14.0-beta3/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep adea8f977601daa8daa9885e02b31ca6dd0ab6d4dbbd8ba2ccfa447ffebda37c

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc make update-swagger-docs build
Expand Down
13 changes: 8 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,12 @@ func NewTerraApp(
appCodec, keys[msgauthtypes.StoreKey], bApp.Router(),
)
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec, keys[wasmtypes.StoreKey], app.GetSubspace(wasmtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.TreasuryKeeper, bApp.Router(),
wasmtypes.DefaultFeatures, homePath, wasmConfig,
appCodec, keys[wasmtypes.StoreKey],
app.GetSubspace(wasmtypes.ModuleName),
app.AccountKeeper, app.BankKeeper,
app.TreasuryKeeper, bApp.Router(),
app.GRPCQueryRouter(), wasmtypes.DefaultFeatures,
homePath, wasmConfig,
)

// register wasm msg parser & querier
Expand All @@ -388,15 +391,15 @@ func NewTerraApp(
wasmtypes.WasmMsgParserRouteStaking: stakingwasm.NewWasmMsgParser(),
wasmtypes.WasmMsgParserRouteMarket: marketwasm.NewWasmMsgParser(),
wasmtypes.WasmMsgParserRouteWasm: wasmkeeper.NewWasmMsgParser(),
})
}, wasmkeeper.NewStargateWasmMsgParser(appCodec))
app.WasmKeeper.RegisterQueriers(map[string]wasmtypes.WasmQuerierInterface{
wasmtypes.WasmQueryRouteBank: bankwasm.NewWasmQuerier(app.BankKeeper),
wasmtypes.WasmQueryRouteStaking: stakingwasm.NewWasmQuerier(app.StakingKeeper, app.DistrKeeper),
wasmtypes.WasmQueryRouteMarket: marketwasm.NewWasmQuerier(app.MarketKeeper),
wasmtypes.WasmQueryRouteOracle: oraclewasm.NewWasmQuerier(app.OracleKeeper),
wasmtypes.WasmQueryRouteTreasury: treasurywasm.NewWasmQuerier(app.TreasuryKeeper),
wasmtypes.WasmQueryRouteWasm: wasmkeeper.NewWasmQuerier(app.WasmKeeper),
})
}, wasmkeeper.NewStargateWasmQuerier(app.WasmKeeper))

// register the proposal types
govRouter := govtypes.NewRouter()
Expand Down
63 changes: 62 additions & 1 deletion client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27478,6 +27478,22 @@ paths:
max_contract_msg_size:
type: string
format: uint64
max_contract_data_size:
type: string
format: uint64
event_params:
type: object
properties:
max_attribute_num:
type: string
format: uint64
max_attribute_key_length:
type: string
format: uint64
max_attribute_value_length:
type: string
format: uint64
title: EventParams defines the event related parameteres
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -54119,6 +54135,19 @@ definitions:
format: boolean
title: Migratable is the flag to specify the contract migratability
title: ContractInfo stores a WASM contract instance
terra.wasm.v1beta1.EventParams:
type: object
properties:
max_attribute_num:
type: string
format: uint64
max_attribute_key_length:
type: string
format: uint64
max_attribute_value_length:
type: string
format: uint64
title: EventParams defines the event related parameteres
terra.wasm.v1beta1.Params:
type: object
properties:
Expand All @@ -54131,7 +54160,23 @@ definitions:
max_contract_msg_size:
type: string
format: uint64
description: Params defines the parameters for the oracle module.
max_contract_data_size:
type: string
format: uint64
event_params:
type: object
properties:
max_attribute_num:
type: string
format: uint64
max_attribute_key_length:
type: string
format: uint64
max_attribute_value_length:
type: string
format: uint64
title: EventParams defines the event related parameteres
description: Params defines the parameters for the wasm module.
terra.wasm.v1beta1.QueryByteCodeResponse:
type: object
properties:
Expand Down Expand Up @@ -54214,6 +54259,22 @@ definitions:
max_contract_msg_size:
type: string
format: uint64
max_contract_data_size:
type: string
format: uint64
event_params:
type: object
properties:
max_attribute_num:
type: string
format: uint64
max_attribute_key_length:
type: string
format: uint64
max_attribute_value_length:
type: string
format: uint64
title: EventParams defines the event related parameteres
description: QueryParamsResponse is the response type for the Query/Params RPC method.
terra.wasm.v1beta1.QueryRawStoreResponse:
type: object
Expand Down
8 changes: 4 additions & 4 deletions cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"path/filepath"

"github.com/spf13/viper"

"github.com/spf13/cast"
"github.com/spf13/cobra"
tmcli "github.com/tendermint/tendermint/libs/cli"
Expand Down Expand Up @@ -132,6 +130,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
}
func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
wasmconfig.AddModuleInitFlags(startCmd)
}

func queryCommand() *cobra.Command {
Expand Down Expand Up @@ -220,8 +219,9 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
terraapp.MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd.
appOpts,
&wasmconfig.Config{BaseConfig: wasmconfig.BaseConfig{
ContractQueryGasLimit: viper.GetUint64(wasmconfig.FlagContractQueryGasLimit),
ContractLoggingWhitelist: viper.GetString(wasmconfig.FlagContractLoggingWhitelist),
ContractQueryGasLimit: cast.ToUint64(appOpts.Get(wasmconfig.FlagContractQueryGasLimit)),
ContractDebugMode: cast.ToBool(appOpts.Get(wasmconfig.FlagContractDebugMode)),
ContractMemoryCacheSize: cast.ToUint32(appOpts.Get(wasmconfig.FlagContractMemoryCacheSize)),
}},
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
Expand Down
30 changes: 10 additions & 20 deletions custom/bank/wasm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"

wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"

wasm "github.com/terra-project/core/x/wasm/exported"
)
Expand All @@ -25,7 +25,7 @@ func NewWasmMsgParser() WasmMsgParser {
}

// Parse implements wasm staking msg parser
func (WasmMsgParser) Parse(contractAddr sdk.AccAddress, wasmMsg wasmTypes.CosmosMsg) ([]sdk.Msg, error) {
func (WasmMsgParser) Parse(contractAddr sdk.AccAddress, wasmMsg wasmvmtypes.CosmosMsg) (sdk.Msg, error) {
msg := wasmMsg.Bank

if msg.Send == nil {
Expand All @@ -36,12 +36,7 @@ func (WasmMsgParser) Parse(contractAddr sdk.AccAddress, wasmMsg wasmTypes.Cosmos
return nil, nil
}

_, stderr := sdk.AccAddressFromBech32(msg.Send.FromAddress)
if stderr != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Send.FromAddress)
}

_, stderr = sdk.AccAddressFromBech32(msg.Send.ToAddress)
toAddr, stderr := sdk.AccAddressFromBech32(msg.Send.ToAddress)
if stderr != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Send.ToAddress)
}
Expand All @@ -51,17 +46,12 @@ func (WasmMsgParser) Parse(contractAddr sdk.AccAddress, wasmMsg wasmTypes.Cosmos
return nil, err
}

sdkMsg := types.MsgSend{
FromAddress: msg.Send.FromAddress,
ToAddress: msg.Send.ToAddress,
Amount: amount,
}

return []sdk.Msg{&sdkMsg}, sdkMsg.ValidateBasic()
sdkMsg := types.NewMsgSend(contractAddr, toAddr, amount)
return sdkMsg, sdkMsg.ValidateBasic()
}

// ParseCustom implements custom parser
func (WasmMsgParser) ParseCustom(_ sdk.AccAddress, _ json.RawMessage) ([]sdk.Msg, error) {
func (WasmMsgParser) ParseCustom(_ sdk.AccAddress, _ json.RawMessage) (sdk.Msg, error) {
return nil, nil
}

Expand All @@ -76,14 +66,14 @@ func NewWasmQuerier(keeper keeper.Keeper) WasmQuerier {
}

// Query - implement query function
func (querier WasmQuerier) Query(ctx sdk.Context, request wasmTypes.QueryRequest) ([]byte, error) {
func (querier WasmQuerier) Query(ctx sdk.Context, request wasmvmtypes.QueryRequest) ([]byte, error) {
if request.Bank.AllBalances != nil {
addr, err := sdk.AccAddressFromBech32(request.Bank.AllBalances.Address)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, request.Bank.AllBalances.Address)
}
coins := querier.keeper.GetAllBalances(ctx, addr)
res := wasmTypes.AllBalancesResponse{
res := wasmvmtypes.AllBalancesResponse{
Amount: wasm.EncodeSdkCoins(coins),
}
return json.Marshal(res)
Expand All @@ -95,12 +85,12 @@ func (querier WasmQuerier) Query(ctx sdk.Context, request wasmTypes.QueryRequest
}

coin := querier.keeper.GetBalance(ctx, addr, request.Bank.Balance.Denom)
res := wasmTypes.BalanceResponse{
res := wasmvmtypes.BalanceResponse{
Amount: wasm.EncodeSdkCoin(coin),
}
return json.Marshal(res)
}
return nil, wasmTypes.UnsupportedRequest{Kind: "unknown BankQuery variant"}
return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown BankQuery variant"}
}

// QueryCustom implements custom query interface
Expand Down
61 changes: 29 additions & 32 deletions custom/bank/wasm/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/secp256k1"

wasmTypes "github.com/CosmWasm/go-cosmwasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"

core "github.com/terra-project/core/types"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -24,22 +26,21 @@ func TestEncoding(t *testing.T) {

cases := map[string]struct {
sender sdk.AccAddress
input wasmTypes.CosmosMsg
input wasmvmtypes.CosmosMsg
// set if valid
output []sdk.Msg
output sdk.Msg
// set if invalid
isError bool
}{
"simple send": {
sender: addrs[0],
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
FromAddress: addrs[0].String(),
ToAddress: addrs[1].String(),
Amount: []wasmTypes.Coin{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
ToAddress: addrs[1].String(),
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Denom: core.MicroLunaDenom,
Amount: "12345",
},
{
Expand All @@ -50,27 +51,24 @@ func TestEncoding(t *testing.T) {
},
},
},
output: []sdk.Msg{
&banktypes.MsgSend{
FromAddress: addrs[0].String(),
ToAddress: addrs[1].String(),
Amount: sdk.Coins{
sdk.NewInt64Coin("uatom", 12345),
sdk.NewInt64Coin("usdt", 54321),
},
output: &banktypes.MsgSend{
FromAddress: addrs[0].String(),
ToAddress: addrs[1].String(),
Amount: sdk.Coins{
sdk.NewInt64Coin(core.MicroLunaDenom, 12345),
sdk.NewInt64Coin("usdt", 54321),
},
},
},
"invalid send amount": {
sender: addrs[0],
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
FromAddress: addrs[0].String(),
ToAddress: addrs[1].String(),
Amount: []wasmTypes.Coin{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
ToAddress: addrs[1].String(),
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Denom: core.MicroLunaDenom,
Amount: "123.456",
},
},
Expand All @@ -81,14 +79,13 @@ func TestEncoding(t *testing.T) {
},
"invalid address": {
sender: addrs[0],
input: wasmTypes.CosmosMsg{
Bank: &wasmTypes.BankMsg{
Send: &wasmTypes.SendMsg{
FromAddress: addrs[0].String(),
ToAddress: invalidAddr,
Amount: []wasmTypes.Coin{
input: wasmvmtypes.CosmosMsg{
Bank: &wasmvmtypes.BankMsg{
Send: &wasmvmtypes.SendMsg{
ToAddress: invalidAddr,
Amount: []wasmvmtypes.Coin{
{
Denom: "uatom",
Denom: core.MicroLunaDenom,
Amount: "7890",
},
},
Expand Down
Loading