From 654fcec122c274a3dbe0a99eb3f76cc02e69085f Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 2 Mar 2022 14:15:11 +0100 Subject: [PATCH 1/2] Revert "Handle nil logger again" This reverts commit 66ac1f58ce7e4976bd77f9236ced388cb9259fc1. --- x/wasm/keeper/msg_dispatcher.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index c28e92d085..51bb37cc79 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -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), } @@ -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) From b2217a3a44b773216ad6b2f4eaad757fc00ad9d3 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 2 Mar 2022 14:21:00 +0100 Subject: [PATCH 2/2] Fix test setup and assertions --- x/wasm/keeper/msg_dispatcher_test.go | 4 +++- x/wasm/keeper/submsg_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index b1a806a6c3..b53eac72da 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -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" @@ -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 { diff --git a/x/wasm/keeper/submsg_test.go b/x/wasm/keeper/submsg_test.go index bb2ab29150..29c3ad8eb1 100644 --- a/x/wasm/keeper/submsg_test.go +++ b/x/wasm/keeper/submsg_test.go @@ -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, @@ -275,7 +275,7 @@ 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, @@ -283,7 +283,7 @@ func TestDispatchSubMsgErrorHandling(t *testing.T) { 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,