Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Align block_helper.toJSON with hashed values #92

Merged
merged 2 commits into from
Apr 12, 2018
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
14 changes: 7 additions & 7 deletions lib/utils/block_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ module.exports = {
number: to.rpcQuantityHexString(block.header.number),
hash: to.hex(block.hash()),
parentHash: to.hex(block.header.parentHash), //common.hash
mixHash: "0x" + (new Array(32).fill("10").join("")), // TODO: Figure out what to do here.
mixHash: to.hex(block.header.mixHash),
nonce: to.rpcDataHexString(to.hex(block.header.nonce), 16),
sha3Uncles: to.hex(block.header.uncleHash),
logsBloom: to.hex(block.header.bloom),
transactionsRoot: to.hex(block.header.transactionsTrie),
stateRoot: to.hex(block.header.stateRoot),
receiptsRoot: to.hex(block.header.receiptTrie),
miner: to.hex(block.header.coinbase),
difficulty: to.hex(block.header.difficulty),
totalDifficulty: to.hex(block.header.difficulty), // TODO: Figure out what to do here.
extraData: to.rpcDataHexString(to.hex(block.header.extraData)),
difficulty: to.rpcQuantityHexString(block.header.difficulty),
totalDifficulty: to.rpcQuantityHexString(block.header.difficulty), // TODO: Figure out what to do here.
extraData: to.rpcDataHexString(block.header.extraData),
size: to.hex(1000), // TODO: Do something better here
gasLimit: to.hex(block.header.gasLimit),
gasUsed: to.hex(block.header.gasUsed),
timestamp: to.hex(block.header.timestamp),
gasLimit: to.rpcQuantityHexString(block.header.gasLimit),
gasUsed: to.rpcQuantityHexString(block.header.gasUsed),
timestamp: to.rpcQuantityHexString(block.header.timestamp),
transactions: block.transactions.map(function(tx) {
if (include_full_transactions) {
return txhelper.toJSON(tx, block);
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/to.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = {

val = new Array(length-val.length).fill("0").join("") + val;
} else {
if(val.length == 0) {
return "0x";
}
val = this.hex(val).replace("0x", "");

if(val.length % 2 != 0) {
Expand Down
7 changes: 7 additions & 0 deletions test/hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ describe("to.rpcQuantityHexString", function() {
});
});

describe("to.rpcDataHexString", function() {
it("should differentiate between a list of 0 items and a list of one 0", function(done) {
assert.notEqual(to.rpcDataHexString(new Buffer("", "hex")), to.rpcDataHexString(new Buffer("00", "hex")));
done();
})
})

function noLeadingZeros(method, result, path) {
if (!path) {
path = 'result'
Expand Down
4 changes: 2 additions & 2 deletions test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ var tests = function(web3) {
var expectedFirstBlock = {
number: 0,
hash: block.hash, // Don't test this one
mixHash: "0x1010101010101010101010101010101010101010101010101010101010101010",
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0000000000000000',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
Expand All @@ -173,7 +173,7 @@ var tests = function(web3) {
miner: '0x0000000000000000000000000000000000000000',
difficulty: "0",
totalDifficulty: "0",
extraData: '0x00',
extraData: '0x',
size: 1000,
gasLimit: 6721975,
gasUsed: 0,
Expand Down