Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] fix panic at wasm event parse #531

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions x/wasm/types/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ func ParseEvents(

var sdkEvents sdk.Events

sdkEvent, err := buildEvent(EventTypeWasmPrefix, contractAddr, attributes)
if err != nil {
return nil, err
}
if len(attributes) != 0 {
sdkEvent, err := buildEvent(EventTypeWasmPrefix, contractAddr, attributes)
if err != nil {
return nil, err
}

sdkEvents = sdkEvents.AppendEvent(*sdkEvent)
sdkEvents = sdkEvents.AppendEvent(*sdkEvent)

// Deprecated: from_contract
sdkEvent.Type = EventTypeFromContract
sdkEvents = sdkEvents.AppendEvent(*sdkEvent)
// Deprecated: from_contract
sdkEvent.Type = EventTypeFromContract
sdkEvents = sdkEvents.AppendEvent(*sdkEvent)
}

// append wasm prefix for the events
for _, event := range events {
Expand Down
41 changes: 41 additions & 0 deletions x/wasm/types/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,47 @@ func TestParseEvents(t *testing.T) {
)}, events)
}

func TestParseEventsWithoutAttributes(t *testing.T) {
_, _, addr := keyPubAddr()

events, err := ParseEvents(addr, wasmvmtypes.EventAttributes{}, wasmvmtypes.Events{
{
Type: "type1",
Attributes: wasmvmtypes.EventAttributes{
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
{Key: "key3", Value: "value3"},
},
},
{
Type: "type2",
Attributes: wasmvmtypes.EventAttributes{
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
{Key: "key3", Value: "value3"},
},
},
})
require.NoError(t, err)
require.Equal(t, sdk.Events{sdk.NewEvent(
fmt.Sprintf("%s-type1", EventTypeWasmPrefix),
[]sdk.Attribute{
{Key: AttributeKeyContractAddress, Value: addr.String()},
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
{Key: "key3", Value: "value3"},
}...,
), sdk.NewEvent(
fmt.Sprintf("%s-type2", EventTypeWasmPrefix),
[]sdk.Attribute{
{Key: AttributeKeyContractAddress, Value: addr.String()},
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
{Key: "key3", Value: "value3"},
}...,
)}, events)
}

func TestBuildEvent(t *testing.T) {
_, _, addr := keyPubAddr()

Expand Down