From 962f37d9be9a88d64644b3cb5ef83e73d2adb78e Mon Sep 17 00:00:00 2001 From: "Jinseong.Cho" Date: Tue, 14 Mar 2023 15:50:52 +0900 Subject: [PATCH] fix wrong wasmplus amino codec register (#12) * fix:wrong wasmplus amino codec register * test: add test for getSignBytes of wasmplus * chore: add changelog * chore: change import order * test: add maximum and minimum test case --- CHANGELOG.md | 1 + x/wasmplus/types/codec.go | 2 +- x/wasmplus/types/tx.go | 6 ++---- x/wasmplus/types/tx_test.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10a6bb37d7..e178691392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * [\#10](https://github.com/line/wasmd/pull/10) update wasmvm version ### 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)) + }) + } +}