0

Hello I'm trying to make my first and simple test for get a variable from my first contract:

Truffle version: Truffle v4.1.14 Node: 8.12.0

pragma solidity ^0.4.4;

contract SimpleContract {
  bytes32  hello = "hello";
  function getHello() public view returns (bytes32){
    return hello;
  }
}

And I did a simple test like:

pragma solidity ^0.4.4;

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

import "../contracts/SimpleContract.sol";


contract TestSimpleContract {

  function testGetHello() public {
    SimpleContract w = SimpleContract(DeployedAddresses.SimpleContract());
    bytes32  expected = "hello";
    bytes32  hello = w.getHello();

    Assert.equal(hello,expected, "SHould hello!");
  }
}

And I have a Migrations:

var Simple = artifacts.require("SimpleContract");


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

And I have this truffle config

module.exports = {
   networks: {
     development: {
      host: "localhost",
      port: 7545,
      network_id: "5777"
    }
   }
 };

But I can't understand and how figure out why it return this error:

1) TestSimpleContract testGetHello: Error: VM Exception while processing transaction: revert at Object.InvalidResponse (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1) at C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1 at C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:134:1 at XMLHttpRequest.request.onreadystatechange (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.js:128:1) at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1) at XMLHttpRequest._setReadyState (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1) at XMLHttpRequest._onHttpResponseEnd (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1) at IncomingMessage. (C:\Users\Lorenzo\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:469:1) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:139:11) at process._tickCallback (internal/process/next_tick.js:181:9)

  • the code looks fine for me, how do you run the test? – Aquila Oct 20 '18 at 10:30
  • what version of truffle? – Aquila Oct 20 '18 at 10:34
  • Truffle v4.1.14 – LorenzoBerti Oct 20 '18 at 10:43
0

The issue happend with ganache-cli. In order to fix it you need to run ganache-cli with networkId

> ganache-cli -i 5777
  • yes! I've already done. I edit my questions. – LorenzoBerti Oct 20 '18 at 10:44
  • interesting catch, I can reproduce the issue with ganache-cli, but can't reproduce with ganache, test is green – Aquila Oct 20 '18 at 11:10
  • @LorenzoBerti found an issue, updates answer – Aquila Oct 20 '18 at 11:20
  • Thank you I'm trying to install ganache-cli and I will try! – LorenzoBerti Oct 20 '18 at 11:25
  • unfortunately, I receive same error :/ – LorenzoBerti Oct 20 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.