Allow empty attribute values (#1618)
* remove event value judgment * remove event value judgment * fix cosmwasm events test
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user