1

My contract hierarchy is Token which calls function on TokenBase. The deployment is defined like so:

var Token = artifacts.require("./Token.sol");
var TokenBase = artifacts.require("./TokenBase.sol");

module.exports = function(deployer) {
  //deployer.deploy(Accounts);
  deployer.deploy(Token, "SweetCoin", "SWC")
  .then(function() {
    console.log("deployment log Token address is", Token.address);
    deployer.deploy(TokenBase, Token.address, 0, 0, 1000).then(function() {
        console.log("deployment log TokenBase address is", TokenBase.address);
    });
  })
};

this seems to work fine as the output of truffle migrate is

deployment log Token address is 0xf10382227656670bc71d5433ae51e6826fabfff1
deployment log TokenBase address is 0xf0d762e793e1691cc2f80787e74ce3715479652e

when truffle test is run it looks like TokenBase is instantiated after the start of the test contract. This is the output after truffle test

deployment log Token address is 0x87a224644edcac90885cc6ca8099dc989d89ed36


TestToken
deployment log TokenBase address is 0xfefe73e3abd10d82461161298e0db6f1b1225da7
    1) testSetUp
    > No events were emitted


0 passing (446ms)
1 failing

1) TestToken testSetUp:
    Error: VM Exception while processing transaction: invalid opcode
    at Object.InvalidResponse (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/errors.js:35:16)
    at /Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:86:36
    at XMLHttpRequest.request.onreadystatechange (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:118:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/Users/mroon/.nvm/versions/node/v7.9.0/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
    at endReadableNT (_stream_readable.js:975:12)

And finally this is the test contract:

pragma solidity ^0.4.10;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";

import "../contracts/Token.sol";
import "../contracts/TokenBase.sol";

contract TestToken {
    Token token;
    TokenBase tokenBase;

    function testSetUp() {
        token = Token(DeployedAddresses.Token());
        tokenBase = TokenBase(DeployedAddresses.TokenBase());
    }

}

The reason I suspect a sync issue is that if I remove the second line in the test: tokenBase = TokenBase(DeployedAddresses.TokenBase()); the test passes.

The question obviously is: how can I make my test pass?

3

It looks like you are not returning a promise from within deployer().deploy().then

Add return before deployer.deploy(TokenBase, Token.address, 0, 0, 1000).then

I'd write the whole thing like this:

  deployer.deploy(Token, "SweetCoin", "SWC").then(function() {
    console.log("deployment log Token address is", Token.address);
    return Token.address;
  }).then(function(){
    return deployer.deploy(TokenBase, Token.address, 0, 0, 1000)
  }).then(function(){
    console.log("TokenBase deployed at: ", TokenBase.address);
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.