Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
28 changes: 14 additions & 14 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {}
});

Expand All @@ -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: {}
});

Expand Down
62 changes: 31 additions & 31 deletions test/eth.getBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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"]
};
Expand All @@ -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"]
};
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/eth.getPendingTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var formattedTx = {
"from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address
"value": '520464',
"gas": 520464,
"gas": '520464',
"gasPrice": '10000000000000',
"input":"0x603880600c6000396000f30060"
};
Expand Down
2 changes: 1 addition & 1 deletion test/eth.getTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var formattedTxResult = {
"from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address
"value": '520464',
"gas": 520464,
"gas": '520464',
"gasPrice": '10000000000000',
"input":"0x603880600c6000396000f30060"
};
Expand Down
2 changes: 1 addition & 1 deletion test/eth.getTransactionFromBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var formattedTxResult = {
"from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address
"value": '520464',
"gas": 520464,
"gas": '520464',
"gasPrice": '10000000000000',
"input":"0x603880600c6000396000f30060"
};
Expand Down
12 changes: 6 additions & 6 deletions test/eth.getTransactionReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
},{
Expand All @@ -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
}];
Expand Down
10 changes: 5 additions & 5 deletions test/eth.getUncle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand All @@ -102,7 +102,7 @@ var formattedBlockResultWithTx = {
"from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address
"value": '520464',
"gas": 520464,
"gas": '520464',
"gasPrice": '10000000000000',
"input":"0x603880600c6000396000f30060",
}],
Expand Down
Loading