Truffle Test – Troubleshooting Petshop Tutorial Failures

truffle

I don't know what this error means or how to fix it.

I try to follow the tutorial located here and when I get to the point where I have to run "truffle test" I get the following error.

with TestAdoption "before all" hook: prepare suite:      Error: Could not find artifacts for ''EthereumPetShopTutorial/contracts/Adoption.sol" from any sources

Output of Truffle version

Truffle v4.1.5 (core: 4.1.5)
Solidity v0.4.21 (solc-js)

this is my 2_deploy_contracts.js file

var Adoption = artifacts.require("Adoption");

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

this is my TestAdoption.sol file:

pragma solidity ^0.4.17;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";

contract TestAdoption {
  Adoption adoption = Adoption(DeployedAddresses.Adoption());

  // Testing the adopt() function
    function testUserCanAdoptPet() public {
        uint returnedId = adoption.adopt(8);

        uint expected = 8;

        Assert.equal(returnedId, expected, "Adoption of pet ID 8 should be recorded.");
    }

}

This is my file structure:

enter image description here

Best Answer

There is something wrong with the latest truffle version. To solve this problem I had to do the following things to find a truffle version that worked.

First check for available versions of truffle with the following command.

npm view truffle versions

Then for each item on the list starting from the latest version. I uninstalled truffle with

npm uninstall -g truffle

then installed the next oldest version with

npm install -g truffle@<version#>

then deleted the build folder

then compiled the project with

truffle compile

then ran

truffle test

if this fails move on to the next oldest version and repeat the test.

In my case a working version of truffle was 4.1.4

Related Topic