Skip to content

Commit

Permalink
Merge pull request #276 from CosmWasm/expose-error-info-on-receive
Browse files Browse the repository at this point in the history
Return full result on IBCPacketRecv
  • Loading branch information
webmaster128 authored Dec 16, 2021
2 parents 9806303 + 091665d commit e6cdf54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 9 additions & 4 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cosmwasm

import (
"encoding/json"
"io/ioutil"
"testing"

"github.com/CosmWasm/wasmvm/api"
"github.com/CosmWasm/wasmvm/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"testing"
)

const IBC_TEST_CONTRACT = "./api/testdata/ibc_reflect.wasm"
Expand Down Expand Up @@ -241,8 +242,10 @@ func TestIBCPacketDispatch(t *testing.T) {
},
}
msg := api.MockIBCPacketReceive(CHANNEL_ID, toBytes(t, ibcMsg))
pres, _, err := vm.IBCPacketReceive(checksum, env, msg, store, *goapi, querier, gasMeter5, TESTING_GAS_LIMIT, deserCost)
pr, _, err := vm.IBCPacketReceive(checksum, env, msg, store, *goapi, querier, gasMeter5, TESTING_GAS_LIMIT, deserCost)
require.NoError(t, err)
assert.NotNil(t, pr.Ok)
pres := pr.Ok

// assert app-level success
var ack AcknowledgeDispatch
Expand All @@ -251,8 +254,10 @@ func TestIBCPacketDispatch(t *testing.T) {

// error on message from another channel
msg2 := api.MockIBCPacketReceive("no-such-channel", toBytes(t, ibcMsg))
pres2, _, err := vm.IBCPacketReceive(checksum, env, msg2, store, *goapi, querier, gasMeter5, TESTING_GAS_LIMIT, deserCost)
pr2, _, err := vm.IBCPacketReceive(checksum, env, msg2, store, *goapi, querier, gasMeter5, TESTING_GAS_LIMIT, deserCost)
require.NoError(t, err)
assert.NotNil(t, pr.Ok)
pres2 := pr2.Ok
// assert app-level failure
var ack2 AcknowledgeDispatch
err = json.Unmarshal(pres2.Acknowledgement, &ack2)
Expand Down
7 changes: 2 additions & 5 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (vm *VM) IBCPacketReceive(
gasMeter GasMeter,
gasLimit uint64,
deserCost types.UFraction,
) (*types.IBCReceiveResponse, uint64, error) {
) (*types.IBCReceiveResult, uint64, error) {
envBin, err := json.Marshal(env)
if err != nil {
return nil, 0, err
Expand All @@ -542,10 +542,7 @@ func (vm *VM) IBCPacketReceive(
if err != nil {
return nil, gasUsed, err
}
if resp.Err != "" {
return nil, gasUsed, fmt.Errorf("%s", resp.Err)
}
return resp.Ok, gasUsed, nil
return &resp, gasUsed, nil
}

// IBCPacketAck is available on IBC-enabled contracts and is called when an
Expand Down

0 comments on commit e6cdf54

Please sign in to comment.