Unit Testing in Truffle

This works but the error handling is wrong for the second test. Should have used truffleAssert.passes. Oh well I know now. After going over the correct solution I realize I mistook contract owner with account owner. Thanks I learned a lot with this and the second one.

it("Do not allow an account that did not create the person to delete it:", async function(){
  let instance = await People.deployed();
  await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1", "ether"), from: accounts[0]});
  await truffleAssert.fails(instance.deletePerson(accounts[0],{from: accounts[1]}),
truffleAssert.ErrorType.REVERT);
});

it("Only allow the account that created the person to delete it:", async function(){
  let instance = await People.deployed();
  await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1", "ether"), from: accounts[0]});
  await instance.deletePerson(accounts[0],{from: accounts[0]});
  let result = await instance.getPerson( {from: accounts[0]});
  assert(result.name === "", "Person was not deleted!");
});
1 Like

Hi @gabba , thx for comment. After seeing video from Filip I realized that I missed a point how to write tests for this assignement. For the part balanceContractAfter - balanceContractBefore == 1 ether here is code

  it("should check if contract balance is increased by 1 ether", async function(){
    const balanceContractBefore = parseFloat(await web3.eth.getBalance(instance.address))
    await instance.createPerson("Lisa",35,160, { from: addressSender, value: web3.utils.toWei("1", "ether") })
    const balanceContractAfter = parseFloat(await web3.eth.getBalance(instance.address))

    assert((balanceContractAfter - balanceContractBefore) == web3.utils.toWei("1","ether"), "Contract balance not increased by 1 ether!");
  })

but for this part that you’ve said about calculating gas price, I didn’t find solution. How to get gas used from createPerson transaction?

1 Like

