fix: use named parameter check instead of fragile >= 6 count for ABI version detection#98
Conversation
…version detection (#310) The previous check used len(inputs) >= 6 to detect whether the addTransaction ABI includes valid_until. This is fragile: a future protocol upgrade adding a 7th argument would supply an extra positional argument and silently corrupt transaction encoding. Replace the count-based check with a named-parameter check: 'valid_until' in [inp['name'] for inp in inputs] This correctly detects the v6 ABI regardless of how many other arguments are added in future upgrades. Fixes #310
|
This PR targeted I retargeted it to |
📝 WalkthroughWalkthroughThe ChangesABI Version Detection
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (1)
genlayer_py/contracts/actions.py (1)
604-606: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test case for the name-based detection edge case.
The existing tests (
test_encode_add_transaction_uses_v5_signature_when_abi_has_5_inputsand..._v6_..._when_abi_has_6_inputs) cover the standard 5-input/v5 and 6-input/v6 ABIs, but they don't validate the specific scenario this PR fixes: an ABI with 6+ inputs that does not containvalid_untilshould be detected as v5. Adding such a test would confirm the new name-based logic behaves differently from the old count-based logic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@genlayer_py/contracts/actions.py` around lines 604 - 606, Add a test for the name-based version detection edge case in the transaction encoding tests around encode_add_transaction and the signature selection helper: cover an ABI with 6 or more inputs that does not include valid_until and assert it is detected as v5, not v6. Update the existing test suite near test_encode_add_transaction_uses_v5_signature_when_abi_has_5_inputs and test_encode_add_transaction_uses_v6_signature_when_abi_has_6_inputs to include this scenario so the new input-name logic is exercised instead of the old count-based behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@genlayer_py/contracts/actions.py`:
- Around line 604-606: Add a test for the name-based version detection edge case
in the transaction encoding tests around encode_add_transaction and the
signature selection helper: cover an ABI with 6 or more inputs that does not
include valid_until and assert it is detected as v5, not v6. Update the existing
test suite near
test_encode_add_transaction_uses_v5_signature_when_abi_has_5_inputs and
test_encode_add_transaction_uses_v6_signature_when_abi_has_6_inputs to include
this scenario so the new input-name logic is exercised instead of the old
count-based behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2be5287e-31ee-4ee8-a37c-8e0dcd7429ff
📒 Files selected for processing (1)
genlayer_py/contracts/actions.py
Summary
Replaces a fragile argument-count check with a named-parameter check for detecting the
addTransactionABI version.Problem
This check works accidentally today (Bradbury has 6 args, Asimov has 5), but will silently break if a future protocol upgrade adds a 7th argument — causing an extra positional argument to be supplied and corrupting transaction encoding.
Fixes #310
Fix
This correctly detects the v6 ABI by checking for the presence of the
valid_untilnamed parameter, regardless of how many other arguments are added in future upgrades.Summary by CodeRabbit