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

Handle invalid block numbers in eth_getTransactionCount #291

Merged
merged 2 commits into from
Feb 20, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/blockchain_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ BlockchainDouble.prototype.getBlock = function(number, callback) {
return this.latestBlock(callback);
} else if (number === "earliest") {
return this.data.blocks.first(callback);
} else {
process.nextTick(callback, new Error("Invalid `blockNumber`: \"" + number + "\""));
}
}
};
Expand Down
29 changes: 27 additions & 2 deletions test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,34 @@ const tests = function(web3) {
const result = await web3.eth.getTransactionCount("0x1234567890123456789012345678901234567890");
assert.strictEqual(result, 0);
});
});

describe("eth_getTransactionCount", function() {
it("should fail when given an invalid blockNumber", (done) => {
const provider = web3.currentProvider;
provider.send(
{
jsonrpc: "2.0",
method: "eth_getTransactionCount",
params: [
accounts[0],
"" // this is in invalid blockNumber
],
id: new Date().getTime()
},
function(err, result) {
if (err) {
// Ganache provider responds with an `err`, so check that, too.
assert.strictEqual(err.message, "Invalid `blockNumber`: \"\"");
}
if (result.error) {
assert.strictEqual(result.error.message, "Invalid `blockNumber`: \"\"");
} else {
assert.fail("eth_getTransactionCount did not return an error message for invalid data");
}
done();
}
);
});

it("should return null for non-existent block", async function() {
const result = await web3.eth.getTransactionCount("0x1234567890123456789012345678901234567890", 9999999);
assert.strictEqual(result, null, "Should return null for non-existent block (GETH)");
Expand Down