Testing to make sure only the owner can delete people:

 it("should not allow non-owner to delete people", async function(){
    let instance = await People.deployed();
    await instance.createPerson("Maya", 25, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.fails(instance.deletePerson(accounts[2], {from: accounts[2]}), truffleAssert.ErrorType.REVERT);
  });
  it("should allow the owner to delete people", async function(){
    let instance = await People.new();
    await instance.createPerson("Maya", 25, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.passes(instance.deletePerson(accounts[1], {from: accounts[0]}));
  });

Edit by @gabba: use the Preformatted text format to display code @Crypto_Jeff :wink:

1 Like

@filip I’m stuck calling “truffle test”. It seems like ganache cannot see the “peopletest.js” file into the test folder.

I tried to reset the contract configuration in ganache (remove and re-add “truffle-config.js”) and re-launched the “migrate --reset” in the terminal, but nothing happened.

Below you can find a screenshot of the error.
Thanks!!

Hi @slavenR

you can get the gas used during your transaction by inspecting the receipt

let tx =  await instance.createPerson("Lisa",35,160, { from: addressSender, value: web3.utils.toWei("1", "ether") })

console.log(tx.receipt.gasUsed);

This value is the amount of gas used so you will have to multiply it by 20000000000, which is the default price per gas unit used by truffle.

1 Like

I think the answers in this topics could help you

Value Assignment code:

  it("should keep track of balance correctly", async function(){
    let instance = await People.new();
    await instance.createPerson("Jason", 23, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});

    let balance = await instance.balance();
    let currentBalance = parseFloat(balance);

    let blockchainBalance = await web3.eth.getBalance(instance.address);

    assert(currentBalance == web3.utils.toWei("1", "ether") && currentBalance == blockchainBalance)
  });
  it("Owner can withdraw balance", async function(){
    let instance = await People.new();
    await instance.createPerson("Joe", 45, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.passes(instance.withdrawAll({from: accounts[0]}));
  });
  it("should not allow a non-owner to withdraw balance", async function(){
    let instance = await People.new();
    await instance.createPerson("Sam", 37, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.fails(instance.withdrawAll({from: accounts[2]}), truffleAssert.ErrorType.REVERT);
  });
  it("owner balance should increase after withdrawal", async function(){
    let instance = await People.new();
    await instance.createPerson("Steve", 29, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});

    let ownerCurrentBalance  = parseFloat(await web3.eth.getBalance(accounts[0]));
    await instance.withdrawAll();
    let ownerBalanceAfter = parseFloat(await web3.eth.getBalance(accounts[0]));
    assert(ownerCurrentBalance < ownerBalanceAfter, "Owners balance did not increase");

  });
  it("should reset balance to 0 after withdrawal", async function(){
    let instance = await People.new();
    await instance.createPerson("Lisa", 35, 160, {from: accounts[2], value: web3.utils.toWei("1", "ether")});

    await instance.withdrawAll();

    let balance = await instance.balance();
    let currentBalance = parseFloat(balance);

    let blockchainBalance = await web3.eth.getBalance(instance.address);

    assert(currentBalance == web3.utils.toWei("0", "ether") && currentBalance == blockchainBalance, "Balance was not 0 or did not match")

  })

1 Like

Thx @gabba for explanation. Here is test if sender address is really decreased by 1 ether.

  it("should check if sender address is decresed by 1 ether", async function(){
    const balanceSenderBefore = parseFloat(await web3.eth.getBalance(addressSender))
    let tx = await instance.createPerson("Lisa",35,160, { from: addressSender, value: web3.utils.toWei("1", "ether") })
    const balanceSenderAfter = parseFloat(await web3.eth.getBalance(addressSender))
    const defaultGasTruffle = 20000000000;
    const gasUsed = tx.receipt.gasUsed;
    let balanceDiff = balanceSenderBefore - (balanceSenderAfter + (gasUsed*defaultGasTruffle))
    assert(balanceDiff == web3.utils.toWei("1", "ether"), "Sender balance wasn't decreased by 1 ether!");
  })
1 Like
const People = artifacts.require('People');
const truffleAssert = require('truffle-assertions');

contract('People', async function (accounts) {
  it('should not create a person with age over 150 years', async function () {
    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 () {
    let instance = await People.deployed();
    await truffleAssert.fails(
      instance.createPerson('Bob', 20, 190, {
        value: 1000,
      }),
      truffleAssert.ErrorType.REVERT
    );
  });

  it('should set senior status correctly', async function () {
    let instance = await People.deployed();
    await instance.createPerson('Bob', 70, 190, {
      value: web3.utils.toWei('1', 'ether'),
    });
    let result = await instance.getPerson();
    assert(result.senior === true, 'Senior status not set');
  });

  it('should set age correctly', async function () {
    let instance = await People.deployed();
    let result = await instance.getPerson();
    assert(result.age.toNumber() === 70, 'Age not set');
  });

  it('should not delete person without sending from contract owner address', async function () {
    let instance = await People.deployed();
    await truffleAssert.fails(
      instance.deletePerson(accounts[0], { from: accounts[1] }),
      truffleAssert.ErrorType.REVERT
    );
  });

  it('should delete person sending from contract owner address', async function () {
    let instance = await People.deployed();
    await instance.deletePerson(accounts[0], { from: accounts[0] });
    let person = await instance.getPerson();
    assert(person.age.toNumber() === 0);
  });
});

1 Like
const People = artifacts.require('People');
const truffleAssert = require('truffle-assertions');

contract('People', async function (accounts) {
  let instance;

  beforeEach(async function () {
    instance = await People.deployed();
  });

  it('should not create a person with age over 150 years', async function () {
    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('Bob', 70, 190, {
        value: 1000,
      }),
      truffleAssert.ErrorType.REVERT
    );
  });

  it('should set senior status correctly', async function () {
    await instance.createPerson('Bob', 70, 190, {
      value: web3.utils.toWei('1', 'ether'),
    });
    let result = await instance.getPerson();
    assert(result.senior === true, 'Senior status not set');
  });

  it('should set age correctly', async function () {
    let result = await instance.getPerson();
    assert(result.age.toNumber() === 70, 'Age not set');
  });

  it('should not delete person without sending from contract owner address', async function () {
    await instance.createPerson('John', 40, 185, {
      from: accounts[5],
      value: web3.utils.toWei('1', 'ether'),
    });
    await truffleAssert.fails(
      instance.deletePerson(accounts[5], { from: accounts[5] }),
      truffleAssert.ErrorType.REVERT
    );
  });

  it('should delete person sending from contract owner address', async function () {
    await truffleAssert.passes(
      instance.deletePerson(accounts[5], { from: accounts[0] })
    );
  });

  it('should have state and blockchain balances increase by the correct amount', async function () {
    let instance = await People.new();
    await instance.createPerson('Bob', 30, 190, {
      from: accounts[0],
      value: web3.utils.toWei('1', 'ether'),
    });

    let stateBalance = await instance.balance();
    let blockchainBalance = await web3.eth.getBalance(instance.address);

    assert(
      web3.utils.fromWei(stateBalance.toString()) === '1' &&
        web3.utils.fromWei(blockchainBalance) === '1'
    );
  });

  it('should not withdraw from non owner address', async function () {
    await truffleAssert.fails(
      instance.withdrawAll({ from: accounts[5] }),
      truffleAssert.ErrorType.REVERT
    );
  });

  it('should withdraw from owner address', async function () {
    await truffleAssert.passes(instance.withdrawAll({ from: accounts[0] }));
  });

  it('should reduce state and blockchain balances by proper amount when withdraw', async function () {
    let instance = await People.new();
    await instance.createPerson('Bob', 30, 190, {
      from: accounts[5],
      value: web3.utils.toWei('1', 'ether'),
    });

    await instance.withdrawAll({ from: accounts[0] });

    let stateBalance = await instance.balance();
    let blockchainBalance = await web3.eth.getBalance(instance.address);

    assert(stateBalance.toString() === '0' && blockchainBalance === '0');
  });

  it('should credit the owners address with proper amount when withdrawing', async function () {
    let instance = await People.new();
    await instance.createPerson('Bob', 30, 190, {
      from: accounts[6],
      value: web3.utils.toWei('1', 'ether'),
    });

    let ownerBalance = await web3.eth.getBalance(accounts[0]);

    await instance.withdrawAll();
    let newBalance = await web3.eth.getBalance(accounts[0]);

    assert(
      parseFloat(ownerBalance) < parseFloat(newBalance),
      'New balance has not increased after withdraw'
    );
  });
});

1 Like

Hey all!
Here are my tests. Looking forward to many more challenges ahead :slight_smile:

contract ("People", async function(accounts){
  --
  --
  --
  it("should delete a person as owner", async function(){
    let instance = await People.deployed();
    await instance.deletePerson(accounts[0]);
    let result = await instance.getPerson();
    assert(result.height.toNumber() === 0, "Person not deleted correctly");
  })
  it("shouldn't allow non-owners to delete a person", async function(){
    let instance = await People.deployed();
    await instance.createPerson("Waffles", 4, 20, {value: web3.utils.toWei("1", "ether")});
    await truffleAssert.fails(instance.deletePerson(accounts[0], {from: accounts[1]}), truffleAssert.ErrorType.REVERT);
  });
});
2 Likes
const People = artifacts.require("People");
const truffleAssert = require("truffle-assertions");

contract ("People", async function(accounts){
  let owner = accounts[0];
  let nonOwner = accounts[1]

  it("shouldnt create a person with age over 150 years", async function(){
    let instance = await People.deployed();
    await truffleAssert.fails(instance.createPerson("Bob", 200, 190, {value: web3.utils.toWei("1", "ether")}), truffleAssert.ErrorType.REVERT);

  });
  it("shouldnt create a person without payment", async function(){
    let instance = await People.deployed();
    await truffleAssert.fails(instance.createPerson("Bob", 50, 190, {value: 1000}), truffleAssert.ErrorType.REVERT);
  });
  it ("should set senior status correctly", async function(){              //promijenit tekst onda
    let instance = await People.deployed();
    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");     // moze se i sve zajedno "true && result.age.toNumber() === 65..."
  });
  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("Only owner can delete accounts", async function(){
    let instance = await People.deployed();
    await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1", "ether")});
    await instance.deletePerson(owner);
    let result = await instance.getPerson();
    assert(result.age == 0, "Person deleted correctly");
});
it("should fail if not owner", async function(){
    let instance = await People.deployed();
    await instance.createPerson("Bob", 64, 190, { value: web3.utils.toWei("1", "ether")});
    await instance.deletePerson(nonOwner);
    let result = await instance.getPerson();
    assert(result.name.length > 0, "Person not deleted");

  });

});
1 Like

Value assigment

it("balance should be increased", async function(){
    let initialBalance = await instance.balance();
    await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1",'ether'), from: accounts[1]});
    let currentBalance= await instance.balance();
    assert(parseInt(currentBalance) === parseInt((parseInt(initialBalance)+parseInt(web3.utils.toWei("1",'ether')))),"it does not update contract balance when adding a new person");
  });
  it("owner can whitdraw balance", async function(){
    await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1", "ether")});
    await truffleAssert.passes(instance.withdrawAll({from: accounts[0]}), "owner cant withdraw");
  });
  it("only the owner can withdraw", async function() {
  await truffleAssert.fails(instance.withdrawAll({from: accounts[1]}));
});
it("balance iz zero after whitdrawal", async function (){
     await instance.createPerson("Bob", 65, 190, {value: web3.utils.toWei("1",'ether')});
     await instance.withdrawAll({from: accounts[0]});
    let currentBalance= await instance.balance();
    assert(parseInt(currentBalance) === 0,"balance in not zero after whitdrawal")
});
1 Like
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("should allow the account owner to delete people", async ()=> {
    await instance.createPerson("Carl", 24, 190, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.passes(instance.deletePerson(accounts[1], {from: accounts[0]}));
  });
  it("shouldn't allow another then the master account to delete people", async ()=> {
    await instance.createPerson("Carl", 24, 190, {from: accounts[2], value: web3.utils.toWei("1", "ether")});
    await truffleAssert.fails(instance.deletePerson(accounts[2], {from: accounts[2]}), truffleAssert.ErrorType.REVERT);
  });


});
1 Like

Only Owner

//Only Owner modifier test

    it("shouldn't delete a person unless called by contract owner", async function() {
        let instance = await People.deployed();
        await truffleAssert.fails(instance.deletePerson(accounts[0], {from: accounts[1]}), truffleAssert.ErrorType.REVERT);
    });

    it("should delete person because its called by contract owner", async function() {
        let instance = await People.deployed();
        await instance.deletePerson(accounts[0], {from: accounts[0]});
        let result = await instance.getPerson();
        assert(result.name === "", "Person has not been deleted");
    })

I didn’t create a new Person, I just used Bob that we created in previous tests.
Bob is made with account[0] so he shouldn’t get deleted in the first test because account[1] is used.
Then he gets deleted in second test. I just watched the video, using truffleAssert.passes is a lot better to use for second test…

==================

Value Testing

async function load_balances(instance) {

        let local = await instance.balance.call(function(err, res) {
            return res;
        });

        let blockchain = await web3.eth.getBalance(instance.address)
        return {local, blockchain}
    };

    

    //Value testing
    it("should increase contract balance and match with local variable's balance", async function() {

        let instance = await People.new(); 
        await instance.createPerson("Lisa", 35, 160, {from: accounts[1], value: web3.utils.toWei("1", "ether")})
        let balances = await load_balances(instance);
        assert(web3.utils.fromWei(balances.blockchain, "ether") >= 1 && balances.blockchain == balances.local, "Eth has not been added to balance for createPerson");
    });

    it("shouldn't allow anyone but the owner to withdraw the balance", async function() {
        await truffleAssert.fails(instance.withdrawAll({from: accounts[1]}), truffleAssert.ErrorType.REVERT);
    });

    it("should allow contract owner to withdraw the balance and balances should go to 0", async function() {
        await truffleAssert.passes(instance.withdrawAll({from: accounts[0]}));
        let balances = await load_balances(instance);
        assert(balances.local + balances.blockchain == 0, "Balances haven't changed to 0 after WithdrawAll")
    });

Ok i completely forgot I can just do instance.balance to get the value of the uint public balance.
It creates getter function. And im relying too much on previous tests, i should be creating new contract and then creating new person to be sure everything is fine.

And I haven’t checked if accounts[0] balance had increased. Everything else is fine i think.

1 Like

Owner Test Assignment:

const People = artifacts.require("People");
const truffleAssert = require("truffle-assertions");

contract("People", async function(accounts){
  it("shouldn't create a person with age over 150 years", async function(){
    let instance = await People.deployed();
    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(){
    let instance = await People.deployed();
    await truffleAssert.fails(instance.createPerson(
      "Bob",100,190,{value: web3.utils.toWei("0.5", "ether")
    }),
    truffleAssert.ErrorType.REVERT);
  });
  it("should set senior status correctly", async function(){
    let instance = await People.deployed();
    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 instance = await People.deployed();
    let result = await instance.getPerson();
    assert(result.age.toNumber() === 65, "Age not set correctly");
  });
  it("should deleted only by the owner", async function(){
    let instance = await People.deployed();
    let owner = accounts[0];
    await instance.deletePerson(owner, {from: owner});
    let result = await instance.getPerson();
    assert(result.age == 0, "Person hasn't been deleted");
  });
  it("shouldn't deletePerson from a normal user", async function(){
    let instance = await People.deployed();
    let owner = accounts[0];
    let user = accounts[1];
    await truffleAssert.fails(instance.deletePerson(owner, {from: user}), truffleAssert.ErrorType.REVERT);
  });
});

1 Like

Thanks Gabba, I’ve tried to follow this tips, but it didn’t work on my Mac. So, at the end, I’ve used the command with sudo, as you explained in the post below. Now it all works! :slight_smile:

1 Like

I keep getting this problem, anyone an idea? @filip

truffle(ganache)> test
Using network ‘ganache’.

Compiling your contracts…

Compiling .\contracts\Ownable.sol

Contract: People
1) should’t create a person with age over 150 years
> No events were emitted

0 passing (184ms)
1 failing

  1. Contract: People
    should’t create a person with age over 150 years :
    TypeError: Cannot read property ‘REVERT’ of undefined
    at Context. (test\PeopleTest.js:7:136)
    at process._tickCallback (internal/process/next_tick.js:68:7)

1
truffle(ganache)> { Error: Returned error: VM Exception while processing transaction: revert Age needs to be below 150 – Reason given: Age needs to be below 150. at PromiEvent (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\promievent.js:6:1)
at TruffleContract.createPerson (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\execute.js:158:1)
at Context. (C:\DOC\eth\PeopleProject\test\PeopleTest.js:7:40)
at process._tickCallback (internal/process/next_tick.js:68:7)
reason: ‘Age needs to be below 150’,
hijackedStack:
‘Error: Returned error: VM Exception while processing transaction: revert Age needs to be below 150 – Reason given: Age needs to be below 150.\n at Object.ErrorResponse (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-helpers\src\errors.js:29:1)\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:140:1\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:112:1\n at XMLHttpRequest.request.onreadystatechange (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)\n at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)\n at XMLHttpRequest._setReadyState (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)\n at XMLHttpRequest._onHttpResponseEnd (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)\n at IncomingMessage. (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:466:23)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)’ }
{ Error: Returned error: VM Exception while processing transaction: revert Age needs to be below 150 – Reason given: Age needs to be below 150. at PromiEvent (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\promievent.js:6:1)
at TruffleContract.createPerson (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\execute.js:158:1)
at Context. (C:\DOC\eth\PeopleProject\test\PeopleTest.js:7:40)
at process._tickCallback (internal/process/next_tick.js:68:7)
reason: ‘Age needs to be below 150’,
hijackedStack:
‘Error: Returned error: VM Exception while processing transaction: revert Age needs to be below 150 – Reason given: Age needs to be below 150.\n at Object.ErrorResponse (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-helpers\src\errors.js:29:1)\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:140:1\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:112:1\n at XMLHttpRequest.request.onreadystatechange (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)\n at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)\n at XMLHttpRequest._setReadyState (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)\n at XMLHttpRequest._onHttpResponseEnd (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)\n at IncomingMessage. (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:466:23)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)’ }

