_forwardFunds() edited to _burnEther() - test function throws error

Hi,
I've edited Crowdsale.sol => buyTokens() => _fowardFunds() to:

function _burnEther() internal {
	address(0).transfer(msg.value);
}

and when I test it with:

it('should burn Ether', async function () {
  const balanceTracker = await balance.tracker(ZERO_ADDRESS);
  await this.exchange.sendTransaction({ value, from: investor });
  expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
});

where value = ether('1'), it throws error:

  AssertionError: expected '3002058100000000000' to equal '1000000000000000000'

It expects 2.0020581 ETH more. Why does it happens?

1 Like

Hi @3rr0r

It appears to be an issue with ganache-cli increasing the balance of the zero address.

I wrote a test that shows this happening including printing out the balance:

    it('balance tracker', async function () {
        value = ether('1');
        const balanceTracker = await balance.tracker(receiver);
        console.log("Balance: ", await web3.eth.getBalance(receiver));
        await send.ether(sender, receiver, value);
        console.log("Balance: ", await web3.eth.getBalance(receiver));
        expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
    });

    it('balance tracker zero address', async function () {
        value = ether('1');
        const balanceTracker = await balance.tracker(constants.ZERO_ADDRESS);
        console.log("Balance: ", await web3.eth.getBalance(constants.ZERO_ADDRESS));
        await send.ether(sender, constants.ZERO_ADDRESS, value);
        console.log("Balance: ", await web3.eth.getBalance(constants.ZERO_ADDRESS));
        expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
    });

I suggest that you rework your test so it tests the balance of the sender rather than the zero address.

We could ask on the truffle gitter and see what response we get.

1 Like

Hi @3rr0r
Let the community know if you get a resolution to your Gitter question:

Hi @3rr0r did you get any response? It may be worth raising an issue.