fix(generate): pass owner and legal name in the right order - #339
venugopalanvip wants to merge 2 commits into
Conversation
generate_descriptor called _generate_metadata(legal_name, owner, url)
against a signature of (owner, legal_name, url), so the two swapped:
--owner landed in metadata.info.legalName and --legal-name in
metadata.owner.
Generating with only --owner therefore dropped the value entirely. info
is built when a legal name and a url are both present, and with the
arguments swapped the owner stood in for the legal name, so a caller
passing --owner alone got metadata {} and no error.
Also builds info when either a legal name or a url is given, rather than
only when both are. Without that, correcting the swap would silently drop
a url supplied alongside --owner, which is the common case. OwnerInfo
requires a legal name, so the display name stands in when only a url is
supplied.
Adds three tests over the existing local ABI fixture, asserting where
owner, legal_name and url land. They fail on the previous behaviour with
"assert 'Legal Name Ltd' == 'Display Name'" and "assert None ==
'Display Name'".
Closes LedgerHQ#338
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
This is also a |
Two problems in the previous commit, both in `_generate_metadata`. `OwnerInfo.url` is a required field, so relaxing the guard to `legal_name is not None or url is not None` created a path where `--legal-name` without `--url` raised a pydantic ValidationError instead of generating a descriptor. The guard now turns on the url, which is what `OwnerInfo` actually needs, and keeps the display-name fallback that was the point of the change: `--owner` with `--url` and no legal name fills `legalName` from the owner rather than dropping the url. The nested `if` that ruff flagged as SIM102 is gone with it -- the condition is a single expression again. `tests/generate/test_generate.py` gains the case that was missing: a legal name with no url leaves `metadata.info` unset rather than raising. It fails against the previous commit. The existing url case now also asserts what `legalName` fell back to, which nothing checked before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Understood on v1 — and thanks, that prompted a re-read that found a real problem in my own patch. The patch as it stood could crash. My three tests had all supplied a url, so none of them reached it. There is now a case that does, and it fails against On v1: happy to close this if you would rather not carry it. One thing to weigh first — So: merge as a stopgap, or close and let it go with v1? Your call — I'm not attached to it, and I'll keep to v2 paths for anything new. |
Indeed, |
|
Makes sense — closing. #338 stays open as the record, so whoever picks up the v2 port of Thanks for the quick reviews on both of these. |
Closes #338.
The bug
generate_descriptorcalls_generate_metadatawith its first two arguments transposed:So
--ownerlands inmetadata.info.legalNameand--legal-nameinmetadata.owner:$ erc7730 generate --chain-id 1 --address 0xae78…6393 \ --owner "Rocket Pool" --legal-name "Rocket Pool Ltd" --url "https://rocketpool.net"And because
infowas only built when a legal name and a url were both present, generating with--owneralone dropped the value completely and silently:$ erc7730 generate --chain-id 1 --address 0xae78…6393 --owner "Rocket Pool""metadata": {}That is the flag a first-time contributor is most likely to reach for, and it fails without any error.
The fix
Two lines, one consequential.
The swap. Arguments now match the signature.
The
and. Correcting the swap alone would introduce a regression:--owner X --url Ycurrently producesinfo(because the owner stood in for the legal name), and after the swap it would produce none — silently dropping the url in the common case. Soinfois now built when either is given.OwnerInfo.legalNameis required, so the display name stands in when only a url is supplied.--owner X{}{"owner": "X"}--owner X --url Y{"info": {"legalName": "X", "url": "Y"}}{"owner": "X", "info": {"legalName": "X", "url": "Y"}}--owner X --legal-name Z --url Y{"owner": "Z", "info": {"legalName": "X", …}}{"owner": "X", "info": {"legalName": "Z", …}}Tests
Three cases added to
tests/generate/test_generate.py, using the existing local ABI fixture so they need no network. The existing suite passesowner=labelbut never asserts where it lands, which is how this survived.They fail on the previous behaviour exactly as reported:
and pass with the fix.
pytest tests/generate --run-v1is green: 19 passed.One note
These tests inherit the file's
pytestmark = pytest.mark.v1, so they are skipped unless--run-v1is passed.generate_descriptorbuildserc7730.model.inputv1 models, which is also why its output carriesmetadata.info.legalName— a field the registry's published v2 schema rejects withadditionalProperties: false. That mismatch is the other half of #338 and is a larger change than this one, so I have left it alone; happy to look at it separately if that would be useful.🤖 Generated with Claude Code