From 1b1e6ae1e8630934a16798d4e83970820991c207 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 20 Jan 2020 20:29:54 +0100 Subject: [PATCH] Test passes with opaque msg --- x/wasm/internal/keeper/keeper.go | 15 +++++++++++++-- x/wasm/internal/keeper/mask_test.go | 8 ++++++++ x/wasm/internal/keeper/test_common.go | 8 +++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 5a2c85b..d234e81 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "encoding/base64" "encoding/binary" "fmt" "path/filepath" @@ -315,8 +316,18 @@ func (k Keeper) dispatchMessage(ctx sdk.Context, contract exported.Account, msg return err } } else if msg.Opaque.Data != "" { - // TODO: handle opaque - panic("dispatch opaque message not yet implemented") + // until more is changes, format is amino json encoding, wrapped base64 + bz, err := base64.StdEncoding.DecodeString(msg.Opaque.Data) + if err != nil { + return sdk.ErrTxDecode(err.Error()) + } + var msg sdk.Msg + err = k.cdc.UnmarshalJSON(bz, &msg) + if err != nil { + return sdk.ErrTxDecode(err.Error()) + } + fmt.Printf("\ndecoded: %#v\n", msg) + return k.handleSdkMessage(ctx, contract, msg) } // what is it? panic(fmt.Sprintf("Unknown CosmosMsg: %#v", msg)) diff --git a/x/wasm/internal/keeper/mask_test.go b/x/wasm/internal/keeper/mask_test.go index 0bc9f9a..03cd911 100644 --- a/x/wasm/internal/keeper/mask_test.go +++ b/x/wasm/internal/keeper/mask_test.go @@ -147,4 +147,12 @@ func TestMaskSend(t *testing.T) { _, err = keeper.Execute(ctx, contractAddr, bob, nil, reflectOpaqueBz) require.NoError(t, err) + // fred got more coins + fredAcct = accKeeper.GetAccount(ctx, fred) + require.NotNil(t, fredAcct) + require.Equal(t, fredAcct.GetCoins(), sdk.NewCoins(sdk.NewInt64Coin("denom", 38000))) + // contract lost them + contractAcct = accKeeper.GetAccount(ctx, contractAddr) + require.NotNil(t, contractAcct) + require.Equal(t, contractAcct.GetCoins(), sdk.NewCoins(sdk.NewInt64Coin("denom", 2000))) } diff --git a/x/wasm/internal/keeper/test_common.go b/x/wasm/internal/keeper/test_common.go index f22eef0..867ad8d 100644 --- a/x/wasm/internal/keeper/test_common.go +++ b/x/wasm/internal/keeper/test_common.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -27,8 +26,11 @@ func MakeTestCodec() *codec.Codec { var cdc = codec.New() // Register AppAccount - cdc.RegisterInterface((*authexported.Account)(nil), nil) - cdc.RegisterConcrete(&auth.BaseAccount{}, "test/wasm/BaseAccount", nil) + // cdc.RegisterInterface((*authexported.Account)(nil), nil) + // cdc.RegisterConcrete(&auth.BaseAccount{}, "test/wasm/BaseAccount", nil) + auth.AppModuleBasic{}.RegisterCodec(cdc) + bank.AppModuleBasic{}.RegisterCodec(cdc) + sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) return cdc