From b8f140588e72d9eef30c3b1ac0e7b9d2c85980ae Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 6 Feb 2024 14:12:21 +0100 Subject: [PATCH] Adjust to type changes and renamings --- app/app.go | 4 +-- tests/e2e/gov_test.go | 8 ++--- tests/e2e/reflect_helper.go | 2 +- x/wasm/ibc_reflect_test.go | 6 ++-- x/wasm/keeper/api.go | 8 ++--- x/wasm/keeper/events.go | 2 +- x/wasm/keeper/events_test.go | 30 +++++++++---------- x/wasm/keeper/handler_plugin_encoders.go | 20 ++++++------- x/wasm/keeper/handler_plugin_encoders_test.go | 16 +++++----- x/wasm/keeper/handler_plugin_test.go | 8 ++--- x/wasm/keeper/keeper.go | 2 +- x/wasm/keeper/keeper_cgo.go | 2 +- x/wasm/keeper/keeper_test.go | 10 ++++--- x/wasm/keeper/msg_dispatcher_test.go | 2 +- x/wasm/keeper/proposal_integration_test.go | 5 +++- x/wasm/keeper/query_plugins.go | 10 +++---- x/wasm/keeper/reflect_test.go | 4 +-- x/wasm/keeper/test_common.go | 6 ++-- x/wasm/keeper/wasmtesting/gas_register.go | 2 +- x/wasm/migrations/v1/store_test.go | 2 +- x/wasm/migrations/v3/store_test.go | 2 +- x/wasm/module_test.go | 2 +- x/wasm/relay_pingpong_test.go | 2 +- x/wasm/relay_test.go | 2 +- x/wasm/types/gas_register.go | 4 +-- x/wasm/types/gas_register_test.go | 2 +- x/wasm/types/types.go | 2 +- x/wasm/types/wasmer_engine.go | 14 +-------- 28 files changed, 85 insertions(+), 94 deletions(-) diff --git a/app/app.go b/app/app.go index 44934eae72..fa4789c926 100644 --- a/app/app.go +++ b/app/app.go @@ -7,7 +7,6 @@ import ( "os" "path/filepath" "sort" - "strings" "sync" abci "github.com/cometbft/cometbft/abci/types" @@ -629,7 +628,6 @@ func NewWasmApp( // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks - availableCapabilities := strings.Join(AllCapabilities(), ",") app.WasmKeeper = wasmkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), @@ -646,7 +644,7 @@ func NewWasmApp( app.GRPCQueryRouter(), wasmDir, wasmConfig, - availableCapabilities, + AllCapabilities(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmOpts..., ) diff --git a/tests/e2e/gov_test.go b/tests/e2e/gov_test.go index 431abd9578..a0abd64edf 100644 --- a/tests/e2e/gov_test.go +++ b/tests/e2e/gov_test.go @@ -61,25 +61,25 @@ func TestGovVoteByContract(t *testing.T) { }{ "yes": { vote: &wasmvmtypes.VoteMsg{ - Vote: wasmvmtypes.Yes, + Option: wasmvmtypes.Yes, }, expPass: true, }, "no": { vote: &wasmvmtypes.VoteMsg{ - Vote: wasmvmtypes.No, + Option: wasmvmtypes.No, }, expPass: false, }, "abstain": { vote: &wasmvmtypes.VoteMsg{ - Vote: wasmvmtypes.Abstain, + Option: wasmvmtypes.Abstain, }, expPass: true, }, "no with veto": { vote: &wasmvmtypes.VoteMsg{ - Vote: wasmvmtypes.NoWithVeto, + Option: wasmvmtypes.NoWithVeto, }, expPass: false, }, diff --git a/tests/e2e/reflect_helper.go b/tests/e2e/reflect_helper.go index d715eefa2f..e64d8bf139 100644 --- a/tests/e2e/reflect_helper.go +++ b/tests/e2e/reflect_helper.go @@ -42,7 +42,7 @@ func MustExecViaStargateReflectContract[T sdkMessageType](t *testing.T, chain *i bz, err := chain.Codec.Marshal(m) require.NoError(t, err) vmMsgs[i] = wasmvmtypes.CosmosMsg{ - Stargate: &wasmvmtypes.StargateMsg{ + Any: &wasmvmtypes.AnyMsg{ TypeURL: sdk.MsgTypeURL(m), Value: bz, }, diff --git a/x/wasm/ibc_reflect_test.go b/x/wasm/ibc_reflect_test.go index 64de333ad5..2d847f8f1a 100644 --- a/x/wasm/ibc_reflect_test.go +++ b/x/wasm/ibc_reflect_test.go @@ -116,7 +116,7 @@ type AccountQuery struct { } type AccountResponse struct { - LastUpdateTime uint64 `json:"last_update_time,string"` - RemoteAddr string `json:"remote_addr"` - RemoteBalance wasmvmtypes.Coins `json:"remote_balance"` + LastUpdateTime uint64 `json:"last_update_time,string"` + RemoteAddr string `json:"remote_addr"` + RemoteBalance wasmvmtypes.Array[wasmvmtypes.Coin] `json:"remote_balance"` } diff --git a/x/wasm/keeper/api.go b/x/wasm/keeper/api.go index e9d5a00d48..8101fef246 100644 --- a/x/wasm/keeper/api.go +++ b/x/wasm/keeper/api.go @@ -28,19 +28,19 @@ var ( } ) -func humanAddress(canon []byte) (string, uint64, error) { +func humanizeAddress(canon []byte) (string, uint64, error) { if err := sdk.VerifyAddressFormat(canon); err != nil { return "", costHumanize, err } return sdk.AccAddress(canon).String(), costHumanize, nil } -func canonicalAddress(human string) ([]byte, uint64, error) { +func canonicalizeAddress(human string) ([]byte, uint64, error) { bz, err := sdk.AccAddressFromBech32(human) return bz, costCanonical, err } var cosmwasmAPI = wasmvm.GoAPI{ - HumanAddress: humanAddress, - CanonicalAddress: canonicalAddress, + HumanizeAddress: humanizeAddress, + CanonicalizeAddress: canonicalizeAddress, } diff --git a/x/wasm/keeper/events.go b/x/wasm/keeper/events.go index 0fc9d57400..5cfb075b2e 100644 --- a/x/wasm/keeper/events.go +++ b/x/wasm/keeper/events.go @@ -28,7 +28,7 @@ func newWasmModuleEvent(customAttributes []wasmvmtypes.EventAttribute, contractA const eventTypeMinLength = 2 // newCustomEvents converts wasmvm events from a contract response to sdk type events -func newCustomEvents(evts wasmvmtypes.Events, contractAddr sdk.AccAddress) (sdk.Events, error) { +func newCustomEvents(evts wasmvmtypes.Array[wasmvmtypes.Event], contractAddr sdk.AccAddress) (sdk.Events, error) { events := make(sdk.Events, 0, len(evts)) for _, e := range evts { typ := strings.TrimSpace(e.Type) diff --git a/x/wasm/keeper/events_test.go b/x/wasm/keeper/events_test.go index 61182ad9c4..6516703ec5 100644 --- a/x/wasm/keeper/events_test.go +++ b/x/wasm/keeper/events_test.go @@ -56,12 +56,12 @@ func TestHasWasmModuleEvent(t *testing.T) { func TestNewCustomEvents(t *testing.T) { myContract := RandomAccountAddress(t) specs := map[string]struct { - src wasmvmtypes.Events + src wasmvmtypes.Array[wasmvmtypes.Event] exp sdk.Events isError bool }{ "all good": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: "myVal"}}, }}, @@ -70,7 +70,7 @@ func TestNewCustomEvents(t *testing.T) { sdk.NewAttribute("myKey", "myVal"))}, }, "multiple attributes": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{ {Key: "myKey", Value: "myVal"}, @@ -83,7 +83,7 @@ func TestNewCustomEvents(t *testing.T) { sdk.NewAttribute("myOtherKey", "myOtherVal"))}, }, "multiple events": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: "myVal"}}, }, { @@ -100,14 +100,14 @@ func TestNewCustomEvents(t *testing.T) { }, }, "without attributes": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", }}, exp: sdk.Events{sdk.NewEvent("wasm-foo", sdk.NewAttribute("_contract_address", myContract.String()))}, }, "empty value can be solved": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: ""}}, }}, @@ -116,7 +116,7 @@ func TestNewCustomEvents(t *testing.T) { sdk.NewAttribute("myKey", ""))}, }, "good on whitespace value": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: "\n\n\n"}}, }}, exp: sdk.Events{sdk.NewEvent("wasm-foo", @@ -124,20 +124,20 @@ func TestNewCustomEvents(t *testing.T) { sdk.NewAttribute("myKey", ""))}, }, "error on short event type": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "f", }}, isError: true, }, "error on _contract_address": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "foo", Attributes: []wasmvmtypes.EventAttribute{{Key: "_contract_address", Value: RandomBech32AccountAddress(t)}}, }}, isError: true, }, "error on reserved prefix": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "wasm", Attributes: []wasmvmtypes.EventAttribute{ {Key: "_reserved", Value: "is skipped"}, @@ -147,7 +147,7 @@ func TestNewCustomEvents(t *testing.T) { isError: true, }, "error on empty key": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "boom", Attributes: []wasmvmtypes.EventAttribute{ {Key: "some", Value: "data"}, @@ -157,7 +157,7 @@ func TestNewCustomEvents(t *testing.T) { isError: true, }, "error on whitespace type": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: " f ", Attributes: []wasmvmtypes.EventAttribute{ {Key: "some", Value: "data"}, @@ -166,7 +166,7 @@ func TestNewCustomEvents(t *testing.T) { isError: true, }, "error on only whitespace key": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: "boom", Attributes: []wasmvmtypes.EventAttribute{ {Key: "some", Value: "data"}, @@ -176,7 +176,7 @@ func TestNewCustomEvents(t *testing.T) { isError: true, }, "strip out whitespace": { - src: wasmvmtypes.Events{{ + src: wasmvmtypes.Array[wasmvmtypes.Event]{{ Type: " food\n", Attributes: []wasmvmtypes.EventAttribute{{Key: "my Key", Value: "\tmyVal"}}, }}, @@ -185,7 +185,7 @@ func TestNewCustomEvents(t *testing.T) { sdk.NewAttribute("my Key", "myVal"))}, }, "empty event elements": { - src: make(wasmvmtypes.Events, 10), + src: make(wasmvmtypes.Array[wasmvmtypes.Event], 10), isError: true, }, "nil": { diff --git a/x/wasm/keeper/handler_plugin_encoders.go b/x/wasm/keeper/handler_plugin_encoders.go index d67969bd13..91c56580e7 100644 --- a/x/wasm/keeper/handler_plugin_encoders.go +++ b/x/wasm/keeper/handler_plugin_encoders.go @@ -28,7 +28,7 @@ type ( CustomEncoder func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) DistributionEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error) StakingEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error) - StargateEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error) + AnyEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.AnyMsg) ([]sdk.Msg, error) WasmEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error) IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error) ) @@ -39,7 +39,7 @@ type MessageEncoders struct { Distribution func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error) IBC func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error) Staking func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error) - Stargate func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error) + Any func(sender sdk.AccAddress, msg *wasmvmtypes.AnyMsg) ([]sdk.Msg, error) Wasm func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error) Gov func(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, error) } @@ -51,7 +51,7 @@ func DefaultEncoders(unpacker codectypes.AnyUnpacker, portSource types.ICS20Tran Distribution: EncodeDistributionMsg, IBC: EncodeIBCMsg(portSource), Staking: EncodeStakingMsg, - Stargate: EncodeStargateMsg(unpacker), + Any: EncodeAnyMsg(unpacker), Wasm: EncodeWasmMsg, Gov: EncodeGovMsg, } @@ -76,8 +76,8 @@ func (e MessageEncoders) Merge(o *MessageEncoders) MessageEncoders { if o.Staking != nil { e.Staking = o.Staking } - if o.Stargate != nil { - e.Stargate = o.Stargate + if o.Any != nil { + e.Any = o.Any } if o.Wasm != nil { e.Wasm = o.Wasm @@ -100,8 +100,8 @@ func (e MessageEncoders) Encode(ctx sdk.Context, contractAddr sdk.AccAddress, co return e.IBC(ctx, contractAddr, contractIBCPortID, msg.IBC) case msg.Staking != nil: return e.Staking(contractAddr, msg.Staking) - case msg.Stargate != nil: - return e.Stargate(contractAddr, msg.Stargate) + case msg.Any != nil: + return e.Any(contractAddr, msg.Any) case msg.Wasm != nil: return e.Wasm(contractAddr, msg.Wasm) case msg.Gov != nil: @@ -204,8 +204,8 @@ func EncodeStakingMsg(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk } } -func EncodeStargateMsg(unpacker codectypes.AnyUnpacker) StargateEncoder { - return func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error) { +func EncodeAnyMsg(unpacker codectypes.AnyUnpacker) AnyEncoder { + return func(sender sdk.AccAddress, msg *wasmvmtypes.AnyMsg) ([]sdk.Msg, error) { codecAny := codectypes.Any{ TypeUrl: msg.TypeURL, Value: msg.Value, @@ -328,7 +328,7 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, error) { switch { case msg.Vote != nil: - voteOption, err := convertVoteOption(msg.Vote.Vote) + voteOption, err := convertVoteOption(msg.Vote.Option) if err != nil { return nil, errorsmod.Wrap(err, "vote option") } diff --git a/x/wasm/keeper/handler_plugin_encoders_test.go b/x/wasm/keeper/handler_plugin_encoders_test.go index 529f5028a0..9d29947b54 100644 --- a/x/wasm/keeper/handler_plugin_encoders_test.go +++ b/x/wasm/keeper/handler_plugin_encoders_test.go @@ -381,7 +381,7 @@ func TestEncoding(t *testing.T) { srcMsg: wasmvmtypes.CosmosMsg{ Distribution: &wasmvmtypes.DistributionMsg{ FundCommunityPool: &wasmvmtypes.FundCommunityPoolMsg{ - Amount: wasmvmtypes.Coins{ + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{ wasmvmtypes.NewCoin(200, "stones"), wasmvmtypes.NewCoin(200, "feathers"), }, @@ -401,7 +401,7 @@ func TestEncoding(t *testing.T) { "stargate encoded bank msg": { sender: addr2, srcMsg: wasmvmtypes.CosmosMsg{ - Stargate: &wasmvmtypes.StargateMsg{ + Any: &wasmvmtypes.AnyMsg{ TypeURL: "/cosmos.bank.v1beta1.MsgSend", Value: bankMsgBin, }, @@ -411,7 +411,7 @@ func TestEncoding(t *testing.T) { "stargate encoded msg with any type": { sender: addr2, srcMsg: wasmvmtypes.CosmosMsg{ - Stargate: &wasmvmtypes.StargateMsg{ + Any: &wasmvmtypes.AnyMsg{ TypeURL: "/cosmos.gov.v1.MsgSubmitProposal", Value: proposalMsgBin, }, @@ -421,7 +421,7 @@ func TestEncoding(t *testing.T) { "stargate encoded invalid typeUrl": { sender: addr2, srcMsg: wasmvmtypes.CosmosMsg{ - Stargate: &wasmvmtypes.StargateMsg{ + Any: &wasmvmtypes.AnyMsg{ TypeURL: "/cosmos.bank.v2.MsgSend", Value: bankMsgBin, }, @@ -581,7 +581,7 @@ func TestEncodeGovMsg(t *testing.T) { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ - Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Vote: wasmvmtypes.Yes}, + Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Option: wasmvmtypes.Yes}, }, }, output: []sdk.Msg{ @@ -596,7 +596,7 @@ func TestEncodeGovMsg(t *testing.T) { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ - Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Vote: wasmvmtypes.No}, + Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Option: wasmvmtypes.No}, }, }, output: []sdk.Msg{ @@ -611,7 +611,7 @@ func TestEncodeGovMsg(t *testing.T) { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ - Vote: &wasmvmtypes.VoteMsg{ProposalId: 10, Vote: wasmvmtypes.Abstain}, + Vote: &wasmvmtypes.VoteMsg{ProposalId: 10, Option: wasmvmtypes.Abstain}, }, }, output: []sdk.Msg{ @@ -626,7 +626,7 @@ func TestEncodeGovMsg(t *testing.T) { sender: myAddr, srcMsg: wasmvmtypes.CosmosMsg{ Gov: &wasmvmtypes.GovMsg{ - Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Vote: wasmvmtypes.NoWithVeto}, + Vote: &wasmvmtypes.VoteMsg{ProposalId: 1, Option: wasmvmtypes.NoWithVeto}, }, }, output: []sdk.Msg{ diff --git a/x/wasm/keeper/handler_plugin_test.go b/x/wasm/keeper/handler_plugin_test.go index b6f400f73c..b86c86fd7f 100644 --- a/x/wasm/keeper/handler_plugin_test.go +++ b/x/wasm/keeper/handler_plugin_test.go @@ -350,7 +350,7 @@ func TestBurnCoinMessageHandlerIntegration(t *testing.T) { }{ "all good": { msg: wasmvmtypes.BurnMsg{ - Amount: wasmvmtypes.Coins{{ + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{{ Denom: "denom", Amount: "100", }}, @@ -358,7 +358,7 @@ func TestBurnCoinMessageHandlerIntegration(t *testing.T) { }, "not enough funds in contract": { msg: wasmvmtypes.BurnMsg{ - Amount: wasmvmtypes.Coins{{ + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{{ Denom: "denom", Amount: "101", }}, @@ -367,7 +367,7 @@ func TestBurnCoinMessageHandlerIntegration(t *testing.T) { }, "zero amount rejected": { msg: wasmvmtypes.BurnMsg{ - Amount: wasmvmtypes.Coins{{ + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{{ Denom: "denom", Amount: "0", }}, @@ -376,7 +376,7 @@ func TestBurnCoinMessageHandlerIntegration(t *testing.T) { }, "unknown denom - insufficient funds": { msg: wasmvmtypes.BurnMsg{ - Amount: wasmvmtypes.Coins{{ + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{{ Denom: "unknown", Amount: "1", }}, diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index ccf16f677a..1e47aa66c6 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -1075,7 +1075,7 @@ func (k *Keeper) handleContractResponse( msgs []wasmvmtypes.SubMsg, attrs []wasmvmtypes.EventAttribute, data []byte, - evts wasmvmtypes.Events, + evts wasmvmtypes.Array[wasmvmtypes.Event], ) ([]byte, error) { attributeGasCost := k.gasRegister.EventCosts(attrs, evts) ctx.GasMeter().ConsumeGas(attributeGasCost, "Custom contract event attributes") diff --git a/x/wasm/keeper/keeper_cgo.go b/x/wasm/keeper/keeper_cgo.go index a2988fcc25..020fef834d 100644 --- a/x/wasm/keeper/keeper_cgo.go +++ b/x/wasm/keeper/keeper_cgo.go @@ -33,7 +33,7 @@ func NewKeeper( _ GRPCQueryRouter, homeDir string, wasmConfig types.WasmConfig, - availableCapabilities string, + availableCapabilities []string, authority string, opts ...Option, ) Keeper { diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index ec943871bd..fefed2726a 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -43,7 +43,9 @@ import ( //go:embed testdata/hackatom.wasm var hackatomWasm []byte -const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4" +var AvailableCapabilities = []string{ + "iterator", "staking", "stargate", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", +} func TestNewKeeper(t *testing.T) { _, keepers := CreateTestInput(t, false, AvailableCapabilities) @@ -1510,8 +1512,8 @@ type sudoMsg struct { } type stealFundsMsg struct { - Recipient string `json:"recipient"` - Amount wasmvmtypes.Coins `json:"amount"` + Recipient string `json:"recipient"` + Amount wasmvmtypes.Array[wasmvmtypes.Coin] `json:"amount"` } func TestSudo(t *testing.T) { @@ -1549,7 +1551,7 @@ func TestSudo(t *testing.T) { // to end users (via Tx/Execute). StealFunds: stealFundsMsg{ Recipient: community.String(), - Amount: wasmvmtypes.Coins{wasmvmtypes.NewCoin(76543, "denom")}, + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{wasmvmtypes.NewCoin(76543, "denom")}, }, } sudoMsg, err := json.Marshal(msg) diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index 94fd46b871..d9b0a9d6e8 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -348,7 +348,7 @@ func TestDispatchSubmessages(t *testing.T) { }, "non-wasm reply events get filtered": { // show events from a stargate message gets filtered out - msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyAlways, Msg: wasmvmtypes.CosmosMsg{Stargate: &wasmvmtypes.StargateMsg{}}}}, + msgs: []wasmvmtypes.SubMsg{{ID: 1, ReplyOn: wasmvmtypes.ReplyAlways, Msg: wasmvmtypes.CosmosMsg{Any: &wasmvmtypes.AnyMsg{}}}}, replyer: &mockReplyer{ replyFn: func(ctx sdk.Context, contractAddress sdk.AccAddress, reply wasmvmtypes.Reply) ([]byte, error) { if reply.Result.Err != "" { diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index b1cc8a38ea..c228424180 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -23,7 +23,10 @@ import ( ) func TestLoadStoredGovV1Beta1LegacyTypes(t *testing.T) { - pCtx, keepers := CreateTestInput(t, false, ReflectCapabilities+",iterator") + capabilities := make([]string, len(ReflectCapabilities)+1) + copy(capabilities, ReflectCapabilities) + capabilities = append(capabilities, "iterator") + pCtx, keepers := CreateTestInput(t, false, capabilities) k := keepers.WasmKeeper keepers.GovKeeper.SetLegacyRouter(v1beta1.NewRouter(). AddRoute(types.ModuleName, NewLegacyWasmProposalHandler(k, types.EnableAllProposals)), diff --git a/x/wasm/keeper/query_plugins.go b/x/wasm/keeper/query_plugins.go index 685dfc1b11..488e4d3adb 100644 --- a/x/wasm/keeper/query_plugins.go +++ b/x/wasm/keeper/query_plugins.go @@ -255,10 +255,10 @@ func IBCQuerier(wasm contractMetaDataSource, channelKeeper types.ChannelKeeper) if portID == "" { // then fallback to contract port address portID = wasm.GetContractInfo(ctx, caller).IBCPortID } - var channels wasmvmtypes.IBCChannels + var channels wasmvmtypes.Array[wasmvmtypes.IBCChannel] if portID != "" { // then return empty list for non ibc contracts; no channels possible gotChannels := channelKeeper.GetAllChannelsWithPortPrefix(ctx, portID) - channels = make(wasmvmtypes.IBCChannels, 0, len(gotChannels)) + channels = make(wasmvmtypes.Array[wasmvmtypes.IBCChannel], 0, len(gotChannels)) for _, ch := range gotChannels { if ch.State != channeltypes.OPEN { continue @@ -461,7 +461,7 @@ func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKee } } -func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations []stakingtypes.Delegation) (wasmvmtypes.Delegations, error) { +func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations []stakingtypes.Delegation) (wasmvmtypes.Array[wasmvmtypes.Delegation], error) { result := make([]wasmvmtypes.Delegation, len(delegations)) bondDenom, err := keeper.BondDenom(ctx) if err != nil { @@ -706,8 +706,8 @@ func ConvertSDKDecCoinsToWasmDecCoins(src sdk.DecCoins) []wasmvmtypes.DecCoin { } // ConvertSdkCoinsToWasmCoins covert sdk type to wasmvm coins type -func ConvertSdkCoinsToWasmCoins(coins []sdk.Coin) wasmvmtypes.Coins { - converted := make(wasmvmtypes.Coins, len(coins)) +func ConvertSdkCoinsToWasmCoins(coins []sdk.Coin) wasmvmtypes.Array[wasmvmtypes.Coin] { + converted := make(wasmvmtypes.Array[wasmvmtypes.Coin], len(coins)) for i, c := range coins { converted[i] = ConvertSdkCoinToWasmCoin(c) } diff --git a/x/wasm/keeper/reflect_test.go b/x/wasm/keeper/reflect_test.go index 53bc35a980..24581f2806 100644 --- a/x/wasm/keeper/reflect_test.go +++ b/x/wasm/keeper/reflect_test.go @@ -23,8 +23,8 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/types" ) -const ( - CyberpunkCapabilities = "staking,mask,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4" +var ( + CyberpunkCapabilities = []string{"staking", "mask", "stargate", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4"} ReflectCapabilities = CyberpunkCapabilities ) diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index a6809702ac..15a6aa8942 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -197,11 +197,11 @@ type TestKeepers struct { // CreateDefaultTestInput common settings for CreateTestInput func CreateDefaultTestInput(t testing.TB) (sdk.Context, TestKeepers) { - return CreateTestInput(t, false, "staking") + return CreateTestInput(t, false, []string{"staking"}) } // CreateTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) -func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { +func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities []string, opts ...Option) (sdk.Context, TestKeepers) { // Load default wasm config return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) } @@ -210,7 +210,7 @@ func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities string, func createTestInput( t testing.TB, isCheckTx bool, - availableCapabilities string, + availableCapabilities []string, wasmConfig types.WasmConfig, db dbm.DB, opts ...Option, diff --git a/x/wasm/keeper/wasmtesting/gas_register.go b/x/wasm/keeper/wasmtesting/gas_register.go index 9358b8a65c..77c176e4ea 100644 --- a/x/wasm/keeper/wasmtesting/gas_register.go +++ b/x/wasm/keeper/wasmtesting/gas_register.go @@ -45,7 +45,7 @@ func (m MockGasRegister) ReplyCosts(discount bool, reply wasmvmtypes.Reply) stor return m.ReplyCostFn(discount, reply) } -func (m MockGasRegister) EventCosts(evts []wasmvmtypes.EventAttribute, _ wasmvmtypes.Events) storetypes.Gas { +func (m MockGasRegister) EventCosts(evts []wasmvmtypes.EventAttribute, _ wasmvmtypes.Array[wasmvmtypes.Event]) storetypes.Gas { if m.EventCostsFn == nil { panic("not expected to be called") } diff --git a/x/wasm/migrations/v1/store_test.go b/x/wasm/migrations/v1/store_test.go index 7afec80b59..4e57da1ee2 100644 --- a/x/wasm/migrations/v1/store_test.go +++ b/x/wasm/migrations/v1/store_test.go @@ -15,7 +15,7 @@ import ( ) func TestMigrate1To2(t *testing.T) { - const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1" + var AvailableCapabilities = []string{"iterator", "staking", "stargate", "cosmwasm_1_1"} ctx, keepers := keeper.CreateTestInput(t, false, AvailableCapabilities) wasmKeeper := keepers.WasmKeeper diff --git a/x/wasm/migrations/v3/store_test.go b/x/wasm/migrations/v3/store_test.go index 0bd217d299..4f7100f67b 100644 --- a/x/wasm/migrations/v3/store_test.go +++ b/x/wasm/migrations/v3/store_test.go @@ -19,7 +19,7 @@ import ( ) func TestMigrate3To4(t *testing.T) { - const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1" + var AvailableCapabilities = []string{"iterator", "staking", "stargate", "cosmwasm_1_1"} ctx, keepers := keeper.CreateTestInput(t, false, AvailableCapabilities) store := ctx.KVStore(keepers.WasmStoreKey) cdc := moduletestutil.MakeTestEncodingConfig(wasm.AppModuleBasic{}).Codec diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index c08ab1455e..63e8f5cd90 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -63,7 +63,7 @@ func setupTest(t *testing.T) testData { InstantiateDefaultPermission: v2.AccessTypeEverybody, } - ctx, keepers := keeper.CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4") + ctx, keepers := keeper.CreateTestInput(t, false, []string{"iterator", "staking", "stargate", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4"}) encConf := keeper.MakeEncodingConfig(t) queryRouter := baseapp.NewGRPCQueryRouter() serviceRouter := baseapp.NewMsgServiceRouter() diff --git a/x/wasm/relay_pingpong_test.go b/x/wasm/relay_pingpong_test.go index 4fcf8926d5..ce5635a8ed 100644 --- a/x/wasm/relay_pingpong_test.go +++ b/x/wasm/relay_pingpong_test.go @@ -262,7 +262,7 @@ func (p player) IBCPacketReceive(_ wasmvm.Checksum, _ wasmvmtypes.Env, msg wasmv return &wasmvmtypes.IBCReceiveResult{ Ok: &wasmvmtypes.IBCReceiveResponse{ - Attributes: wasmvmtypes.EventAttributes{ + Attributes: wasmvmtypes.Array[wasmvmtypes.EventAttribute]{ {Key: "empty-value-test"}, }, Acknowledgement: receivedBall.BuildAck().GetBytes(), diff --git a/x/wasm/relay_test.go b/x/wasm/relay_test.go index e30b276bdc..e461c10739 100644 --- a/x/wasm/relay_test.go +++ b/x/wasm/relay_test.go @@ -634,7 +634,7 @@ func (s *sendEmulatedIBCTransferContract) IBCPacketTimeout(_ wasmvm.Checksum, _ returnTokens := &wasmvmtypes.BankMsg{ Send: &wasmvmtypes.SendMsg{ ToAddress: data.Sender, - Amount: wasmvmtypes.Coins{wasmvmtypes.NewCoin(amount.Uint64(), data.Denom)}, + Amount: wasmvmtypes.Array[wasmvmtypes.Coin]{wasmvmtypes.NewCoin(amount.Uint64(), data.Denom)}, }, } diff --git a/x/wasm/types/gas_register.go b/x/wasm/types/gas_register.go index f77d3c854e..15e9058b1e 100644 --- a/x/wasm/types/gas_register.go +++ b/x/wasm/types/gas_register.go @@ -84,7 +84,7 @@ type GasRegister interface { // ReplyCosts costs to to handle a message reply ReplyCosts(discount bool, reply wasmvmtypes.Reply) storetypes.Gas // EventCosts costs to persist an event - EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Events) storetypes.Gas + EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Array[wasmvmtypes.Event]) storetypes.Gas // ToWasmVMGas converts from Cosmos SDK gas units to [CosmWasm gas] (aka. wasmvm gas) // // [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md @@ -216,7 +216,7 @@ func (g WasmGasRegister) ReplyCosts(discount bool, reply wasmvmtypes.Reply) stor } // EventCosts costs to persist an event -func (g WasmGasRegister) EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Events) storetypes.Gas { +func (g WasmGasRegister) EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Array[wasmvmtypes.Event]) storetypes.Gas { gas, remainingFreeTier := g.eventAttributeCosts(attrs, g.c.EventAttributeDataFreeTier) for _, e := range events { gas += g.c.CustomEventCost diff --git a/x/wasm/types/gas_register_test.go b/x/wasm/types/gas_register_test.go index d8612ccfd7..d530fa02ec 100644 --- a/x/wasm/types/gas_register_test.go +++ b/x/wasm/types/gas_register_test.go @@ -258,7 +258,7 @@ func TestEventCosts(t *testing.T) { // most cases are covered in TestReplyCost already. This ensures some edge cases specs := map[string]struct { srcAttrs []wasmvmtypes.EventAttribute - srcEvents wasmvmtypes.Events + srcEvents wasmvmtypes.Array[wasmvmtypes.Event] expGas storetypes.Gas }{ "empty events": { diff --git a/x/wasm/types/types.go b/x/wasm/types/types.go index e59ae1f8a3..4b2a83e0d9 100644 --- a/x/wasm/types/types.go +++ b/x/wasm/types/types.go @@ -281,7 +281,7 @@ func NewEnv(ctx sdk.Context, contractAddr sdk.AccAddress) wasmvmtypes.Env { env := wasmvmtypes.Env{ Block: wasmvmtypes.BlockInfo{ Height: uint64(ctx.BlockHeight()), - Time: uint64(nano), + Time: wasmvmtypes.Uint64(nano), ChainID: ctx.ChainID(), }, Contract: wasmvmtypes.ContractInfo{ diff --git a/x/wasm/types/wasmer_engine.go b/x/wasm/types/wasmer_engine.go index 85f6b2408a..fe5e06fa2b 100644 --- a/x/wasm/types/wasmer_engine.go +++ b/x/wasm/types/wasmer_engine.go @@ -12,22 +12,10 @@ const DefaultMaxQueryStackSize uint32 = 10 // WasmEngine defines the WASM contract runtime engine. type WasmEngine interface { - // Create will compile the wasm code, and store the resulting pre-compile - // as well as the original code. Both can be referenced later via CodeID - // This must be done one time for given code, after which it can be - // instatitated many times, and each instance called many times. - // - // For example, the code for all ERC-20 contracts should be the same. - // This function stores the code for that contract only once, but it can - // be instantiated with custom inputs in the future. - // - // Deprecated: use StoreCode instead. - Create(code wasmvm.WasmCode) (wasmvm.Checksum, error) - // Create will compile the wasm code, and store the resulting pre-compile // as well as the original code. Both can be referenced later via checksum // This must be done one time for given code, after which it can be - // instatitated many times, and each instance called many times. + // instantiated many times, and each instance called many times. // It does the same as StoreCodeUnchecked plus the static checks. StoreCode(code wasmvm.WasmCode) (wasmvm.Checksum, error)