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

Fix padWorkflowName() #977

Merged
merged 5 commits into from
Dec 19, 2024
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
19 changes: 10 additions & 9 deletions pkg/capabilities/consensus/ocr3/types/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change? i don't think it's correct

// 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
}
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/capabilities/consensus/ocr3/types/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, technically correct ;)

},
}
for _, tt := range tests {
Expand Down
Loading