This was a bit hard to understand, you have to keep the false positives and the positive false separated.
This is my code:
it("should not be able to delete person if not the owner", async function () {
let instance = await People.deployed();
await instance.createPerson("Bob", 50, 190, {value: web3.utils.toWei("1", "ether"),from: accounts[0]})
let persn = await instance.getPerson({ from: accounts[0] });
assert(persn.name === "Bob", "Person not created")
await
truffleAssert.fails(
instance.deletePerson(accounts[0], { from: accounts[0] }
), truffleAssert.ErrorType.REVERT
);
let person = await instance.getPerson({from: accounts[0]});
assert(person.name === "BoB", "Person deleted");
});
it("should not be able to delete person if not the owner", async function () {
let instance = await People.deployed();
await instance.createPerson("Bob", 50, 190, {
value: web3.utils.toWei("1", "ether"),
from: accounts[0],
});
let persn = await instance.getPerson({ from: accounts[0] });
assert(persn.name === "Bob", "Person not created");
await truffleAssert.fails(
instance.deletePerson(accounts[0], { from: accounts[1] }),
truffleAssert.ErrorType.REVERT
);
let person = await instance.getPerson({ from: accounts[0] });
assert(person.name === "BoB", "Person deleted");
});
and the last:
/// ADD BALANCE CORRECTLY TO CONTRACT
it("should increase balance on the contract", async function () {
await instance.createPerson("Alice", 29, 160, {
from: accounts[3],
value: web3.utils.toWei("1", "ether"),
});
let bal1 = await instance.balance();
let bal2 = await web3.eth.getBalance(instance.address);
assert(parseFloat(bal1) === parseFloat(bal2), "Balance is not the same");
});
/// The owner of the contract can withdraw
it("owner can withdraw from the contract", async function () {
await instance.createPerson("Alice", 29, 160, {
from: accounts[3],
value: web3.utils.toWei("2", "ether"),
});
await truffleAssert.passes(
instance.withdrawAll({ from: accounts[0] }),
truffleAssert.ErrorType.REVERT
);
});
///Non-owner of the contract can not withdraw
it("Non-owner can not withdraw from the contract", async function () {
await instance.createPerson("Alice", 29, 160, {
from: accounts[3],
value: web3.utils.toWei("2", "ether"),
});
await truffleAssert.fails(
instance.withdrawAll({ from: accounts[3] }),
truffleAssert.ErrorType.REVERT
);
});
///Balance reset
it("Balance should reset to 0 after withdrawal", async function () {
await instance.createPerson("Alice", 29, 160, {
from: accounts[4],
value: web3.utils.toWei("1", "ether"),
});
await instance.withdrawAll();
let bal2 = await instance.balance();
assert(parseFloat(bal2) === 0, "Balance is not 0");
});