Skip to content

fix(parse_wei): match WEI key against uppercased currency#1

Open
abhicris wants to merge 1 commit into
create-protocol:mainfrom
abhicris:kcolb/fix-2026-06-01-parse-wei-case
Open

fix(parse_wei): match WEI key against uppercased currency#1
abhicris wants to merge 1 commit into
create-protocol:mainfrom
abhicris:kcolb/fix-2026-06-01-parse-wei-case

Conversation

@abhicris
Copy link
Copy Markdown
Member

@abhicris abhicris commented Jun 1, 2026

Why

parse_wei() uppercases the currency suffix before looking it up in the multiplier dict, but the dict key is lowercase \"wei\". So parse_wei(\"X wei\") and parse_wei(\"X WEI\") both miss the lookup and fall through to the default ETH multiplier — returning X * 10**18 instead of X.

The existing test in tests/test_payment_protocol.py already asserts the correct behavior:

```python
assert parse_wei("1000000000000000000 wei") == 10**18
```

…but the test currently fails (or has never been run against this code path) because the function returns 10**36. One-character fix: change the dict key to \"WEI\" so the existing .get(currency.upper(), …) lookup hits.

This mirrors the upstream kcolbchain/switchboard fork. AgentEscrow's amount parsing in client tooling needs to be exact for protocol-level escrow accounting.

Diff

1 line changed, no new files.

The multiplier lookup uppercases the currency suffix, but the dict had a
lowercase 'wei' key, so 'X wei' fell through to the default ETH multiplier
and returned X * 10**18 instead of X.

The existing test_parse_wei case 'parse_wei("1000000000000000000 wei") == 10**18'
asserts the correct behavior — this fix makes it actually hold.
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.

1 participant