From 4e7316e97bcc32473ebeabeebe7084dd0ce6ddf3 Mon Sep 17 00:00:00 2001 From: FengFeng <1290017556@qq.com> Date: Wed, 15 Nov 2023 17:15:58 +0800 Subject: [PATCH] Allow empty attribute values (#1618) * remove event value judgment * remove event value judgment * fix cosmwasm events test --- x/wasm/keeper/events.go | 4 ---- x/wasm/keeper/events_test.go | 41 +++++++++++++++--------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/x/wasm/keeper/events.go b/x/wasm/keeper/events.go index ef738b10d6..b50719d461 100644 --- a/x/wasm/keeper/events.go +++ b/x/wasm/keeper/events.go @@ -55,10 +55,6 @@ func contractSDKEventAttributes(customAttributes []wasmvmtypes.EventAttribute, c return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute key. Value: %s", l.Value)) } value := strings.TrimSpace(l.Value) - // TODO: check if this is legal in the SDK - if it is, we can remove this check - if len(value) == 0 { - return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Empty attribute value. Key: %s", key)) - } // and reserve all _* keys for our use (not contract) if strings.HasPrefix(key, types.AttributeReservedPrefix) { return nil, errorsmod.Wrap(types.ErrInvalidEvent, fmt.Sprintf("Attribute key starts with reserved prefix %s: '%s'", types.AttributeReservedPrefix, key)) diff --git a/x/wasm/keeper/events_test.go b/x/wasm/keeper/events_test.go index b091eb452d..3c55a60878 100644 --- a/x/wasm/keeper/events_test.go +++ b/x/wasm/keeper/events_test.go @@ -106,6 +106,23 @@ func TestNewCustomEvents(t *testing.T) { exp: sdk.Events{sdk.NewEvent("wasm-foo", sdk.NewAttribute("_contract_address", myContract.String()))}, }, + "empty value can be solved": { + src: wasmvmtypes.Events{{ + Type: "foo", + Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: ""}}, + }}, + exp: sdk.Events{sdk.NewEvent("wasm-foo", + sdk.NewAttribute("_contract_address", myContract.String()), + sdk.NewAttribute("myKey", ""))}, + }, + "good on whitespace value": { + src: wasmvmtypes.Events{{ + Type: "foo", + Attributes: []wasmvmtypes.EventAttribute{{Key: "myKey", Value: "\n\n\n"}}, + }}, exp: sdk.Events{sdk.NewEvent("wasm-foo", + sdk.NewAttribute("_contract_address", myContract.String()), + sdk.NewAttribute("myKey", ""))}, + }, "error on short event type": { src: wasmvmtypes.Events{{ Type: "f", @@ -129,16 +146,6 @@ func TestNewCustomEvents(t *testing.T) { }}, isError: true, }, - "error on empty value": { - src: wasmvmtypes.Events{{ - Type: "boom", - Attributes: []wasmvmtypes.EventAttribute{ - {Key: "some", Value: "data"}, - {Key: "key", Value: ""}, - }, - }}, - isError: true, - }, "error on empty key": { src: wasmvmtypes.Events{{ Type: "boom", @@ -168,16 +175,6 @@ func TestNewCustomEvents(t *testing.T) { }}, isError: true, }, - "error on only whitespace value": { - src: wasmvmtypes.Events{{ - Type: "boom", - Attributes: []wasmvmtypes.EventAttribute{ - {Key: "some", Value: "data"}, - {Key: "myKey", Value: " \t\r\n"}, - }, - }}, - isError: true, - }, "strip out whitespace": { src: wasmvmtypes.Events{{ Type: " food\n", @@ -243,10 +240,6 @@ func TestNewWasmModuleEvent(t *testing.T) { src: []wasmvmtypes.EventAttribute{{Key: " ", Value: "value"}}, isError: true, }, - "error on whitespace value": { - src: []wasmvmtypes.EventAttribute{{Key: "key", Value: "\n\n\n"}}, - isError: true, - }, "strip whitespace": { src: []wasmvmtypes.EventAttribute{{Key: " my-real-key ", Value: "\n\n\nsome-val\t\t\t"}}, exp: sdk.Events{sdk.NewEvent("wasm",