Skip to content

Commit

Permalink
Incorrect argument types when calling a compass-evm logic call functi…
Browse files Browse the repository at this point in the history
…on (#477)
  • Loading branch information
Vizualni authored Sep 15, 2022
1 parent 13147dc commit 948922c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions x/evm/keeper/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ const (
ErrConsensusNotAchieved = whoops.String("evm: consensus not achieved")
ErrCannotAddSupportForChainThatExists = whoops.Errorf("chain info already exists: %s")
ErrCannotActiveSmartContractThatIsNotDeploying = whoops.String("trying to activate a smart contract that is not currently deploying")

ErrWasmExecuteMessageNotValid = whoops.String("message is not valid")
)
15 changes: 7 additions & 8 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -311,27 +310,27 @@ type ExecuteEVMFromCosmWasm struct {
Payload []byte `json:"payload"`
}

func (e ExecuteEVMFromCosmWasm) valid() bool {
func (e ExecuteEVMFromCosmWasm) valid() error {
zero := ExecuteEVMFromCosmWasm{}
if e.TargetContractInfo == zero.TargetContractInfo {
return false
return whoops.String("target contract info is empty")
}
if len(e.Payload) == 0 {
return false
return whoops.String("payload bytes is empty")
}
// todo: add more in the future
return true
return nil
}

func (k Keeper) WasmMessengerHandler() wasmutil.MessengerFnc {
return func(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error) {
var executeMsg ExecuteEVMFromCosmWasm
err := json.Unmarshal(msg.Custom, &executeMsg)
if err != nil {
return nil, nil, whoops.Wrap(err, wasmtypes.ErrUnknownMsg)
return nil, nil, err
}
if !executeMsg.valid() {
return nil, nil, wasmtypes.ErrUnknownMsg
if err = executeMsg.valid(); err != nil {
return nil, nil, whoops.Wrap(err, ErrWasmExecuteMessageNotValid)
}

ci, err := k.GetChainInfo(ctx, executeMsg.TargetContractInfo.ChainReferenceID)
Expand Down
3 changes: 1 addition & 2 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -811,7 +810,7 @@ var _ = Describe("wasm message handler", func() {
Context("invalid message", func() {
When("message is empty", func() {
It("returns an error", func() {
Expect(subject()).To(MatchError(wasmtypes.ErrUnknownMsg))
Expect(subject()).To(MatchError(keeper.ErrWasmExecuteMessageNotValid))
})
})
})
Expand Down

0 comments on commit 948922c

Please sign in to comment.