Value Assignment:
const People = artifacts.require("People");
const truffleAssert = require("truffle-assertions");
contract("People", async function(accounts){
let instance;
before(async function(){
instance = await People.deployed();
});
it("shouldn't create a persion with age above 150", async function(){
// BEFORE EACH RUNS ON TOP
await truffleAssert.fails(instance.createPerson("Bob", 200, 190, {value: web3.utils.toWei("1", "ether")}), truffleAssert.ErrorType.REVERT);
});
it("shouldn't create a person without payment", async function(){
await truffleAssert.fails(instance.createPerson("Bob", 50, 190, {value: 1000}), truffleAssert.ErrorType.REVERT);
});
it("should set senior status correctly", async function(){
await instance.createPerson("Superman", 90, 190, {value: web3.utils.toWei("1", "ether")});
let boolean = await instance.getPerson();
assert(boolean.senior === true, "Senior level has been set.");
});
it("shouldn't delete the person.", async function(){
await instance.createPerson("Superman", 42, 190, {value: web3.utils.toWei("1", "ether"), from: accounts[4]});
await truffleAssert.fails(instance.deletePerson(accounts[4], {from: accounts[2]}), truffleAssert.ErrorType.REVERT);
});
it("should delete the person.", async function(){
await instance.createPerson("Batman", 45, 187, {value: web3.utils.toWei("1","ether"), from: accounts[1]});
await truffleAssert.fails(instance.deletePerson(accounts[1], {from: accounts[0]}), truffleAssert.ErrorType.REVERT);
});
it("should correctly check the contract's balance is correctly increased", async function(){
let instance = await People.new();
await instance.createPerson("Flash", 23, 189, {from: accounts[4], value: web3.utils.toWei("1","ether")});
let addedBalance = await instance.balance();
let ganacheBalance = await web3.eth.getBalance(instance.address);
assert(addedBalance == ganacheBalance, "Incorrect balance is being added, added balance does not match.");
assert(addedBalance == web3.utils.toWei("1", "ether"));
});
it("shouldn't widthdraw", async function(){
let instance = await People.new();
await instance.createPerson("Green Lantern", 37, 185, {value: web3.utils.toWei("1","ether"), from: accounts[2]});
await truffleAssert.fails(instance.withdrawAll({from: accounts[1]}), truffleAssert.ErrorType.REVERT);
});
it("should widthdraw", async function(){
let instance = await People.new();
await instance.createPerson("Doomsday", 2, 3, {value: web3.utils.toWei("1","ether"), from: accounts[2]});
await truffleAssert.fails(instance.withdrawAll({from: accounts[0]}), truffleAssert.ErrorType.REVERT);
});
});