Skip to content

Commit

Permalink
fix: root-level after hook in TestStatus (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShookLyngs authored Jul 26, 2022
1 parent d1cdb3b commit 81ebc9c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions contracts/test/TestStatus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ethers, config, network } = require("hardhat");
const { expect } = require("chai");

let startingBalances = [];
const startingBalances = {};

before("Before testing",() => {
it("Check the Godwoken network version", () => {
Expand All @@ -20,27 +20,26 @@ before("Before testing",() => {

it("Record signers' starting balance", async () => {
const signers = await ethers.getSigners();
startingBalances = await Promise.all(signers.map(signer => signer.getBalance()));
for (let i = 0; i < signers.length; i++) {
const signer = signers[i];
startingBalances[signer.address] = await signer.getBalance();
}
});
});

after(async () => {
const signers = await ethers.getSigners();
const signersBalances = await Promise.all(signers.map(signer => signer.getBalance()));
const finalBalances = signers.map((signer, index) => {
const spent = signersBalances[index].sub(startingBalances[index]);

console.log('Total capacity spent in the test run:');
signers.forEach((signer, index) => {
const balance = signersBalances[index];
const balanceEther = ethers.utils.formatEther(balance);
const startingBalance = startingBalances[signer.address] || balance;
const spent = balance.sub(startingBalance);
const spentEther = ethers.utils.formatEther(spent);
const mark = spent.gte(0) ? '+' : '';
return {
address: signer.address,
spentEther,
spent,
mark,
};
});

console.log('Total capacity changed in the test run:');
finalBalances.forEach((row) => {
console.log(`${row.address} spent ${row.mark}${row.spentEther} pCKB (${row.spent} capacity)`);
console.log(`${signer.address} spent: ${mark}${spentEther} pCKB (${spent}), balance: ${balanceEther} pCKB`);
});
});
});

0 comments on commit 81ebc9c

Please sign in to comment.