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

Commit

Permalink
Merge branch 'trufflesuite:develop' into feat/forked-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored Feb 27, 2023
2 parents 4a65345 + 2becf31 commit be09b49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,14 +1274,12 @@ export default class EthereumApi implements Api {
@assertArgLength(1)
async eth_getBlockTransactionCountByHash(hash: DATA) {
const { blocks } = this.#blockchain;
const blockNum = await blocks.getNumberFromHash(hash);
if (!blockNum) return null;

const rawBlock = await blocks.getRawByBlockNumber(Quantity.from(blockNum));
if (!rawBlock) return null;

const [, rawTransactions] = decode<GanacheRawBlock>(rawBlock);
return Quantity.from(rawTransactions.length);
const block = await blocks
.getByHash(hash)
.catch<Block>(_ => null);
if (!block) return null;
const transactions = block.getTransactions();
return Quantity.from(transactions.length);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/chains/ethereum/ethereum/tests/forking/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,12 @@ describe("forking", function () {
const block = await provider.send("eth_getBlockByNumber", ["0x0", true]);
assert.deepStrictEqual(block, block0);
});

it("should get transaction count by hash from the original chain", async () => {
const block = await provider.send("eth_getBlockByNumber", ["0xB443", true]);
const blockTransactionCountByHash = await provider.send("eth_getBlockTransactionCountByHash", [block.hash]);
assert.deepStrictEqual(block.transactions.length, parseInt(blockTransactionCountByHash));
});

});
});

0 comments on commit be09b49

Please sign in to comment.