Skip to content

Commit

Permalink
fix wrong wasmplus amino codec register (#12)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
loin3 authored Mar 14, 2023
1 parent 577e450 commit 962f37d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion x/wasmplus/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions x/wasmplus/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions x/wasmplus/types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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))
})
}
}

0 comments on commit 962f37d

Please sign in to comment.