0

When I run truffle test on ganache-cli, it will pass the test but when I run the same truffle test commnad on local geth node, it will fail with error saying invalid address at the method which takes address as a parameter (even though parameter address has no problem).

However when I deploy contracts to the local geth node and call the method that I get an error, there was no problem.

Here are the truffle.js setting:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*',
      gasPrice: 0,
      gas: 6600000,
    },
  },
  compilers: {
    solc: {
      version: '0.4.25',
    },
    settings: {
      optimizer: {
        enables: true,
        runs: 200,
      },
    },
  },
};

version

Truffle v4.1.14 (core: 4.1.14)
Solidity v0.4.24 (solc-js)
geth (docker) ethereum/client-go:release-1.8
Ganache CLI v6.3.0 (ganache-core: 2.4.0)

0

Issue #1:

This configuration is valid only starting from Truffle v5.x:

compilers: {
    solc: {
        version: '0.4.25',
    },
    settings: {
        optimizer: {
            enables: true,
            runs: 200,
        },
    },
},

On Truffle v4.x or earlier, you should change it to this:

solc: {
    optimizer: {
        enabled: true,
        runs: 200
    },
},

And yes, you cannot configure solc version here, which means that you're kind of bound to stay with solc v0.4.24 (which is what Truffle v4.1.14 relies on). There are ways to change the compiler version after installing Truffle, which you can find on this website, but I recommend that you simply upgrade to Truffle v4.1.15 (which relies on solc v0.4.25). You can also upgrade to Truffle v5.x, but that will subsequently upgrade your solc from v0.4.x to v0.5.x and your web3 from v0.x to v1.x, each of which introducing API-breaking changes, which will leave you to fix a lot of broken things in your code (both Solidity and Javascript).

Issue #2:

When Ganache starts, it automatically unlocks the accounts specified in the command-line.

For example:

ganache-cli
    --port=8545
    --gasPrice=20000000000
    --gasLimit=8000000
    --account=0x0000000000000000000000000000000000000000000000000000000000000001,1000000
    --account=0x0000000000000000000000000000000000000000000000000000000000000002,1000000

Will unlock the accounts with private keys 0x0...1 and 0x0...2 (2 accounts).

The default (if you don't specify anything) is 0x0...1 thru 0x0...a (10 accounts).

GETH doesn't do that, so you must unlock the accounts yourself prior to running any of your Truffle tests, by sending to GETH an "unlock account" command for each one of the accounts used in these tests.

  • 1
    Yes, I did created and unlocked a few accounts before running a test, it worked perfect. Thank you very much. – kphex Mar 14 at 2:59
  • @kphex: No problem. See a similar question about the difference between Ganache and Parity here. The answer is the same. – goodvibration Mar 14 at 6:49
  • Great, thank you for the sharing the solution to the issue that you faced before. – kphex Mar 15 at 6:27

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.