StephenGrider / EthereumCasts

Companion repo to an Ethereum/Solidity course on Udemy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arithmetic performed on String results of toWei in Lottery.test.js

samsidx opened this issue · comments

Following code in Lotter.test.js should explicitly convert output of web3.utils.toWei to int as parseInt(await web3.utils.toWei('0.01', 'ether'). I understand the type casting implicit conversion but for pedagogical purpose above seems more helpful.

it('sends money to the winner and resets the players array', async () => {
    await lottery.methods.enter().send({
      from: accounts[0],
      value: web3.utils.toWei('2', 'ether')
    });

    const initialBalance = await web3.eth.getBalance(accounts[0]);
    await lottery.methods.pickWinner().send({ from: accounts[0] });
    const finalBalance = await web3.eth.getBalance(accounts[0]);
    const difference = finalBalance - initialBalance;

    assert(difference > web3.utils.toWei('1.8', 'ether'));
  });