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

Commit be09b49

Browse files
authored
Merge branch 'trufflesuite:develop' into feat/forked-logs
2 parents 4a65345 + 2becf31 commit be09b49

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/chains/ethereum/ethereum/src/api.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,14 +1274,12 @@ export default class EthereumApi implements Api {
12741274
@assertArgLength(1)
12751275
async eth_getBlockTransactionCountByHash(hash: DATA) {
12761276
const { blocks } = this.#blockchain;
1277-
const blockNum = await blocks.getNumberFromHash(hash);
1278-
if (!blockNum) return null;
1279-
1280-
const rawBlock = await blocks.getRawByBlockNumber(Quantity.from(blockNum));
1281-
if (!rawBlock) return null;
1282-
1283-
const [, rawTransactions] = decode<GanacheRawBlock>(rawBlock);
1284-
return Quantity.from(rawTransactions.length);
1277+
const block = await blocks
1278+
.getByHash(hash)
1279+
.catch<Block>(_ => null);
1280+
if (!block) return null;
1281+
const transactions = block.getTransactions();
1282+
return Quantity.from(transactions.length);
12851283
}
12861284

12871285
/**

src/chains/ethereum/ethereum/tests/forking/block.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,12 @@ describe("forking", function () {
8484
const block = await provider.send("eth_getBlockByNumber", ["0x0", true]);
8585
assert.deepStrictEqual(block, block0);
8686
});
87+
88+
it("should get transaction count by hash from the original chain", async () => {
89+
const block = await provider.send("eth_getBlockByNumber", ["0xB443", true]);
90+
const blockTransactionCountByHash = await provider.send("eth_getBlockTransactionCountByHash", [block.hash]);
91+
assert.deepStrictEqual(block.transactions.length, parseInt(blockTransactionCountByHash));
92+
});
93+
8794
});
8895
});

0 commit comments

Comments
 (0)