Skip to content

Conversation

@mts1715
Copy link

@mts1715 mts1715 commented Nov 28, 2025

Closes #8127
test: achieve 100% test coverage for engine/common/rpc/convert package

Add comprehensive tests for all previously untested conversion and validation
functions.

Changes:

  • Add tests for MessagesToBlockSeals and PayloadFromMessage
  • Create validate_test.go with tests for all 7 validation functions
  • Add tests for 9 previously untested functions:
    • TransactionsToMessages
    • CcfPayloadToJsonPayload
    • CcfEventsToJsonEvents
    • CcfEventToJsonEvent
    • EventToMessageFromVersion
    • EventsToMessagesWithEncodingConversion
    • BlockTimestamp2ProtobufTime
    • BlockEventsToMessage
    • MessageToBlockEvents

Add comprehensive tests for all previously untested conversion and validation functions.
@mts1715 mts1715 self-assigned this Nov 28, 2025
@mts1715 mts1715 requested a review from a team as a code owner November 28, 2025 20:15
@peterargue peterargue changed the base branch from master to feature/optimistic-sync November 28, 2025 20:42
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv left a comment

Choose a reason for hiding this comment

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

Overall, looks good! I’ve left a few suggestions for improvements.

EndHeight: endHeight,
}

msg := convert.CompatibleRangeToMessage(comparableRange)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the "convert range to message" subtest, since the "roundtrip conversion" subtest now covers the same behavior.

Comment on lines +117 to +120
assert.Equal(t, seal.BlockID, converted.BlockID)
assert.Equal(t, seal.ResultID, converted.ResultID)
assert.Equal(t, seal.FinalState, converted.FinalState)
assert.Equal(t, seal.AggregatedApprovalSigs, converted.AggregatedApprovalSigs)
Copy link
Contributor

Choose a reason for hiding this comment

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

we could use the ID() method here and in other cases to ensure that the objects are cryptographically identical.

Suggested change
assert.Equal(t, seal.BlockID, converted.BlockID)
assert.Equal(t, seal.ResultID, converted.ResultID)
assert.Equal(t, seal.FinalState, converted.FinalState)
assert.Equal(t, seal.AggregatedApprovalSigs, converted.AggregatedApprovalSigs)
assert.Equal(t, seal.ID(), converted.ID())

Comment on lines +141 to +144
assert.Equal(t, seal.BlockID, converted[i].BlockID)
assert.Equal(t, seal.ResultID, converted[i].ResultID)
assert.Equal(t, seal.FinalState, converted[i].FinalState)
assert.Equal(t, seal.AggregatedApprovalSigs, converted[i].AggregatedApprovalSigs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.Equal(t, seal.BlockID, converted[i].BlockID)
assert.Equal(t, seal.ResultID, converted[i].ResultID)
assert.Equal(t, seal.FinalState, converted[i].FinalState)
assert.Equal(t, seal.AggregatedApprovalSigs, converted[i].AggregatedApprovalSigs)
assert.Equal(t, seal.ID(), converted[i].ID())

Comment on lines +127 to +131
seals := []*flow.Seal{
unittest.Seal.Fixture(),
unittest.Seal.Fixture(),
unittest.Seal.Fixture(),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
seals := []*flow.Seal{
unittest.Seal.Fixture(),
unittest.Seal.Fixture(),
unittest.Seal.Fixture(),
}
seals := unittest.Seal.Fixtures(3)

Comment on lines +161 to +165
assert.Equal(t, block.Payload.Guarantees, payload.Guarantees)
assert.Equal(t, block.Payload.Seals, payload.Seals)
assert.Equal(t, block.Payload.Receipts, payload.Receipts)
assert.Equal(t, block.Payload.Results, payload.Results)
assert.Equal(t, block.Payload.ProtocolStateID, payload.ProtocolStateID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.Equal(t, block.Payload.Guarantees, payload.Guarantees)
assert.Equal(t, block.Payload.Seals, payload.Seals)
assert.Equal(t, block.Payload.Receipts, payload.Receipts)
assert.Equal(t, block.Payload.Results, payload.Results)
assert.Equal(t, block.Payload.ProtocolStateID, payload.ProtocolStateID)
assert.Equal(t, block.Payload.Hash(), payload.Hash())

}

// TestConvertBlockEventsToMessage tests converting a single flow.BlockEvents to a protobuf message.
func TestConvertBlockEventsToMessage(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the TestConvertBlockEventsToMessage is redundant. The TestConvertMessageToBlockEvents, already performs a full round-trip conversion and checks the same fields, so we could simplify by keeping only the round-trip test.

and rename the TestConvertMessageToBlockEvents to TestConvertBlockEvent.

require.Equal(t, blockEvents.BlockHeight, converted.BlockHeight)
require.Equal(t, blockEvents.BlockID, converted.BlockID)
require.Equal(t, blockEvents.BlockTimestamp.Unix(), converted.BlockTimestamp.Unix())
require.Len(t, converted.Events, len(blockEvents.Events))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
require.Len(t, converted.Events, len(blockEvents.Events))
require.Len(t, converted.Events, len(blockEvents.Events))
for i, event := range blockEvents.Events {
require.Equal(t, event.ID(), converted.Events[i].ID())
}

or
we can compare all object, cause flow.BlockEvents does not have the ID() method.
require.Equal(t, blockEvents, converted)

)

_, err := convert.CcfEventToJsonEvent(invalidEvent)
require.Error(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please verify the error and that the response is nil.

)

_, err := convert.CcfEventToJsonEvent(emptyEvent)
require.Error(t, err, "empty payload should result in error from flow.NewEvent")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and in other cases

Comment on lines +45 to +54
// Add some variation to exercise different code paths
if i%2 == 0 {
arg, err := jsoncdc.Encode(cadence.NewAddress(unittest.AddressFixture()))
require.NoError(t, err)
tx.Arguments = append(tx.Arguments, arg)
}

if i%3 == 0 {
tx.EnvelopeSignatures = append(tx.EnvelopeSignatures, unittest.TransactionSignatureFixture())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend just using unittest.TransactionBodyListFixture, but renaming it to unittest.TransactionFixtures (since unittest.TransactionBodyFixture is deprecated , and we have only three usages of TransactionBodyListFixture, so no need to create a new one).
Alternatively, we could add With... options to TransactionFixture and use them. But I think it not worth in such tests. Reason: we prevent mutations of struct types marked as immutable in code and tries to avoid such mutations in new tests at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Access] Improve grpc converter tests.

4 participants