-
Notifications
You must be signed in to change notification settings - Fork 684
Fix getTransactionCount leading zeros in hex string #32
Fix getTransactionCount leading zeros in hex string #32
Conversation
@@ -13,7 +13,6 @@ var async = require("async"); | |||
var BlockchainDouble = require("./blockchain_double.js"); | |||
var ForkedBlockchain = require("./utils/forkedblockchain.js"); | |||
var Web3 = require('web3'); | |||
var async = require("async"); |
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.
Removed because it's already present at line 12
From https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding: "When encoding QUANTITIES (integers, numbers): encode as hex, prefix with '0x', the most compact representation (slight exception: zero should be represented as '0x0'). Examples:" "WRONG: 0x0400 (no leading zeroes allowed)"
Hello, thank you for working on this! Would you mind also merging in some tests I wrote for this? |
Add tests for leading zeros in hex values
@attente thanks for writing the tests. Merged. |
@natanrolnik & @attente thanks for teaming up on this one! |
I have same problem as you, can you help me how to deal with leading zero in raw-transaction? including: |
As described here (emphasis mine):
The implementation of
getTransactionCount
would encode numbers including a leading zero, for example:4
would become0x04
instead of the correct way0x4
.This PR fixes it, and also fixes the function
hexWithoutLeadingZeroes
inlib/utils/to.js
to correctly convert0
to0x0
instead of0x
(which would lead to an exception in Web3js when creating a BigNumber, more specifically at line 363).I tried to add a test for this change, but as Web3 already returns the decoded number, I wasn't able to find the right place to check that the hex string is returned correctly.
Related issues and PRs that might related to this PR: