Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 180ddf9

Browse files
committed
[Quorum] Fix #2766, timestamp is not present on a Quorum node
1 parent 460c554 commit 180ddf9

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

packages/web3-core-helpers/src/Formatters.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ export const outputBlockFormatter = (block) => {
300300
block.gasLimit = Utils.hexToNumber(block.gasLimit);
301301
block.gasUsed = Utils.hexToNumber(block.gasUsed);
302302
block.size = Utils.hexToNumber(block.size);
303-
block.timestamp = Utils.hexToNumber(block.timestamp);
303+
304+
// Support Quorum 2.2.0 - timestamp is not present in the Quorum getBlock response
305+
if (block.timestamp !== null) {
306+
block.timestamp = Utils.hexToNumber(block.timestamp);
307+
}
304308

305309
if (block.number !== null) {
306310
block.number = Utils.hexToNumber(block.number);

packages/web3-core-helpers/tests/src/Formatters/OutputBlockFormatterTest.js

+45
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,49 @@ describe('OutputBlockFormatterTest', () => {
5151
miner: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
5252
});
5353
});
54+
it('[Quorum] call outputBlockFormatter with a valid block without a timestamp', () => {
55+
const block = {
56+
gasLimit: 0x0,
57+
gasUsed: 0x0,
58+
size: 0x0,
59+
number: 0x0,
60+
difficulty: 100,
61+
totalDifficulty: 100,
62+
transactions: [
63+
{
64+
blockNumber: 0,
65+
transactionIndex: 0,
66+
gas: 100,
67+
gasPrice: 100,
68+
nonce: 1,
69+
value: 100,
70+
to: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
71+
from: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
72+
}
73+
],
74+
miner: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
75+
};
76+
77+
expect(outputBlockFormatter(block)).toEqual({
78+
gasLimit: 0x0,
79+
gasUsed: 0x0,
80+
size: 0x0,
81+
number: 0x0,
82+
difficulty: '100', // Strange some numbers will be handled as string and some as number (gas & nonce)
83+
totalDifficulty: '100',
84+
transactions: [
85+
{
86+
blockNumber: 0,
87+
transactionIndex: 0,
88+
gas: 100,
89+
gasPrice: '100',
90+
nonce: 1,
91+
value: '100',
92+
to: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078',
93+
from: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
94+
}
95+
],
96+
miner: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
97+
});
98+
});
5499
});

0 commit comments

Comments
 (0)