Skip to content

Commit

Permalink
Adjust to type changes and renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Feb 6, 2024
1 parent c4adc1b commit b8f1405
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 94 deletions.
4 changes: 1 addition & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"sort"
"strings"
"sync"

abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -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]),
Expand All @@ -646,7 +644,7 @@ func NewWasmApp(
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
availableCapabilities,
AllCapabilities(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
wasmOpts...,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/reflect_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/ibc_reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
8 changes: 4 additions & 4 deletions x/wasm/keeper/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion x/wasm/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions x/wasm/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
}},
Expand All @@ -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"},
Expand All @@ -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"}},
}, {
Expand All @@ -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: ""}},
}},
Expand All @@ -116,28 +116,28 @@ 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",
sdk.NewAttribute("_contract_address", myContract.String()),
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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"}},
}},
Expand All @@ -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": {
Expand Down
20 changes: 10 additions & 10 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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)
}
Expand All @@ -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,
}
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand Down
16 changes: 8 additions & 8 deletions x/wasm/keeper/handler_plugin_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
Loading

0 comments on commit b8f1405

Please sign in to comment.