From 334c039ca53e7a47488e2c3ef75d0876d09e33b6 Mon Sep 17 00:00:00 2001 From: alstjd0921 Date: Fri, 12 Mar 2021 01:27:27 +0900 Subject: [PATCH 01/10] Fix outputTransactionFormatter to support formatting gas limit over 53 bits --- packages/web3-core-helpers/src/formatters.js | 6 +-- test/eth.getBlock.js | 54 ++++++++++---------- test/eth.getTransaction.js | 2 +- test/eth.getTransactionFromBlock.js | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 6f9af04de0d..b1ee5e7f96d 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -238,7 +238,7 @@ var outputTransactionFormatter = function (tx) { if (tx.transactionIndex !== null) tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); tx.nonce = utils.hexToNumber(tx.nonce); - tx.gas = utils.hexToNumber(tx.gas); + tx.gas = outputBigNumberFormatter(tx.gas); tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); tx.value = outputBigNumberFormatter(tx.value); @@ -345,9 +345,9 @@ var inputLogFormatter = function (options) { return utils.fromUtf8(value); }; - if (options === undefined) options = {} + if (options === undefined) options = {}; // If options !== undefined, don't blow out existing data - if (options.fromBlock === undefined) options = {...options, fromBlock: 'latest'} + if (options.fromBlock === undefined) options = {...options, fromBlock: 'latest'}; if (options.fromBlock || options.fromBlock === 0) options.fromBlock = inputBlockNumberFormatter(options.fromBlock); diff --git a/test/eth.getBlock.js b/test/eth.getBlock.js index 1fe66a346da..f9b30ccee16 100644 --- a/test/eth.getBlock.js +++ b/test/eth.getBlock.js @@ -13,13 +13,13 @@ var blockResult = { "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff", "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a", "difficulty": "0x027f07", - "totalDifficulty": "0x027f07", - "size": "0x027f07", + "totalDifficulty": "0x027f07", + "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", - "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], + "transactions": ['0x460cfb8472af2c5fd05b5a2', '0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var formattedBlockResult = { @@ -34,12 +34,12 @@ var formattedBlockResult = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, "timestamp": 1424182926, - "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], + "transactions": ['0x460cfb8472af2c5fd05b5a2', '0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; var blockResultWithTx = { @@ -53,25 +53,25 @@ var blockResultWithTx = { "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff", "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a", "difficulty": "0x027f07", - "totalDifficulty": "0x027f07", - "size": "0x027f07", + "totalDifficulty": "0x027f07", + "size": "0x027f07", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x9f759", "gasUsed": "0x9f759", "timestamp": "0x54e34e8e", "transactions": [{ "status": "mined", - "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", - "nonce":"0x2", + "hash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", + "nonce": "0x2", "blockHash": "0x6fd9e2a26ab", "blockNumber": "0x15df", - "transactionIndex": "0x1", - "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", - "to":"0x85f43d8a49eeb85d32cf465507dd71d507100c1d", - "value":"0x7f110", + "transactionIndex": "0x1", + "from": "0x407d73d8a49eeb85d32cf465507dd71d507100c1", + "to": "0x85f43d8a49eeb85d32cf465507dd71d507100c1d", + "value": "0x7f110", "gas": "0x7f110", - "gasPrice":"0x09184e72a000", - "input":"0x603880600c6000396000f30060", + "gasPrice": "0x09184e72a000", + "input": "0x603880600c6000396000f30060", }], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; @@ -87,24 +87,24 @@ var formattedBlockResultWithTx = { "miner": "0x4E65FDa2159562a496F9f3522f89122A3088497a", "difficulty": '163591', "totalDifficulty": '163591', - "size": 163591, + "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": 653145, "gasUsed": 653145, "timestamp": 1424182926, "transactions": [{ "status": "mined", - "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", + "hash": "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "nonce": 2, "blockHash": "0x6fd9e2a26ab", "blockNumber": 5599, - "transactionIndex": 1, - "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", - "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", + "transactionIndex": 1, + "from": "0x407D73d8a49eeb85D32Cf465507dd71d507100c1", + "to": "0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', - "input":"0x603880600c6000396000f30060", + "input": "0x603880600c6000396000f30060", }], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] }; @@ -114,19 +114,19 @@ var tests = [{ formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', false], result: blockResult, formattedResult: formattedBlockResult, - call: 'eth_'+ method + 'ByHash' -},{ + call: 'eth_' + method + 'ByHash' +}, { args: [436], formattedArgs: ['0x1b4', false], result: blockResult, formattedResult: formattedBlockResult, - call: 'eth_'+ method + 'ByNumber' -},{ + call: 'eth_' + method + 'ByNumber' +}, { args: [436, true], formattedArgs: ['0x1b4', true], result: blockResultWithTx, formattedResult: formattedBlockResultWithTx, - call: 'eth_'+ method + 'ByNumber' + call: 'eth_' + method + 'ByNumber' }]; testMethod.runTests('eth', method, tests); diff --git a/test/eth.getTransaction.js b/test/eth.getTransaction.js index d0fae0de54f..0eeb3a97079 100644 --- a/test/eth.getTransaction.js +++ b/test/eth.getTransaction.js @@ -24,7 +24,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransactionFromBlock.js b/test/eth.getTransactionFromBlock.js index 32260659ac2..eb45b642842 100644 --- a/test/eth.getTransactionFromBlock.js +++ b/test/eth.getTransactionFromBlock.js @@ -26,7 +26,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; From a687dde4909cccbb1ec2b97815d26ef98aa551d4 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Thu, 25 Mar 2021 18:43:13 -0500 Subject: [PATCH 02/10] Update use of hexToNumber to outputBigNumberFormatter --- packages/web3-core-helpers/src/formatters.js | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 6f9af04de0d..23412f38479 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -234,11 +234,11 @@ var inputSignFormatter = function (data) { */ var outputTransactionFormatter = function (tx) { if (tx.blockNumber !== null) - tx.blockNumber = utils.hexToNumber(tx.blockNumber); + tx.blockNumber = outputBigNumberFormatter(tx.blockNumber); if (tx.transactionIndex !== null) - tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); - tx.nonce = utils.hexToNumber(tx.nonce); - tx.gas = utils.hexToNumber(tx.gas); + tx.transactionIndex = outputBigNumberFormatter(tx.transactionIndex); + tx.nonce = outputBigNumberFormatter(tx.nonce); + tx.gas = outputBigNumberFormatter(tx.gas); tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); tx.value = outputBigNumberFormatter(tx.value); @@ -268,11 +268,11 @@ var outputTransactionReceiptFormatter = function (receipt) { } if (receipt.blockNumber !== null) - receipt.blockNumber = utils.hexToNumber(receipt.blockNumber); + receipt.blockNumber = outputBigNumberFormatter(receipt.blockNumber); if (receipt.transactionIndex !== null) - receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); - receipt.cumulativeGasUsed = utils.hexToNumber(receipt.cumulativeGasUsed); - receipt.gasUsed = utils.hexToNumber(receipt.gasUsed); + receipt.transactionIndex = outputBigNumberFormatter(receipt.transactionIndex); + receipt.cumulativeGasUsed = outputBigNumberFormatter(receipt.cumulativeGasUsed); + receipt.gasUsed = outputBigNumberFormatter(receipt.gasUsed); if (_.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); @@ -299,12 +299,12 @@ var outputTransactionReceiptFormatter = function (receipt) { var outputBlockFormatter = function (block) { // transform to number - block.gasLimit = utils.hexToNumber(block.gasLimit); - block.gasUsed = utils.hexToNumber(block.gasUsed); - block.size = utils.hexToNumber(block.size); - block.timestamp = utils.hexToNumber(block.timestamp); + block.gasLimit = outputBigNumberFormatter(block.gasLimit); + block.gasUsed = outputBigNumberFormatter(block.gasUsed); + block.size = outputBigNumberFormatter(block.size); + block.timestamp = outputBigNumberFormatter(block.timestamp); if (block.number !== null) - block.number = utils.hexToNumber(block.number); + block.number = outputBigNumberFormatter(block.number); if (block.difficulty) block.difficulty = outputBigNumberFormatter(block.difficulty); @@ -392,11 +392,11 @@ var outputLogFormatter = function (log) { } if (log.blockNumber !== null) - log.blockNumber = utils.hexToNumber(log.blockNumber); + log.blockNumber = outputBigNumberFormatter(log.blockNumber); if (log.transactionIndex !== null) - log.transactionIndex = utils.hexToNumber(log.transactionIndex); + log.transactionIndex = outputBigNumberFormatter(log.transactionIndex); if (log.logIndex !== null) - log.logIndex = utils.hexToNumber(log.logIndex); + log.logIndex = outputBigNumberFormatter(log.logIndex); if (log.address) { log.address = utils.toChecksumAddress(log.address); From 734ae523f0bf4a0f7d3db8ce07b22ad80c055f42 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 29 Mar 2021 16:49:47 -0500 Subject: [PATCH 03/10] Revert some hexToNumber -> outputBigNumberFormatter changes --- packages/web3-core-helpers/src/formatters.js | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 23412f38479..37950117bc5 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -234,10 +234,10 @@ var inputSignFormatter = function (data) { */ var outputTransactionFormatter = function (tx) { if (tx.blockNumber !== null) - tx.blockNumber = outputBigNumberFormatter(tx.blockNumber); + tx.blockNumber = utils.hexToNumber(tx.blockNumber); if (tx.transactionIndex !== null) - tx.transactionIndex = outputBigNumberFormatter(tx.transactionIndex); - tx.nonce = outputBigNumberFormatter(tx.nonce); + tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); + tx.nonce = utils.hexToNumber(tx.nonce); tx.gas = outputBigNumberFormatter(tx.gas); tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); tx.value = outputBigNumberFormatter(tx.value); @@ -268,9 +268,9 @@ var outputTransactionReceiptFormatter = function (receipt) { } if (receipt.blockNumber !== null) - receipt.blockNumber = outputBigNumberFormatter(receipt.blockNumber); + receipt.blockNumber = utils.hexToNumber(receipt.blockNumber); if (receipt.transactionIndex !== null) - receipt.transactionIndex = outputBigNumberFormatter(receipt.transactionIndex); + receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); receipt.cumulativeGasUsed = outputBigNumberFormatter(receipt.cumulativeGasUsed); receipt.gasUsed = outputBigNumberFormatter(receipt.gasUsed); @@ -301,15 +301,15 @@ var outputBlockFormatter = function (block) { // transform to number block.gasLimit = outputBigNumberFormatter(block.gasLimit); block.gasUsed = outputBigNumberFormatter(block.gasUsed); - block.size = outputBigNumberFormatter(block.size); - block.timestamp = outputBigNumberFormatter(block.timestamp); + block.size = utils.hexToNumber(block.size); + block.timestamp = utils.hexToNumber(block.timestamp); if (block.number !== null) - block.number = outputBigNumberFormatter(block.number); + block.number = utils.hexToNumber(block.number); if (block.difficulty) - block.difficulty = outputBigNumberFormatter(block.difficulty); + block.difficulty = utils.hexToNumber(block.difficulty); if (block.totalDifficulty) - block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); + block.totalDifficulty = utils.hexToNumber(block.totalDifficulty); if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { @@ -392,11 +392,11 @@ var outputLogFormatter = function (log) { } if (log.blockNumber !== null) - log.blockNumber = outputBigNumberFormatter(log.blockNumber); + log.blockNumber = utils.hexToNumber(log.blockNumber); if (log.transactionIndex !== null) - log.transactionIndex = outputBigNumberFormatter(log.transactionIndex); + log.transactionIndex = utils.hexToNumber(log.transactionIndex); if (log.logIndex !== null) - log.logIndex = outputBigNumberFormatter(log.logIndex); + log.logIndex = utils.hexToNumber(log.logIndex); if (log.address) { log.address = utils.toChecksumAddress(log.address); From 5e56b864992df307df8d24aa7ddea632dbe749a8 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 29 Mar 2021 16:51:07 -0500 Subject: [PATCH 04/10] Revert changes to block difficulty --- packages/web3-core-helpers/src/formatters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 37950117bc5..1a35fe5d05c 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -307,9 +307,9 @@ var outputBlockFormatter = function (block) { block.number = utils.hexToNumber(block.number); if (block.difficulty) - block.difficulty = utils.hexToNumber(block.difficulty); + block.difficulty = outputBigNumberFormatter(block.difficulty); if (block.totalDifficulty) - block.totalDifficulty = utils.hexToNumber(block.totalDifficulty); + block.totalDifficulty = outputBigNumberFormatter(block.totalDifficulty); if (_.isArray(block.transactions)) { block.transactions.forEach(function (item) { From 8e8f7491a41d0d0f38dc433c05f15e5059d77951 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 15:32:29 -0500 Subject: [PATCH 05/10] Fix failing tests --- test/formatters.outputBlockFormatter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/formatters.outputBlockFormatter.js b/test/formatters.outputBlockFormatter.js index d6bf27563de..774cf7df2b4 100644 --- a/test/formatters.outputBlockFormatter.js +++ b/test/formatters.outputBlockFormatter.js @@ -33,8 +33,8 @@ describe('formatters', function () { difficulty: '1000', totalDifficulty: '1000', number: 1000, - gasLimit: 1000, - gasUsed: 1000, + gasLimit: '1000', + gasUsed: '1000', timestamp: 1000, extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', @@ -69,8 +69,8 @@ describe('formatters', function () { difficulty: '1000', totalDifficulty: '1000', number: null, - gasLimit: 1000, - gasUsed: 1000, + gasLimit: '1000', + gasUsed: '1000', timestamp: 1000, extraData: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265', nonce: null, From 09a0a63971d7b235b273c9f438a16803d6c03c0d Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 19:00:02 -0500 Subject: [PATCH 06/10] Update expected values to be number strings --- test/contract.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/contract.js b/test/contract.js index 368b7dd8d87..2d01be031b6 100644 --- a/test/contract.js +++ b/test/contract.js @@ -668,11 +668,11 @@ var runTests = function(contractFactory) { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xbf1234', - gasUsed: 0 + gasUsed: '0' }); done(); }); @@ -762,11 +762,11 @@ var runTests = function(contractFactory) { .on('receipt', function(result){ assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xbf1234', - gasUsed: 0 + gasUsed: '0' }); done(); }).catch(console.log); @@ -1899,12 +1899,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: 10, blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: { Unchanged: { address: address, @@ -2062,12 +2062,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! nope: causes a timeout assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: 10, blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: { Changed: [ { @@ -2214,12 +2214,12 @@ var runTests = function(contractFactory) { // wont throw if it errors ?! assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: 10, blockHash: '0x43ffdd', - gasUsed: 0, + gasUsed: '0', events: { Unchanged: { address: address, @@ -2329,12 +2329,12 @@ var runTests = function(contractFactory) { if(count === 1) { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: 10, blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: {} }); @@ -2343,12 +2343,12 @@ var runTests = function(contractFactory) { if(count === 2) { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, transactionHash: '0x1234', blockNumber: 10, blockHash: '0x1234', - gasUsed: 0, + gasUsed: '0', events: {} }); From 5cff1144efd4399f769a5f64f0ea8653b262ca5b Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 19:00:14 -0500 Subject: [PATCH 07/10] Check if defined before formatting --- packages/web3-core-helpers/src/formatters.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 1a35fe5d05c..a59955bb67b 100644 --- a/packages/web3-core-helpers/src/formatters.js +++ b/packages/web3-core-helpers/src/formatters.js @@ -238,9 +238,9 @@ var outputTransactionFormatter = function (tx) { if (tx.transactionIndex !== null) tx.transactionIndex = utils.hexToNumber(tx.transactionIndex); tx.nonce = utils.hexToNumber(tx.nonce); - tx.gas = outputBigNumberFormatter(tx.gas); - tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); - tx.value = outputBigNumberFormatter(tx.value); + if (tx.gas) tx.gas = outputBigNumberFormatter(tx.gas); + if (tx.gasPrice) tx.gasPrice = outputBigNumberFormatter(tx.gasPrice); + if (tx.value) tx.value = outputBigNumberFormatter(tx.value); if (tx.to && utils.isAddress(tx.to)) { // tx.to could be `0x0` or `null` while contract creation tx.to = utils.toChecksumAddress(tx.to); @@ -271,8 +271,8 @@ var outputTransactionReceiptFormatter = function (receipt) { receipt.blockNumber = utils.hexToNumber(receipt.blockNumber); if (receipt.transactionIndex !== null) receipt.transactionIndex = utils.hexToNumber(receipt.transactionIndex); - receipt.cumulativeGasUsed = outputBigNumberFormatter(receipt.cumulativeGasUsed); - receipt.gasUsed = outputBigNumberFormatter(receipt.gasUsed); + if (receipt.cumulativeGasUsed) receipt.cumulativeGasUsed = outputBigNumberFormatter(receipt.cumulativeGasUsed); + if (receipt.gasUsed) receipt.gasUsed = outputBigNumberFormatter(receipt.gasUsed); if (_.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(outputLogFormatter); @@ -297,10 +297,10 @@ var outputTransactionReceiptFormatter = function (receipt) { * @returns {Object} */ var outputBlockFormatter = function (block) { - + // transform to number - block.gasLimit = outputBigNumberFormatter(block.gasLimit); - block.gasUsed = outputBigNumberFormatter(block.gasUsed); + if (block.gasLimit) block.gasLimit = outputBigNumberFormatter(block.gasLimit); + if (block.gasUsed) block.gasUsed = outputBigNumberFormatter(block.gasUsed); block.size = utils.hexToNumber(block.size); block.timestamp = utils.hexToNumber(block.timestamp); if (block.number !== null) From db16c205c723960ef39be93c8bb708dd593788ff Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 19:25:50 -0500 Subject: [PATCH 08/10] Updating to number strings --- test/eth.getBlock.js | 10 +++++----- test/eth.getPendingTransactions.js | 2 +- test/eth.getTransaction.js | 2 +- test/eth.getTransactionFromBlock.js | 2 +- test/eth.getTransactionReceipt.js | 12 ++++++------ test/eth.getUncle.js | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/eth.getBlock.js b/test/eth.getBlock.js index 1fe66a346da..66b50348656 100644 --- a/test/eth.getBlock.js +++ b/test/eth.getBlock.js @@ -36,8 +36,8 @@ var formattedBlockResult = { "totalDifficulty": '163591', "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": 1424182926, "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] @@ -89,8 +89,8 @@ var formattedBlockResultWithTx = { "totalDifficulty": '163591', "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": 1424182926, "transactions": [{ "status": "mined", @@ -102,7 +102,7 @@ var formattedBlockResultWithTx = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060", }], diff --git a/test/eth.getPendingTransactions.js b/test/eth.getPendingTransactions.js index 5cccfd70c5f..d1c305efcd9 100644 --- a/test/eth.getPendingTransactions.js +++ b/test/eth.getPendingTransactions.js @@ -25,7 +25,7 @@ var formattedTx = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransaction.js b/test/eth.getTransaction.js index d0fae0de54f..0eeb3a97079 100644 --- a/test/eth.getTransaction.js +++ b/test/eth.getTransaction.js @@ -24,7 +24,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransactionFromBlock.js b/test/eth.getTransactionFromBlock.js index 32260659ac2..eb45b642842 100644 --- a/test/eth.getTransactionFromBlock.js +++ b/test/eth.getTransactionFromBlock.js @@ -26,7 +26,7 @@ var formattedTxResult = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060" }; diff --git a/test/eth.getTransactionReceipt.js b/test/eth.getTransactionReceipt.js index dabb7f6bb64..fa16418aec7 100644 --- a/test/eth.getTransactionReceipt.js +++ b/test/eth.getTransactionReceipt.js @@ -34,8 +34,8 @@ var formattedTxResult = { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', "logs": [{ id: "log_2b801386", transactionIndex: 1000, @@ -83,8 +83,8 @@ var tests = [{ "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', }, call: 'eth_'+ method },{ @@ -107,8 +107,8 @@ var tests = [{ "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 16, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464, + "cumulativeGasUsed": '520464', + "gasUsed": '520464', }, call: 'eth_'+ method }]; diff --git a/test/eth.getUncle.js b/test/eth.getUncle.js index 31c3a91a948..2fd44b2aa1c 100644 --- a/test/eth.getUncle.js +++ b/test/eth.getUncle.js @@ -36,8 +36,8 @@ var formattedBlockResult = { "totalDifficulty": '163591', "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": 1424182926, "transactions": ['0x460cfb8472af2c5fd05b5a2','0x460cfb8472af2c5fd05b5a2'], "uncles": ["0x460cfb8472af2c5fd05b5a2", "0xd5460cfb8472af2c5fd05b5a2"] @@ -89,8 +89,8 @@ var formattedBlockResultWithTx = { "totalDifficulty": '163591', "size": 163591, "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": 653145, - "gasUsed": 653145, + "gasLimit": '653145', + "gasUsed": '653145', "timestamp": 1424182926, "transactions": [{ // "status": "mined", @@ -102,7 +102,7 @@ var formattedBlockResultWithTx = { "from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address "to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address "value": '520464', - "gas": 520464, + "gas": '520464', "gasPrice": '10000000000000', "input":"0x603880600c6000396000f30060", }], From 0969d45b5706a6e5c0ed887fe30f68ffbfd1a1db Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 20:35:19 -0500 Subject: [PATCH 09/10] Update numbers to number strings --- test/eth.sendTransaction.js | 10 +++++----- test/helpers/test.method.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/eth.sendTransaction.js b/test/eth.sendTransaction.js index 4a77bd8e791..55f380a5d03 100644 --- a/test/eth.sendTransaction.js +++ b/test/eth.sendTransaction.js @@ -129,7 +129,7 @@ var tests = [{ to: '0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', value: '1234567654321', gasPrice: '324234234234', - gas: 500000, + gas: '500000', chain: 'mainnet', hardfork: 'petersburg' }], @@ -156,7 +156,7 @@ var tests = [{ to: '0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', value: '1234567654321', gasPrice: '324234234234', - gas: 500000, + gas: '500000', chain: 'mainnet', hardfork: 'petersburg' }], @@ -186,7 +186,7 @@ var tests = [{ to: '0xdbdbdb2cbd23b783741e8d7fcf51e459b497e4a6', value: '1234567654321', gasPrice: '324234234234', - gas: 500000, + gas: '500000', chain: 'mainnet', hardfork: 'petersburg' }], @@ -291,8 +291,8 @@ describe(method, function () { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464 + "cumulativeGasUsed": '520464', + "gasUsed": '520464' }); } else { assert.deepEqual(result, test.formattedResult); diff --git a/test/helpers/test.method.js b/test/helpers/test.method.js index 3afa2958e5c..c8352cc861c 100644 --- a/test/helpers/test.method.js +++ b/test/helpers/test.method.js @@ -158,8 +158,8 @@ var runTests = function (obj, method, tests) { "transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "transactionIndex": 1, "contractAddress":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address - "cumulativeGasUsed": 520464, - "gasUsed": 520464 + "cumulativeGasUsed": '520464', + "gasUsed": '520464' }); } else { assert.deepEqual(result, test.formattedResult); From 40d34836cc267e0bf15786fc39e260f2e255cd0c Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 30 Mar 2021 20:47:31 -0500 Subject: [PATCH 10/10] Update numbers to num strings --- test/eth.subscribe.js | 4 ++-- test/method.buildCall.js | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/eth.subscribe.js b/test/eth.subscribe.js index 4f2db3b1308..ead73c0b085 100644 --- a/test/eth.subscribe.js +++ b/test/eth.subscribe.js @@ -40,8 +40,8 @@ var tests = [{ difficulty: "24022326322090", totalDifficulty: "24022326322090", extraData: "0xd983010305844765746887676f312e342e328777696e646f7773", - gasLimit: 4712388, - gasUsed: 231000, + gasLimit: '4712388', + gasUsed: '231000', hash: "0x950427f707bf395fda0092d4f5dcbcf32d632106fb08e397124d0726082693e6", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0xf8b483DbA2c3B7176a3Da549ad41A48BB3121069", // checksum address diff --git a/test/method.buildCall.js b/test/method.buildCall.js index f3b769117eb..cfc6e9e28dc 100644 --- a/test/method.buildCall.js +++ b/test/method.buildCall.js @@ -305,11 +305,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -330,11 +330,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -425,11 +425,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -449,11 +449,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: address, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); done(); @@ -832,11 +832,11 @@ describe('lib/web3/method', function () { assert.deepEqual(result, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); }) @@ -844,11 +844,11 @@ describe('lib/web3/method', function () { assert.deepEqual(receipt, { contractAddress: null, - cumulativeGasUsed: 10, + cumulativeGasUsed: '10', transactionIndex: 3, blockNumber: 10, blockHash: '0xafff', - gasUsed: 0 + gasUsed: '0' }); assert.deepEqual(conf, countConf);