C:\Users\VAIO-PC.config\truffle\compilers\node_modules\soljson-v0.5.12+commit.7709ece9.js:33
(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var __GLOBAL__I_000101=Module["__GLOBAL__I_000101"]=asm["__GLOBAL__I_000101"];var __GLOBAL__sub_I_ABIFunctions_cpp=Module["__GLOBAL__sub_I_ABIFunctions_cpp"]=asm["__GLOBAL__sub_I_ABIFunctions_cpp"];var __GLOBAL__sub_I_ABI_cpp=Module["__GLOBAL__sub_I_ABI_cpp"]=asm["__GLOBAL__sub_I_ABI_cpp"];var __GLOBAL__sub_I_ASTJsonConverter_cpp=Module["__GLOBAL__sub_I_ASTJsonConverter_cpp"]=asm["__GLOBAL__sub_I_ASTJsonConverter_cpp"];var __GLOBAL__sub_I_AST_cpp=Module["__GLOBAL__sub_I_AST_cpp"]=asm["__GLOBAL__sub_I_AST_cpp"];var __GLOBAL__sub_I_ArrayUtils_cpp=Module["__GLOBAL__sub_I_ArrayUtils_cpp"]=asm["__GLOBAL__sub_I_ArrayUtils_cpp"];var __GLOBAL__sub_I_AsmAnalysis_cpp=Module["__GLOBAL__sub_I_AsmAnalysis_cpp"]=asm["__GLOBAL__sub_I_AsmAnalysis_cpp"];var __GLOBAL__sub_I_BMC_cpp=Module["__GLOBAL__sub_I_BMC_cpp"]=asm["__GLOBAL__sub_I_BMC_cpp"];var GLOBAL__sub_I_CHC_cpp=Module["
abort({“reason”:“Age needs to be below 150”,“hijackedStack”:“Error: Returned error: VM Exception while processing transaction: revert Age needs to be below 150 – Reason given: Age needs to be below 150.\n at Object.ErrorResponse (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-helpers\src\errors.js:29:1)\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:140:1\n at C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:112:1\n at XMLHttpRequest.request.onreadystatechange (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)\n at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)\n at XMLHttpRequest._setReadyState (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)\n at XMLHttpRequest._onHttpResponseEnd (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)\n at IncomingMessage. (C:\Users\VAIO-PC\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)\n at IncomingMessage.emit (events.js:203:15)\n at IncomingMessage.EventEmitter.emit (domain.js:466:23)\n at endReadableNT (_stream_readable.js:1143:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)”}). Build with -s ASSERTIONS=1 for more info.

C:\DOC\eth\PeopleProject>

Its hard to tell without the code but make sure that you are using async await properly.
Are you missing await keyword somewhere?

1 Like

The problem starts when I implemen the folowing code: , truffleAssert.errorType.REVERT
without this piece everything is working fine.