diff --git a/CHANGELOG.md b/CHANGELOG.md index f1765bd669..1c2d87f40d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [\#8](https://github.com/line/wasmd/pull/8) Bump line/lbm-sdk to a7557b1d10 ### Bug Fixes +* [\#12](https://github.com/line/wasmd/pull/12) fix not to register wrong codec in `x/wasmplus` ### Breaking Changes diff --git a/x/wasmplus/types/codec.go b/x/wasmplus/types/codec.go index 71237b391b..9e3073be6f 100644 --- a/x/wasmplus/types/codec.go +++ b/x/wasmplus/types/codec.go @@ -16,7 +16,7 @@ import ( // RegisterLegacyAminoCodec registers the account types and interface func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { //nolint:staticcheck - legacy.RegisterAminoMsg(cdc, &MsgStoreCodeAndInstantiateContract{}, "wasm/StoreCodeAndInstantiateContract") + legacy.RegisterAminoMsg(cdc, &MsgStoreCodeAndInstantiateContract{}, "wasm/MsgStoreCodeAndInstantiateContract") cdc.RegisterConcrete(&DeactivateContractProposal{}, "wasm/DeactivateContractProposal", nil) cdc.RegisterConcrete(&ActivateContractProposal{}, "wasm/ActivateContractProposal", nil) diff --git a/x/wasmplus/types/tx.go b/x/wasmplus/types/tx.go index 7589343343..7d425b342b 100644 --- a/x/wasmplus/types/tx.go +++ b/x/wasmplus/types/tx.go @@ -3,12 +3,10 @@ package types import ( sdk "github.com/line/lbm-sdk/types" sdkerrors "github.com/line/lbm-sdk/types/errors" - - wasmtypes "github.com/line/wasmd/x/wasm/types" ) func (msg MsgStoreCodeAndInstantiateContract) Route() string { - return wasmtypes.RouterKey + return RouterKey } func (msg MsgStoreCodeAndInstantiateContract) Type() string { @@ -51,7 +49,7 @@ func (msg MsgStoreCodeAndInstantiateContract) ValidateBasic() error { } func (msg MsgStoreCodeAndInstantiateContract) GetSignBytes() []byte { - return sdk.MustSortJSON(wasmtypes.ModuleCdc.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } func (msg MsgStoreCodeAndInstantiateContract) GetSigners() []sdk.AccAddress { diff --git a/x/wasmplus/types/tx_test.go b/x/wasmplus/types/tx_test.go index 6b00495595..c7f1c134a1 100644 --- a/x/wasmplus/types/tx_test.go +++ b/x/wasmplus/types/tx_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/line/lbm-sdk/types" + "github.com/line/lbm-sdk/x/auth/legacy/legacytx" wasmTypes "github.com/line/wasmd/x/wasm/types" ) @@ -135,3 +136,37 @@ func TestNewMsgStoreCodeAndInstantiateContractGetSigners(t *testing.T) { bytes := sdk.MustAccAddressFromBech32(res[0].String()) require.Equal(t, "696e707574313131313131313131313131313131", fmt.Sprintf("%v", hex.EncodeToString(bytes))) } + +func TestMsgJsonSignBytes(t *testing.T) { + const myInnerMsg = `{"foo":"bar"}` + specs := map[string]struct { + src legacytx.LegacyMsg + exp string + }{ + "MsgInstantiateContract with every field": { + src: &MsgStoreCodeAndInstantiateContract{Sender: "sender1", WASMByteCode: []byte{89, 69, 76, 76, 79, 87, 32, 83, 85, 66, 77, 65, 82, 73, 78, 69}, + InstantiatePermission: &wasmTypes.AccessConfig{Permission: wasmTypes.AccessTypeAnyOfAddresses, Addresses: []string{"address1", "address2"}}, + Admin: "admin1", Label: "My", Msg: wasmTypes.RawContractMessage(myInnerMsg), Funds: sdk.Coins{{Denom: "denom1", Amount: sdk.NewInt(1)}}}, + exp: ` +{ + "type":"wasm/MsgStoreCodeAndInstantiateContract", + "value": {"admin":"admin1","funds":[{"amount":"1","denom":"denom1"}],"instantiate_permission":{"addresses":["address1","address2"], + "permission":"AnyOfAddresses"},"label":"My","msg":{"foo":"bar"},"sender":"sender1","wasm_byte_code":"WUVMTE9XIFNVQk1BUklORQ=="} +}`, + }, + "MsgInstantiateContract with minimum field": { + src: &MsgStoreCodeAndInstantiateContract{}, + exp: ` +{ + "type":"wasm/MsgStoreCodeAndInstantiateContract", + "value": {"funds":[]} +}`, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + bz := spec.src.GetSignBytes() + assert.JSONEq(t, spec.exp, string(bz), "raw: %s", string(bz)) + }) + } +}