Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 12, 2024
1 parent b99102c commit da75347
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
8 changes: 4 additions & 4 deletions server/v2/stf/stf.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,15 @@ func createMessageEvent(msg transaction.Msg, msgIndex, eventIndex int32) event.E
Attributes: func() ([]appdata.EventAttribute, error) {
typeURL := msgTypeURL(msg)
return []appdata.EventAttribute{
{Key: "message.action", Value: "/" + typeURL},
{Key: "message.module", Value: getModuleNameFromTypeURL(typeURL)},
{Key: "action", Value: "/" + typeURL},
{Key: "module", Value: getModuleNameFromTypeURL(typeURL)},
}, nil
},
Data: func() (json.RawMessage, error) {
typeURL := msgTypeURL(msg)
attrs := []appdata.EventAttribute{
{Key: "message.action", Value: "/" + typeURL},
{Key: "message.module", Value: getModuleNameFromTypeURL(typeURL)},
{Key: "action", Value: "/" + typeURL},
{Key: "module", Value: getModuleNameFromTypeURL(typeURL)},
}

return json.Marshal(attrs)
Expand Down
23 changes: 18 additions & 5 deletions server/v2/stf/stf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ func TestSTF(t *testing.T) {
}
// check TxEvents
events := txResult.Events
if len(events) != 6 {
t.Fatalf("Expected 6 TxEvents, got %d", len(events))
if len(events) != 7 {
t.Fatalf("Expected 7 TxEvents, got %d", len(events))
}
for i, event := range events {
if event.BlockStage != appdata.TxProcessingStage {
Expand All @@ -235,7 +235,8 @@ func TestSTF(t *testing.T) {
if event.TxIndex != 1 {
t.Errorf("Expected TxIndex 1, got %d", event.TxIndex)
}
if event.EventIndex != int32(i%2+1) {
if event.EventIndex != int32(i%2+1) &&
(event.Type == "message" && event.EventIndex != 3) { // special case for message event type as it happens in the msg handling flow
t.Errorf("Expected EventIndex %d, got %d", i%2+1, event.EventIndex)
}

Expand All @@ -247,7 +248,7 @@ func TestSTF(t *testing.T) {
t.Errorf("Expected 1 or 2 attributes, got %d", len(attrs))
}

if len(attrs) == 2 {
if len(attrs) == 2 && event.Type != "message" {
if attrs[1].Key != "index" || attrs[1].Value != "2" {
t.Errorf("Expected attribute key 'index' and value '2', got key '%s' and value '%s'", attrs[1].Key, attrs[1].Value)
}
Expand All @@ -273,7 +274,19 @@ func TestSTF(t *testing.T) {
if attrs[0].Key != "msg" || attrs[0].Value != "&BoolValue{Value:true,XXX_unrecognized:[],}" {
t.Errorf("Expected msg attribute with value '&BoolValue{Value:true,XXX_unrecognized:[],}', got '%s'", attrs[0].Value)
}
case 4, 5:
case 4:
if event.Type != "message" {
t.Errorf("Expected event type 'message', got %s", event.Type)
}

if event.MsgIndex != 1 {
t.Errorf("Expected MsgIndex 1, got %d", event.MsgIndex)
}

if attrs[0].Key != "action" || attrs[0].Value != "/google.protobuf.BoolValue" {
t.Errorf("Expected msg attribute with value '/google.protobuf.BoolValue', got '%s'", attrs[0].Value)
}
case 5, 6:
if event.Type != "post-tx-exec" {
t.Errorf("Expected event type 'post-tx-exec', got %s", event.Type)
}
Expand Down

0 comments on commit da75347

Please sign in to comment.