Introduction to Unit Testing

I really appreciate all of your help. Man. Thanks.

Here is the abi:

var abi = [
    {
      "constant": true,
      "inputs": [],
      "name": "getMessage",
      "outputs": [
        {
          "internalType": "string",
          "name": "",
          "type": "string"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "internalType": "string",
          "name": "newMessage",
          "type": "string"
        }
      ],
      "name": "setMessage",
      "outputs": [],
      "payable": true,
      "stateMutability": "payable",
      "type": "function"
    }
  ]
1 Like

Hey @NeoKanoPheus

In your ABI I do not see the function createPerson()

I see only getMessage() and setMessage()

Take the correct ABI and try again :slight_smile:

You can find the abi into your project folder > build > contracts

Keep me updated
Dani

1 Like

Duly noted.
Thank you very much

1 Like

How do I downgrade the node?

Same problems on linux

solved it by installing NVM and changed NODE.JS V12.18.1 ==> V10.18

then it worked

Hey @elterremoto

Check this FAQ: FAQ - How to downgrade Node.Js

Cheers,
Dani

2 Likes

Hello,

I had error ERR_INVALID_REPL_INPUT after running test

so I followed these instructions.

After that I have a new error:

Compiling your contracts...
===========================
Error: TypeError: Error parsing C:/Users/enrico/Desktop/coding/truffle/helloworld/contracts/Migrations.sol: Cannot destructure property 'body' of 'undefined' as it is undefined.
    at Object.compile (C:\Users\enrico\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\legacy\index.js:80:1)

The Helloworld contract was not modified (before it was migrating it normally).

Do you have any idea how to fix this? thanks

@filip

Trying to run “test” in truffle console. Getting this message:

TypeError [ERR_INVALID_REPL_INPUT]: Listeners for uncaughtException cannot be used in the REPL

Any advice?

I found this thread which I think is about this issue, but not sure what to do: https://github.com/trufflesuite/truffle/issues/2463

1 Like

Hey @enrico

Check this FAQ: FAQ - How to downgrade Node.Js

Let me know if that fixes the issue.

Cheers,
Dani

1 Like

Slavenr’s solution worked for me!

1 Like

@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.

https://stackoverflow.com/questions/47008159/how-to-downgrade-node-version

1 Like

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

helloworld.sol

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;
  }
}

//Helloworld_Deploy.js

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

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

//initial migration

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

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

//Helloworld.js

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.

Rob.

1 Like

Hey @Rob_McCourt

You have a warning and an error:

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

error
This is related to the Node version installed.
Click this link and follow the guide to downgrade it:
https://forum.ivanontech.com/t/faq-how-to-downgrade-node-js/22908/2

let me know,
Dani

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?

Cheers,
Dani

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