I've defined a truffle migration step as follows:
Deploy my 'main' smart contract, nothing out of the ordinary:
var UniversityVoting = artifacts.require('./UniversityVoting.sol');
module.exports = async (deployer) => {
await deployer.deploy(UniversityVoting);
};
I then deploy an ERC20
token contract, called VotingToken
. As you can see, in module.exports
, I get an instance of UniversityVoting
which I deployed in step 1, so I can then pass the address of the newly deployed VotingToken
to it:
var VotingToken = artifacts.require('./VotingToken.sol');
var UniversityVoting = artifacts.require('./UniversityVoting.sol');
module.exports = async (deployer) => {
UniversityVotingInstance = await UniversityVoting.deployed();
await deployer.deploy(VotingToken, UniversityVotingInstance.address);
await UniversityVotingInstance.setVotingTokenAddress(VotingToken.address);
};
This works fine using truffle migrate
and I can indeed see the correct VotingToken
address in Ganache:
But in a test written in JavaScript that I execute using truffle test
, where I create a new instance of UniversityVoting
and call a getter
method that returns deployedVotingToken
it returns a 0 address
. Why would that happen in a truffle test? I thought it was supposed to run your migration files?
describe("Deploy and use the child institution contract", function() {
before(async function() {
universityVoting = await UniversityVoting.new(
{
from: developerAccount
});
...
// In an 'it' block
const originalToken = await universityVoting.getVotingTokenAddress();
originalToken.should.equal("[exampleAddress]"); // Here it says that AssertionError: expected '0x0000000000000000000000000000000000000000' to equal '0x34344343434'