Hi all,
I have a little trouble with the Value Assignment.
After the migration I want to console.log the following while running the test:
-owner address
-owner balance
-contract address
-contract balance
So I have written following test code:
const People = artifacts.require("People");
const truffleAssert = require("truffle-assertions");
contract("People", async function(accounts){
let instance;
before(async function(){
instance = await People.deployed();
//beforeEach()
//afterEach()
//after()
});
it("should not create a person with age over 150 years", async function(){
//BEFORE EACH*
// let instance = await People.deployed();
await truffleAssert.fails(instance.createPerson("Bob", 200, 190, {value: web3.utils.toWei("1", "ether" )}), truffleAssert.ErrorType.REVERT);
});
it("should not create a person without payment", async function(){
await truffleAssert.fails(instance.createPerson("Booztb", 50, 190, {value: 1000}, truffleAssert.ErrorType.REVERT));
});
it("should set senior status correctly", async function(){
await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1", "ether" )});
let result = await instance.getPerson();
assert(result.senior === true, "Senior level not set");
});
it("should set age correctly", async function(){
let result = await instance.getPerson();
assert(result.age.toNumber() === 65, "Age not set correctly");
});
it("should not allow anybody aside the owner to delete people", async function(){
await instance.createPerson("jeff", 65, 190, {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 Person", async function(){
let instance = await People.new();
// let instance = await People.deployed();
await truffleAssert.passes(instance.deletePerson(accounts[1], {from: accounts[0]}));
});
it("should check when person is added the balance of the contract will increase", async function(){
await instance.createPerson("jeff", 65, 190, {from: accounts[0], value: web3.utils.toWei("1", "ether" )});
let owner = accounts[0];
let balance = await web3.eth.getBalance(owner);
let contractBalance = People.address;
console.log("deployed address of owner " + owner);
console.log("address of contract " + People.address);
web3.eth.getBalance(contractBalance).then(function(balance){
console.log("Balance of contract " + balance);
})
web3.eth.getBalance(owner).then(function(balance){
console.log("Balance of owner " + balance);
})
})
});
so far everything went well except the contract address was not the one ganache console as well as the ganache app showed after running the migration.
Maybe some can take a look and help.
THX