Truffle runs and passes(?) the Tests without connecting to the specified network.
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
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.
The tests just run and surprisingly all pass.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G6030
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): v12.1.0npm --version): 6.9.0@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!
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