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

Commit

Permalink
Fix getBlockTransactionCountByNumberFormat so it returns the right fo…
Browse files Browse the repository at this point in the history
…rmat (#414)
  • Loading branch information
davidmurdoch committed Apr 15, 2019
1 parent aa33028 commit 698f007
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ GethApiDouble.prototype.eth_getBlockTransactionCountByNumber = function(blockNum
}
return callback(err);
}
callback(null, block.transactions.length);
callback(null, to.rpcQuantityHexString(block.transactions.length));
});
};

Expand Down
27 changes: 19 additions & 8 deletions test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const fs = require("fs");
const to = require("../lib/utils/to");
const _ = require("lodash");
const pify = require("pify");
const generateSend = require("./helpers/utils/rpc");

const source = fs.readFileSync("./test/contracts/examples/Example.sol", { encoding: "utf8" });
const compilationResult = solc.compile(source, 1);
Expand Down Expand Up @@ -55,8 +56,10 @@ const contract = {
const tests = function(web3) {
let accounts;
let personalAccount;
let send;

before("create and fund personal account", async function() {
send = generateSend(web3.currentProvider);
accounts = await web3.eth.getAccounts();
accounts = accounts.map(function(val) {
return val.toLowerCase();
Expand Down Expand Up @@ -234,9 +237,13 @@ const tests = function(web3) {
it("should return the number of transactions given the block number (0 transactions)", async function() {
// Block 0 should have 0 transactions as per test eth_getBlockByNumber
const block = await web3.eth.getBlock(0, true);
const blockTransactionCount = await web3.eth.getBlockTransactionCount(0);
assert.strictEqual(block.transactions.length, blockTransactionCount, "Block transaction count should be 0.");
assert.strictEqual(0, blockTransactionCount, "Block transaction count should be 0.");
const blockTransactionCount = await send("eth_getBlockTransactionCountByNumber", 0);
assert.strictEqual(
block.transactions.length,
parseInt(blockTransactionCount.result),
"Block transaction count should be 0."
);
assert.strictEqual(blockTransactionCount.result, "0x0", "Block transaction count should be 0.");
});

it("should return the number of transactions given the block number (1 transaction)", async function() {
Expand All @@ -256,14 +263,18 @@ const tests = function(web3) {
assert.deepStrictEqual(txHash.length, 66);

const block = await web3.eth.getBlock("latest", true);
const blockTransactionCount = await web3.eth.getBlockTransactionCount(block.number);
assert.strictEqual(block.transactions.length, blockTransactionCount, "Tx count should equal block tx's length.");
assert.strictEqual(1, blockTransactionCount, "Block transaction count should be 1.");
const blockTransactionCount = await send("eth_getBlockTransactionCountByNumber", block.number);
assert.strictEqual(
block.transactions.length,
parseInt(blockTransactionCount.result),
"Tx count should equal block tx's length."
);
assert.strictEqual(blockTransactionCount.result, "0x1", "Block transaction count should be 1.");
});

it("should return null transactions when the block doesn't exist", async function() {
const blockTransactionCount = await web3.eth.getBlockTransactionCount(1000000);
assert.strictEqual(null, blockTransactionCount, "Block transaction count should be null.");
const blockTransactionCount = await send("eth_getBlockTransactionCountByNumber", 1000000);
assert.strictEqual(blockTransactionCount.result, null, "Block transaction count should be null.");
});
});

Expand Down

0 comments on commit 698f007

Please sign in to comment.