Skip to content

Commit

Permalink
fix(@embark/test-runner): fix reporter to only catch gas for txs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrainville committed Feb 7, 2020
1 parent a016fa8 commit 0e30bf3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/stack/test-runner/src/lib/reporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const chalk = require('chalk');
const { blockchain: blockchainConstants } = require('embark-core/constants');

class Reporter {
constructor(embark, options) {
Expand All @@ -9,17 +10,32 @@ class Reporter {
this.fails = 0;
this.gasAccumulator = 0;

// Keep track of TXs because otherwise, we can intercept random receipts
this.transactionsHashes = [];

this.wireGasUsage();
}

wireGasUsage() {
const {events} = this.embark;
events.on('blockchain:proxy:response', (params) => {
const { result } = params.response;
if (params.request.method === blockchainConstants.transactionMethods.eth_sendTransaction) {
// We just gather data and wait for the receipt
return this.transactionsHashes.push(params.response.result);
} else if (params.request.method === blockchainConstants.transactionMethods.eth_sendRawTransaction) {
return this.transactionsHashes.push(params.response.result);
}

const {result} = params.response;
if (!result || !result.gasUsed) {
return;
}
const hashIndex = this.transactionsHashes.indexOf(result.transactionHash);
if (hashIndex === -1) {
// Probably just a normal receipt
return;
}
this.transactionsHashes.splice(hashIndex, 1);

const gas = parseInt(result.gasUsed, 16);
this.gasAccumulator += gas;
Expand Down

0 comments on commit 0e30bf3

Please sign in to comment.