I wasn’t able to get this one on my own unfortunately. I kept trying to plug accounts into the functions in the tests instead of at the top. That resulted in accounts not being defined. After watching the solution, I was easily able to see my mistake.
onlyOwner solution below.
const People = artifacts.require("People");
const truffleAssert = require("truffle-assertions");
contract("People", async function(accounts){
it("shouldn't create a person over 150 age", async function() {
let instance = await People.deployed();
await truffleAssert.fails(instance.createPerson("Bob", 200, 200, {value: web3.utils.toWei("1", "ether")}), truffleAssert.ErrorType.REVERT);
});
it("shouldn't create a person without payment", async function(){
let instance = await People.deployed()
await truffleAssert.fails(instance.createPerson("Bob", 50, 200, {value: 1000}), truffleAssert.ErrorType.REVERT);
});
it("should set senior status correctly", async function(){
let instance = await People.deployed()
await instance.createPerson("Bob", 65, 200, {value: web3.utils.toWei("1", "ether")}), truffleAssert.ErrorType.REVERT;
let result = await instance.getPerson();
assert(result.senior === true, "Senior level not set");
});
it("should set age correctly", async function(){
let instance = await People.deployed();
let result = await instance.getPerson();
assert(result.age.toNumber() === 65, "Age not set correctly");
});
it("should confirm sender is owner", async function(){
let instance = await People.deployed();
await instance.createPerson("Lisa", 35, 160, {from: accounts[1], value: web3.utils.toWei("1", "ether")})
await truffleAssert.fails(instance.deletePerson(accounts[1], {from: accounts[1]}), truffleAssert.ErrorType.REVERT);
});
it("should allow owner to delete people", async function(){
let instance = await People.deployed();
await truffleAssert.passes(instance.deletePerson(accounts[1]), {from: accounts[0]})
});
});```