-
Notifications
You must be signed in to change notification settings - Fork 21
test(ledger): naive serde and determine tx type benchmarks #1249
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
Conversation
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
📝 WalkthroughWalkthroughThis change introduces performance benchmarking infrastructure for transaction handling across multiple Cardano eras. Two new public constants containing CBOR hexadecimal representations of Byron and Conway transaction samples have been added to replace inline literals in test setup. Six new benchmark functions have been introduced to measure performance of transaction type determination, deserialization, and serialization operations for both Byron and Conway era transactions. The existing test flow is preserved while expanding test coverage to these additional transaction paths. Minor formatting adjustments were made to error handling assertions. Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
ledger/tx_test.go (2)
24-27: Consider making constants private.The constants are exported but appear to be used only within this file. Unless they need to be shared with other test files in the
ledger_testpackage, consider making them private (lowercase names) to limit their scope.const ( - byronTxCborHex = "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0" - conwayTxCborHex = "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6" + byronTxCborHex = "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0" + conwayTxCborHex = "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6" )
67-92: Consider handling hex decode errors for robustness.All benchmarks ignore errors from
hex.DecodeString. While this is common practice when input is known to be valid (validated by the test), explicitly checking these errors would improve consistency and make debugging easier if the constants are ever modified incorrectly.Example for
BenchmarkDetermineTransactionType_Conway:func BenchmarkDetermineTransactionType_Conway(b *testing.B) { - txCbor, _ := hex.DecodeString(conwayTxCborHex) + txCbor, err := hex.DecodeString(conwayTxCborHex) + if err != nil { + b.Fatalf("failed to decode hex: %s", err) + } b.ResetTimer() for i := 0; i < b.N; i++ { _, err := ledger.DetermineTransactionType(txCbor)Apply similar changes to other benchmark functions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ledger/tx_test.go(3 hunks)
🔇 Additional comments (3)
ledger/tx_test.go (3)
29-65: LGTM!The refactoring to use constants improves maintainability and DRY principles. The test validates that both transaction hex strings are valid and correctly classified.
94-138: Well-structured benchmarks.The deserialization and serialization benchmarks are correctly implemented:
- Setup happens before
b.ResetTimer()- Serialization benchmarks properly prepare transaction objects outside the timed loop
- Each benchmark measures a single, focused operation
78-81: LGTM!The comment provides helpful context about benchmark coverage and clarifies that the Conway type determination benchmark exercises the fallthrough logic across multiple eras.
Summary by CodeRabbit
Tests
Chores