@filip - Looks like this was a bone-headed mistake on my part. Here was the output without converting to gwei:
AS WEI
owner start bal: 97892192780000000000
amt paid: 1000000000000000000
gas cost: 390160000000000
owner end bal: 98891802620000000000
1) should withdraw balance
- Contract: People
should withdraw balance:
Error: Number can only safely store up to 53 bits
at assert (node_modules\bn.js\lib\bn.js:6:21)
So the issue is that I had converted everything to BigNumbers but was still trying to convert the targetAmt to a number
assert(ownerAmt == targetAmt.toNumber(), "Owner âŚ
Once I removed the toNumber() call, this test passed fine using WEI values. So the complete working test that includes capturing the amount spent in gas is:
it("should withdraw balance", async function(){
// Reset contract
let instance = await People.new();
let ownerStartBalance = await web3.eth.getBalance(accounts[0]);
let amt = web3.utils.toWei("1", "ether");
// Add person using account 1
await instance.createPerson("Clem", 25, 160, {value: amt, from: accounts[1]});
// Get contract balance
let contractBalance = await web3.eth.getBalance(instance.address);
// Make sure that the amount paid was recorded.
assert(contractBalance === amt, "Contract balance should equal amount paid.");
// Withdraw Balance, capture txInfo.
const txInfo = await instance.withdrawAll({from: accounts[0]});
// Get gas used
const tx = await web3.eth.getTransaction(txInfo.tx);
// Calculate gas cost.
let gasCost = new BN(tx.gasPrice, 10).mul(new BN(txInfo.receipt.gasUsed, 10));
// Get contract balance
contractBalance = await web3.eth.getBalance(instance.address);
// Account balanace should now be 0
assert(contractBalance == 0, "Contract balanace should be 0.");
// Get owner's current balanace.
let ownerAmt = await web3.eth.getBalance(accounts[0]);
// Calculate target amount
let targetAmt = new BN(ownerStartBalance, 10).add(new BN(amt, 10)).sub(new BN(gasCost, 10));
// Owner amount should equal ownerStartAmount + amt
// Due to rounding this check could give false negatives.
assert(ownerAmt == targetAmt, "Owner amount should now equal " + targetAmt + " but is " + ownerAmt);
});