diff --git a/packages/web3-core-helpers/src/formatters.js b/packages/web3-core-helpers/src/formatters.js index 6f9af04de0d..5e472211dc3 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 = utils.hexToNumber(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 = utils.hexToNumber(receipt.cumulativeGasUsed); - receipt.gasUsed = utils.hexToNumber(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 = utils.hexToNumber(block.gasLimit); - block.gasUsed = utils.hexToNumber(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) @@ -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/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: {} }); diff --git a/test/eth.getBlock.js b/test/eth.getBlock.js index 1fe66a346da..9f6beb59139 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, + "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, + "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.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", }], 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/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/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, 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); 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);