Skip to content

Commit

Permalink
Merge pull request #770 from CosmWasm/759-redact-reply-errors-tests
Browse files Browse the repository at this point in the history
Fix test setup and assertions
  • Loading branch information
ethanfrey authored Mar 2, 2022
2 parents 66ac1f5 + b2217a3 commit daf0d00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
9 changes: 1 addition & 8 deletions x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk
}
} else {
// Issue #759 - we don't return error string for worries of non-determinism
logRedactError(ctx, err)
moduleLogger(ctx).Info("Redacting submessage error", "cause", err)
result = wasmvmtypes.SubcallResult{
Err: redactError(err),
}
Expand All @@ -159,13 +159,6 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk
return rsp, nil
}

func logRedactError(ctx sdk.Context, err error) {
logger := moduleLogger(ctx)
if logger != nil {
logger.Info("Redacting submessage error", "cause", err)
}
}

func redactError(err error) string {
// FIXME: do we want to hardcode some constant string mappings here as well?
// Or better document them? (SDK error string may change on a patch release to fix wording)
Expand Down
4 changes: 3 additions & 1 deletion x/wasm/keeper/msg_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"testing"

"github.com/tendermint/tendermint/libs/log"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -347,7 +349,7 @@ func TestDispatchSubmessages(t *testing.T) {
em := sdk.NewEventManager()
ctx := sdk.Context{}.WithMultiStore(&mockStore).
WithGasMeter(sdk.NewGasMeter(100)).
WithEventManager(em)
WithEventManager(em).WithLogger(log.TestingLogger())
d := NewMessageDispatcher(spec.msgHandler, spec.replyer)
gotData, gotErr := d.DispatchSubmessages(ctx, RandomAccountAddress(t), "any_port", spec.msgs)
if spec.expErr {
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/keeper/submsg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) {
msg: invalidBankSend,
subMsgError: true,
// uses less gas than the send tokens (cost of bank transfer)
resultAssertions: []assertion{assertGasUsed(76000, 79000), assertErrorString("sdk/5")},
resultAssertions: []assertion{assertGasUsed(76000, 79000), assertErrorString("codespace: sdk, code: 5")},
},
"out of gas panic with no gas limit": {
submsgID: 7,
Expand All @@ -275,15 +275,15 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) {
subMsgError: true,
gasLimit: &subGasLimit,
// uses same gas as call without limit (note we do not charge the 40k on reply)
resultAssertions: []assertion{assertGasUsed(77500, 77600), assertErrorString("sdk/5")},
resultAssertions: []assertion{assertGasUsed(77800, 77900), assertErrorString("codespace: sdk, code: 5")},
},
"out of gas caught with gas limit": {
submsgID: 17,
msg: infiniteLoop,
subMsgError: true,
gasLimit: &subGasLimit,
// uses all the subGasLimit, plus the 52k or so for the main contract
resultAssertions: []assertion{assertGasUsed(subGasLimit+72000, subGasLimit+73000), assertErrorString("sdk/11")},
resultAssertions: []assertion{assertGasUsed(subGasLimit+73000, subGasLimit+74000), assertErrorString("codespace: sdk, code: 11")},
},
"instantiate contract gets address in data and events": {
submsgID: 21,
Expand Down

0 comments on commit daf0d00

Please sign in to comment.