4

Here my test js file

const ApprovalContract = artifacts.require('../../contracts/ApprovalContract.sol');

contract('ApprovalContract' function (accounts) {

    it('initiates contract', async function() {
        const contract = await ApprovalContract.deployed();
        const approver = await contract.approver.call();
        assert.equal(approver, 0x3999BA5D247c800E5Ef3d4de66618741E3675379, "approver don't match");
    });
})

From my cmd

3
  • What is the content of your configuration file (truffle.js and/or truffle-config.js)? Are you testing against ganache or a private network? The error message is saying your truffle configuration id doesn't matches the id returned by the network.
    – Ismael
    Apr 4, 2019 at 19:22
  • I testing against truffle/ganache network, and I have both 2 file, truffle.js and truffle-config.js in different location. The truffle-config.js file was just an example file when i "truffle init" and below is my truffle.js file code. module.exports = { networks: { development: { host: "127.0.0.1", port: 9545, network_id: "*" } } }; truffle-config.js location: D:\Desktop\BuildDapps 2\contracts truffle.js location: D:\Desktop\BuildDapps 2\contracts\test
    – sohd9
    Apr 5, 2019 at 13:46
  • I think the configuration file has to be in D:\Desktop\BuildDapps 2`, and you should execute truffle commands from that directory. You only need one config file in your proyect, either truffle-config.js` or truffle.js.
    – Ismael
    Apr 5, 2019 at 17:20

3 Answers 3

5

I encountered the same thing when running truffle test.

The reason is likely because truffle-config.js from truffle unbox <package> have network information commented out.

Thus, the port and network_id default to 4447, which is what truffle test defaults to if nothing is specified in truffle-config.js

See: https://github.com/trufflesuite/truffle/pull/1577/files

What you will need to do is to uncomment the networks config in truffle-config.js.

module.exports = {
  /* <- NOTE: need to uncomment this!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    },
    test: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
  */ <- NOTE: need to uncomment this!
};

0

delete file truffle.js

file truffle-config.js module.exports = { networks: { development: { host: "127.0.0.1", port: 7545, network_id: "*" } } };

0

In my case, i did not specify the truffle-config.js in Gananche.

Go to the setting and add correct truffle-config.js

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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