Skip to content

Commit 0e30bf3

Browse files
committed
fix(@embark/test-runner): fix reporter to only catch gas for txs
Before, we added the gas for all receipts that came in because they had a `gasUsed`, instead of adding the gas for receipts that came with a transaction
1 parent a016fa8 commit 0e30bf3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/stack/test-runner/src/lib/reporter.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const chalk = require('chalk');
2+
const { blockchain: blockchainConstants } = require('embark-core/constants');
23

34
class Reporter {
45
constructor(embark, options) {
@@ -9,17 +10,32 @@ class Reporter {
910
this.fails = 0;
1011
this.gasAccumulator = 0;
1112

13+
// Keep track of TXs because otherwise, we can intercept random receipts
14+
this.transactionsHashes = [];
15+
1216
this.wireGasUsage();
1317
}
1418

1519
wireGasUsage() {
1620
const {events} = this.embark;
1721
events.on('blockchain:proxy:response', (params) => {
18-
const { result } = params.response;
22+
if (params.request.method === blockchainConstants.transactionMethods.eth_sendTransaction) {
23+
// We just gather data and wait for the receipt
24+
return this.transactionsHashes.push(params.response.result);
25+
} else if (params.request.method === blockchainConstants.transactionMethods.eth_sendRawTransaction) {
26+
return this.transactionsHashes.push(params.response.result);
27+
}
1928

29+
const {result} = params.response;
2030
if (!result || !result.gasUsed) {
2131
return;
2232
}
33+
const hashIndex = this.transactionsHashes.indexOf(result.transactionHash);
34+
if (hashIndex === -1) {
35+
// Probably just a normal receipt
36+
return;
37+
}
38+
this.transactionsHashes.splice(hashIndex, 1);
2339

2440
const gas = parseInt(result.gasUsed, 16);
2541
this.gasAccumulator += gas;

0 commit comments

Comments
 (0)