Introduction to Unit Testing

@Karolis_Abramavicius Thank you so much… This was very easy to follow and helps a lot! :+1: :hugs:

1 Like

I had to downgrade node js from 12 to 10.16.0.

Here’s the link on how to change versions if your’e on a Mac.

1 Like

Can anyone help me with this error when i run the test?


pragma solidity 0.5.12;

contract Helloworld {
  string message = "Hello World!";

  function getMessage() public view returns (string memory) {
    return message;
  function setMessage(string memory newMessage) public payable {
  message = message;


const Helloworld = artifacts.require("Helloworld");

module.exports = function(deployer, network, accounts){
      instance.setMessage("Hello Again!", {value: 1000000, from: accounts[0]}).then(function(){
        console.log("error: " + err);
    console.log("Deploy failed " + err);

//initial migration

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {


const Helloworld = artifacts.require("Helloworld");

contract("Helloworld", async function(){
  it("should initialize correctly", async function(){
    let instance = await Helloworld.deployed();
    let message = await instance.getMessage();
    assert(message === "Hello Again!");

Not sure if i can go further until i figure this error out.

Thanks chaps.


1 Like

Hey @Rob_McCourt

You have a warning and an error:

The parameter string memory message is not used and can be removed.

This is related to the Node version installed.
Click this link and follow the guide to downgrade it:

let me know,

works perfectly thanks…

1 Like

Could somebody please tell me what’s going on here? I don’t understand the error. I’ve looked over and over again at the code from the video and I cannot figure out what’s wrong. Thank you.

What was the last command?

1 Like

Hey @mburtonshaw

From your screenshot it seems the tx failed due to a revert statement.
I am not able to provide more info as I need a bit of context.
Which function were you calling?
Also as @Rob_McCourt suggested, what was the last command you sent?


1 Like

@Rob_McCourt @dan-i
I entered “truffle console” and then “test”. I may have entered “migrate” before “test” but I don’t think I did

After running Test I keep receiving this error

1 Like

hey @kryptokrymmenos

Please follow this faq and downgrade node js: FAQ - How to downgrade Node.Js



Would you please share your github repo? I would like to take a look.


1 Like


1 Like

Hey @mburtonshaw

The issue pops up also when deploying your contract.
You are trying to send ether to a non - payable function in your migration file.

instance.setMessage("Hello again", {value: 1000000, from: accounts[0]}).

Remove value:

instance.setMessage("Hello again", { from: accounts[0]}).


1 Like

Hi I would like to get help to understand a supply chain code that is about creating an item that costs a specific amount of wei and then track it via blockchain, here is the questions and the code:

1- What does this mean: ItemManager.SupplyChainSteps _step; why not, we create only : SupplyChainSteps -Step?

2-What does this command mean: ItemManager parentContract; as I understood that we created a variable called parentContract of type ItemManager, but what is the purpose of that and what does it mean a variable of type ItemManager?

3- Why did you use a constructor here: and for which reason?

constructor(ItemManager _parentContract, uint _priceInWei, uint _index) public {

priceInWei = _priceInWei;

index = _index;

parentContract = _parentContract;


4-what is the function of this command:

address(parentContract).call{value:msg.value}(abi.encodeWithSignature("triggerPayment(uint256)", index));

5-What is the meaning of : Item item = new Item(this, _priceInWei, index);

what does it mean: this  and what did we create in this case and why?

pragma solidity ^0.6.4;

contract Item {
 uint public priceInWei;
 uint public paidWei;
 uint public index;

 ItemManager parentContract;

 constructor(ItemManager _parentContract, uint _priceInWei, uint _index) public {
 priceInWei = _priceInWei;
 index = _index;

 receive() external payable {
 require(msg.value == priceInWei, "We don't support partial payments");
 require(paidWei == 0, "Item is already paid!");
 paidWei += msg.value;
 (bool success, ) = address(parentContract).call{value:msg.value}(abi.encodeWithSignature("triggerPayment(uint256)", index));
 require(success, "Delivery did not work");


 fallback () external {



contract ItemManager {

 struct S_Item {
 Item _item;
 ItemManager.SupplyChainSteps _step;
 string _identifier;
 mapping(uint => S_Item) public items;
 uint index;

 enum SupplyChainSteps {Created, Paid, Delivered}

 event SupplyChainStep(uint _itemIndex, uint _step, address _address);

 function createItem(string memory _identifier, uint _priceInWei) public {
 Item item = new Item(this, _priceInWei, index);
 items[index]._item = item;
 items[index]._step = SupplyChainSteps.Created;
 items[index]._identifier = _identifier;
 emit SupplyChainStep(index, uint(items[index]._step), address(item));

 function triggerPayment(uint _index) public payable {
 Item item = items[_index]._item;
 require(address(item) == msg.sender, "Only items are allowed to update themselves"
 require(item.priceInWei() == msg.value, "Not fully paid yet");
 require(items[index]._step == SupplyChainSteps.Created, "Item is further in the supply chain");
 items[_index]._step = SupplyChainSteps.Paid;
 emit SupplyChainStep(_index, uint(items[_index]._step), address(item));

 function triggerDelivery(uint _index) public {
 require(items[_index]._step == SupplyChainSteps.Paid, "Item is further in the supply chain");
 items[_index]._step = SupplyChainSteps.Delivered;
 emit SupplyChainStep(_index, uint(items[_index]._step), address(items[_index]._item));

I had exactly the same problem and I had to roll back to node 10. Since I have project that need node 12 and I have installed node on my user account (~/whereIinstalledIt) (not in /usr/local/bin/node) I created file links to point node, npm, npx, truffle to the version 10 or 12.

you can also use npm to switch install version see
for details

I have a problem with the code.
In the second part Building our First Test Part 2. The program does not work for me as intended. I don’t understand if the code is for payable or not payable functions

Works for me making not payable the function, but i cannot create a test that works for payable functions.


Hey @camarosan

The code does not work if you try to send eth to a non-payable function such as setMessage()

If you want to send eth to your function, it needs to be payable
function setMessage(string memory _msg) public payable {}

hi @dan-i

i copy the same code that Filip post and it does not work for the second test. with the payable function.

Hello Again
it is solved, thanks to a future video in the course :smile:

1 Like

Seems everyone is having the same kind of problems. Your reply was the most straight forward one. Step by step until fininsh line! Thanks m8!