Well, I have a smart contract called Register
. The test script is quite straightforward:
const Register = artifacts.require("Register")
contract('Register', (accounts) => {
let register;
beforeEach('create new Register contract', async () => {
register = await Register.new("test", 0, {from: accounts[0]});
})
it("test register enntity", async () => {
register.entity().then(entity => {
assert.equal(entity, accounts[0], "Entity is wrong!");
})
})
})
If I create 2_migrate_contracts.js
in folder migrations
with content:
var Register = artifacts.require("./Register.sol");
module.exports = function(deployer) {
deployer.deploy(Register, "tesst", 0);
};
then the truffle test
process finish with no error.
As far as I know, the test script creates a new Register
contract, which should be irrelevant with the migrated contract. So if I comment out the 2_migrate_contracts.js
file and let the test script do all the jobs. However, I got this error:
"before all" hook: prepare suite:
Uncaught Error: Attempting to run transaction which calls a contract function, but recipient address 0x4f94fdfc235abc73a163bff1ba9341f6226ff6bd is not a contract address.
I tried to delete the ./build
folder. No help.
So I am confused. Does truffle test
have to begin with a migration process? i.e., I can not skip the migration process and created new contract in test script only?
Thanks in advance.
=================== UPDATE ======================
I just take a step forward. In my project, actually, there is another contract named Authorization
, and accordingly, there is another test file named TestAuthorization
. Now if I run the test file by file such as:
truffle test ./test/TestRegister
Then the test will be fine. But if I run all the test together using truffle test
. Then the 'recipient address is not a contract address' error shows again.
According to the Josesph's reply, it is said When running your tests against Ganache or Truffle Develop, Truffle will use advanced snapshotting features to ensure your test files don't share state with each other. Now the question is: how can I run multiple test with truffle test
?