It is really embarrassing, how narrow minded the truffle authors think. My tests run their own deployment that is used in the tests. In my case, the truffle migration includes the steps that data is copied from the old instance to the new instance of the main contract, then the old contract is destroyed. Unfortunately, here the snapshot does not help, the old instance is not restored and a defect instance remains in the contract's json file. So I have to prevent the migration scripts from running. So there are good reasons, why migration should be optional and configurable in truffle test
!
I solved it in the following way:
- run a second
canache-cli
with a separete network named test
- if the
truffle migrate
script is in network test
, do nothing
- run
truffle test
with option --network test
In detail:
Add on top of migrations/2_contract
the line:
module.exports = async function(deployer, network, accounts) {
if (network == "test") return; // test maintains own contracts
…
}
Add new network test
to truffle-config.js
:
…
networks: {
…
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*"
},
test: {
host: "127.0.0.1",
port: 8546,
network_id: "*"
}
}
…
Run a second canache-cli
(besides the one running network development
:
In one console, I run ganache for development
, for my GUI tests:
ganache-cli -d --db ${HOME}/tmp/ganache/development -i 123456 -p 8545
In another console, I run a separate ganache for test
:
ganache-cli -d --db ${HOME}/tmp/ganache/test -i 654321 -p 8546
That's it! Now I can run:
truffle migrate --reset
And
truffle test --network test
Without interferences.