Skip to content

Commit

Permalink
Allow empty attribute values (#1618)
Browse files Browse the repository at this point in the history
* remove event value judgment

* remove event value judgment

* fix cosmwasm events test

(cherry picked from commit 4e7316e)
  • Loading branch information
99Kies authored and mergify[bot] committed Nov 15, 2023
1 parent 2d9c98f commit 9ced765
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
4 changes: 0 additions & 4 deletions x/wasm/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
41 changes: 17 additions & 24 deletions x/wasm/keeper/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9ced765

Please sign in to comment.