From 1a40aa6dcbdac8cd34183bbc1e4e686b3c7492a2 Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Wed, 22 Feb 2023 20:37:15 +0900 Subject: [PATCH 1/5] fix:wrong wasmplus amino codec register --- x/wasmplus/types/codec.go | 2 +- x/wasmplus/types/tx.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) 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 { From 63d1e31415440d1b8932ffe06f7d186a4bc2ad8a Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Wed, 22 Feb 2023 22:31:44 +0900 Subject: [PATCH 2/5] test: add test for getSignBytes of wasmplus --- x/wasmplus/types/tx_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/x/wasmplus/types/tx_test.go b/x/wasmplus/types/tx_test.go index 6b00495595..642443b2ce 100644 --- a/x/wasmplus/types/tx_test.go +++ b/x/wasmplus/types/tx_test.go @@ -3,6 +3,7 @@ package types import ( "encoding/hex" "fmt" + "github.com/line/lbm-sdk/x/auth/legacy/legacytx" "testing" "github.com/stretchr/testify/assert" @@ -135,3 +136,25 @@ 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": { + src: &MsgStoreCodeAndInstantiateContract{Sender: "sender1", WASMByteCode: []byte{89, 69, 76, 76, 79, 87, 32, 83, 85, 66, 77, 65, 82, 73, 78, 69}, Admin: "admin1", Label: "My", Msg: wasmTypes.RawContractMessage(myInnerMsg)}, + exp: ` +{ + "type":"wasm/MsgStoreCodeAndInstantiateContract", + "value": {"admin":"admin1","funds":[],"label":"My","msg": {"foo":"bar"},"sender":"sender1","wasm_byte_code":"WUVMTE9XIFNVQk1BUklORQ=="} +}`, + }} + 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)) + }) + } +} From 7aceec23ab0155a3845eb7e7d10d5c4c05c2cf4f Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Wed, 22 Feb 2023 23:05:12 +0900 Subject: [PATCH 3/5] chore: add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 8775236f6729ffe32616a8d95a318611728fe1af Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Thu, 23 Feb 2023 21:52:01 +0900 Subject: [PATCH 4/5] chore: change import order --- x/wasmplus/types/tx_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasmplus/types/tx_test.go b/x/wasmplus/types/tx_test.go index 642443b2ce..eed5e10b22 100644 --- a/x/wasmplus/types/tx_test.go +++ b/x/wasmplus/types/tx_test.go @@ -3,13 +3,13 @@ package types import ( "encoding/hex" "fmt" - "github.com/line/lbm-sdk/x/auth/legacy/legacytx" "testing" "github.com/stretchr/testify/assert" "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" ) From 28fd22642cd807be5422ed46553ea2c0170fc7fe Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Thu, 23 Feb 2023 22:35:03 +0900 Subject: [PATCH 5/5] test: add maximum and minimum test case --- x/wasmplus/types/tx_test.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/x/wasmplus/types/tx_test.go b/x/wasmplus/types/tx_test.go index eed5e10b22..c7f1c134a1 100644 --- a/x/wasmplus/types/tx_test.go +++ b/x/wasmplus/types/tx_test.go @@ -143,14 +143,26 @@ func TestMsgJsonSignBytes(t *testing.T) { src legacytx.LegacyMsg exp string }{ - "MsgInstantiateContract": { - src: &MsgStoreCodeAndInstantiateContract{Sender: "sender1", WASMByteCode: []byte{89, 69, 76, 76, 79, 87, 32, 83, 85, 66, 77, 65, 82, 73, 78, 69}, Admin: "admin1", Label: "My", Msg: wasmTypes.RawContractMessage(myInnerMsg)}, + "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":[],"label":"My","msg": {"foo":"bar"},"sender":"sender1","wasm_byte_code":"WUVMTE9XIFNVQk1BUklORQ=="} + "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()