Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong wasmplus amino codec register #12

Merged
merged 5 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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))
})
}
}