Test passes with opaque msg

This commit is contained in:
Ethan Frey 2020-01-20 20:29:54 +01:00
parent 3f78ce5331
commit 1b1e6ae1e8
3 changed files with 26 additions and 5 deletions

View File

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

View File

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

View File

@ -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