- Notifications
You must be signed in to change notification settings - Fork 22
test: fix decoding transaction metadata #1280
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 PR refactors test helpers in Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
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 |
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/verify_block_test.go (2)
24-61: Generic tx body decoding and[]anyconversion look correct; consider small safety checkThe switch on
v.(type)and the move toany/[]anykeep behavior identical while modernizing the types; usingdecodeTxBodyBytes(t, txArray[0])via[]anyis sound givenanyis an alias forinterface{}and CBOR decoding will still populate compatible slice elements.One small optional improvement: guard against malformed CBOR that yields an empty
txArrayto avoid a potential index panic and get a clearer failure message in tests:func decodeTxBodies[T any](t *testing.T, txs []any, label string) []T { t.Helper() bodies := make([]T, len(txs)) for i, tx := range txs { - txArray, ok := tx.([]any) + txArray, ok := tx.([]any) if !ok { t.Fatalf("unexpected %s tx element type %T", label, tx) } + if len(txArray) == 0 { + t.Fatalf("unexpected empty %s tx at index %d", label, i) + } txBodyBytes := decodeTxBodyBytes(t, txArray[0]) if _, err := cbor.Decode(txBodyBytes, &bodies[i]); err != nil { ...
63-95: Centralized metadata decoding mirrors prior per‑era logic; minor redundancies are safeThe new
decodeTransactionMetadataSetcorrectly:
- Treats each
txas[]anyand pulls metadata from index 2 only when present.- Preserves the
uint(txIndex)keying used bycommon.TransactionMetadataSet.- Uses
common.DecodeMetadatumRaw(lv.Cbor()), matching the existing decoding semantics.Two minor nits you can ignore or address later:
- The intermediate
transactionMetadataSetmap of*cbor.LazyValuecould be skipped by decoding directly in the first loop.- The second
if lv != nilcheck before decoding is redundant because you already gate onlv != nilwhen populating the map.Neither affects correctness; the helper significantly reduces duplication across eras.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ledger/verify_block_test.go(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ledger/verify_block_test.go (8)
ledger/common/metadata.go (2)
TransactionMetadataSet(38-38)DecodeMetadatumRaw(98-160)cbor/value.go (1)
LazyValue(367-369)ledger/shelley/shelley.go (1)
EraNameShelley(32-32)ledger/allegra/allegra.go (1)
EraNameAllegra(28-28)ledger/mary/mary.go (1)
EraNameMary(31-31)ledger/alonzo/alonzo.go (1)
EraNameAlonzo(34-34)ledger/babbage/babbage.go (1)
EraNameBabbage(34-34)ledger/conway/conway.go (1)
EraNameConway(34-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
ledger/verify_block_test.go (1)
181-293: Refactored tx decoding & metadata wiring per era is consistent and preserves behavior
- Changing
txsto[]anyand decoding withcbor.Decode(bodyCborBytes, &txs)aligns with the updated helpers and keeps the decoded structure compatible withdecodeTxBodiesanddecodeTransactionMetadataSet.- For each block type (Shelley, Allegra, Mary, Alonzo, Babbage, Conway), the generic
decodeTxBodies[...]call uses the correct era‑specific transaction body type, and the corresponding call todecodeTransactionMetadataSetpasses the matchingEraName*constant, so metadata decoding now follows a single, consistent path.- The construction of each concrete block (
ShelleyBlock,AllegraBlock,MaryBlock,AlonzoBlock,BabbageBlock,ConwayBlock) still wiresTransactionBodies,TransactionWitnessSets, andTransactionMetadataSettogether as before; the only real change is that metadata is no longer decoded inline per era.This refactor looks good and should be behavior‑preserving while making future metadata test updates easier.
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.
No issues found across 1 file
Summary by cubic
Fixes transaction metadata decoding in block verification tests by adding a shared helper and using it across all eras. Also replaces interface{} with any for cleaner generics.
Bug Fixes
Refactors
Written for commit bda1e0d. Summary will update automatically on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.