ThisAs I've mentioned in the comments, there are a number of problems in your code:
- Calling
parseInt(res)
may lead to an incorrect result, sinceres
is aBigNumber
possibly larger thanNumber.MAX_SAFE_INTEGER
- Using
1000000000000000000
may lead to an incorrect result, since it is larger thanNumber.MAX_SAFE_INTEGER
I'm not sure what exactly the cause of your failure, since I always use async
/await
instead of then
where possible.
But in any case, this seems to be working fine:
contract("Sale", function(accounts) {
let sale;
let fromAddr = accounts[0];
let amountToSend = "1000000000000000000";
before(async function() {
sale = await artifacts.require("Sale").new();
});
it("Test if can be payed", async function() {
let res = await web3.eth.sendTransaction({
from: fromAddr,
to: sale.address,
value: amountToSend
});
// if we reach here then the transaction has completed successfully
});
it("Test if contract received ether", async function() {
let res = await web3.eth.getBalance(sale.address);
assert(res.greaterThanOrEqualTo(amountToSend));
});
it("Catch if balanceOf "+fromAddr, async function() {
let res = await sale.balanceOf.call(fromAddr);
assert(res.greaterThanOrEqualTo(1));
});
});