Truffle: Tests run without a network

Created on 7 May 2019  Â·  3Comments  Â·  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

Truffle runs and passes(?) the Tests without connecting to the specified network.

Steps to Reproduce

test:

const FooContract = artifacts.require("FooContract");
contract("FooContract", async instances => {
  it("has owner when new", async () => {
    let instance = await FooContract.new()
    let owner = await instance.owner.call();
    expect(owner).to.exist;
  });
  it("has owner", async () => {
    let instance = await FooContract.deployed();
    let owner = await instance.owner.call();
    expect(owner).to.exist;
  });
});

truffle.js:

module.exports = {
    networks: {
        geth: {
            host: "127.0.0.1",
            port: 8545,
            network_id: "*"
        }
    }
};

Connecting to a network not specified in the truffle.js fails as expected:

truffle console --network foo
Unknown network "foo". See your Truffle configuration file for available networks.
Truffle v5.0.14 (core: 5.0.14)
Node v12.1.0

Running the test surprisingly still works

truffle test --network foo ./test/*.js
running tests
Using network 'foo'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
  Contract: FooContract
    ✓ has owner when new (108ms)
    ✓ has owner

Expected Behavior

I don't see how the tests can run without connecting to the specified network.
It should give the same Unknown network "foo" error as when connecting with the console. And it of course should run the tests on the specified network.

truffle test --network geth ./test/*.js

This might be just a user error - but neither the logging nor documentation seem to cover this.

Actual Results

The tests just run and surprisingly all pass.

Environment

  • Operating System:
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.6
BuildVersion:   17G6030
  • Ethereum client:
  • Truffle version (truffle version):
Truffle v5.0.14 (core: 5.0.14)
Solidity v0.5.0 (solc-js)
Node v12.1.0
Web3.js v1.0.0-beta.37
  • node version (node --version): v12.1.0
  • npm version (npm --version): 6.9.0
bug truffle test

Most helpful comment

@CruzMolina Thanks for the explanation. Yes - that really is quite confusing :)
Just logging the startup of the ganache network would already help a lot.
"No test network specified. Starting ganache." or something like that would be great.
Cheers

All 3 comments

@tcurdt It looks like this is because truffle test will spin up a default internal ganache network if a development or test network isn't specified in the config. Currently it will just name that network any network name passed to it at the command line. Definitely a little confusing, there should probably be a check for this.

@CruzMolina Thanks for the explanation. Yes - that really is quite confusing :)
Just logging the startup of the ganache network would already help a lot.
"No test network specified. Starting ganache." or something like that would be great.
Cheers

Hi @tcurdt it looks like we've addressed this issue in a recent PR. We're closing this for issue maintenance but feel free to comment and we'll be happy to reopen if it's still a problem. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Katsu1991 picture Katsu1991  Â·  3Comments

ferittuncer picture ferittuncer  Â·  3Comments

mezrin picture mezrin  Â·  3Comments

oed picture oed  Â·  3Comments

rjl493456442 picture rjl493456442  Â·  4Comments