diff --git a/pkg/capabilities/consensus/ocr3/types/aggregator.go b/pkg/capabilities/consensus/ocr3/types/aggregator.go index af86026ed..6484a5fbc 100644 --- a/pkg/capabilities/consensus/ocr3/types/aggregator.go +++ b/pkg/capabilities/consensus/ocr3/types/aggregator.go @@ -13,22 +13,23 @@ const MetadataFieldName = "INTERNAL_METADATA" type Metadata struct { Version uint32 // 1 byte - ExecutionID string // 32 hex bytes + ExecutionID string // 32 hex bytes (string len = 64) Timestamp uint32 // 4 bytes DONID uint32 // 4 bytes DONConfigVersion uint32 // 4 bytes - WorkflowID string // 32 hex bytes - WorkflowName string // 10 hex bytes - WorkflowOwner string // 20 hex bytes - ReportID string // 2 hex bytes + WorkflowID string // 32 hex bytes (string len = 64) + WorkflowName string // 10 hex bytes (string len = 20) + WorkflowOwner string // 20 hex bytes (string len = 40) + ReportID string // 2 hex bytes (string len = 4) } // the contract requires exactly 10 bytes for the workflow name -// the json schema allows for a variable length string <= len(10) -// pad with trailing spaces to meet the contract requirements +// the resulting workflow name should be up to 10 bytes long +// so pad accordingly to meet the contract requirements func (m *Metadata) padWorkflowName() { - if len(m.WorkflowName) < 10 { - suffix := strings.Repeat(" ", 10-len(m.WorkflowName)) + // it should have 10 hex bytes, so 20 characters total + if len(m.WorkflowName) < 20 { + suffix := strings.Repeat("0", 20-len(m.WorkflowName)) m.WorkflowName += suffix } } diff --git a/pkg/capabilities/consensus/ocr3/types/aggregator_test.go b/pkg/capabilities/consensus/ocr3/types/aggregator_test.go index dce0179b3..94660d103 100644 --- a/pkg/capabilities/consensus/ocr3/types/aggregator_test.go +++ b/pkg/capabilities/consensus/ocr3/types/aggregator_test.go @@ -16,25 +16,32 @@ func TestMetadata_padWorkflowName(t *testing.T) { want string }{ { - name: "padWorkflowName 1", + name: "padWorkflowName hex with 9 bytes", fields: fields{ - WorkflowName: "123456789", + WorkflowName: "ABCD1234EF567890AB", }, - want: "123456789 ", + want: "ABCD1234EF567890AB00", }, { - name: "padWorkflowName 0", + name: "padWorkflowName hex with 5 bytes", fields: fields{ - WorkflowName: "1234567890", + WorkflowName: "1234ABCD56", }, - want: "1234567890", + want: "1234ABCD560000000000", }, { - name: "padWorkflowName 10", + name: "padWorkflowName empty", fields: fields{ WorkflowName: "", }, - want: " ", + want: "00000000000000000000", + }, + { + name: "padWorkflowName non-hex string", + fields: fields{ + WorkflowName: "not-hex", + }, + want: "not-hex0000000000000", }, } for _, tt := range tests {