-
Notifications
You must be signed in to change notification settings - Fork 9
fix(account): send parses plain integer as wei, not GEN #294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d963e3
fix(account): send parses plain integer as wei, not GEN
MuncleUscles 35686f3
chore(deps): bump genlayer-js to ^1.0.0
MuncleUscles 44c033b
ci(smoke): build the CLI before running smoke tests
MuncleUscles e7e45ed
ci(smoke): create default keystore before running subprocess tests
MuncleUscles 86aece9
ci(smoke): bump test timeout 30s → 90s for slow validator-list fetch
MuncleUscles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
Does JavaScript BigInt(string) accept signed and base-prefixed string inputs such as "-1" and "0x10", and does viem parseEther accept signed decimal strings?💡 Result:
Yes, JavaScript's BigInt(string) accepts signed strings like "-1" and base-prefixed strings like "0x10". No, viem's parseEther does not accept signed decimal strings; while its underlying parseUnits supports negatives technically, parseEther is designed for positive ether amounts in Ethereum transactions, and negative values are invalid for such contexts (e.g., uint256 types). Using negatives would produce a negative BigInt, which cannot be encoded as unsigned transaction data.
Citations:
🏁 Script executed:
Repository: genlayerlabs/genlayer-cli
Length of output: 1900
🏁 Script executed:
Repository: genlayerlabs/genlayer-cli
Length of output: 1603
🏁 Script executed:
Repository: genlayerlabs/genlayer-cli
Length of output: 973
🏁 Script executed:
Repository: genlayerlabs/genlayer-cli
Length of output: 854
Whitelist the amount grammar and update help text.
BigInt(trimmed)accepts signed values (e.g., "-1") and base-prefixed strings (e.g., "0x10"), which contradicts the stated "plain integer → wei" contract. Additionally, the help text at line 99 ofsrc/commands/account/index.tsonly says "Send GEN to an address" without documenting that plain integers are wei and the GEN suffix is required for decimal amounts.Update the validation to explicitly accept only plain positive integers for wei, and update the help text to document the amount format.
🛡️ Proposed validation and help text updates
For
src/commands/account/send.tslines 40–47:const trimmed = amount.trim(); const lower = trimmed.toLowerCase(); if (lower.endsWith("gen")) { - return parseEther(lower.slice(0, -3).trim()); + const genAmount = lower.slice(0, -3).trim(); + if (!/^\d+(?:\.\d+)?$/.test(genAmount)) { + throw new Error("Invalid amount. Use an integer wei value or a decimal GEN value with a GEN suffix."); + } + return parseEther(genAmount); } // Plain integer → wei. BigInt() throws on decimals, which is the intended // failure mode for ambiguous input like "1.5". + if (!/^\d+$/.test(trimmed)) { + throw new Error("Invalid amount. Use an integer wei value or add a GEN suffix for GEN amounts."); + } return BigInt(trimmed);For
src/commands/account/index.tsline 99:📝 Committable suggestion
🤖 Prompt for AI Agents