I created and deployed two contracts successfully (with confirmation) using truffle migrate like so:

module.exports = function(deployer) {
    deployer.deploy(ReentrancyPot).then(async () => {
        deployer.deploy(ReentrancyAttack, ReentrancyPot.address);

The second contract has a dependency on the first like so (excerpt from ReentrancyAttack.sol)

contract ReentrancyAttack {
    ReentrancyPot public pot;

    function ReentrancyAttack (address _pot) public {
        pot = ReentrancyPot(_pot);

I'm using a test for the first contract and it is successful, however, the second contract is showing as not deployed (truffle.js is configured to point to port 8545)

var ReentrancyPot = artifacts.require("./ReentrancyPot.sol");
var ReentrancyAttack = artifacts.require("./ReentrancyAttack.sol");
var Web3 = require('web3');
var web3 = new Web3(Web3.givenProvider || 'ws://localhost:8545');


contract('ReentrancyPot / ReentrancyAttack', function(accounts) {

    it("pot should support deposits and withdrawals", async () => {
        let pot = await ReentrancyPot.deployed();
        let attack = await ReentrancyAttack.deployed();

I'm getting the following error after running truffle test:

Error: ReentrancyAttack has not been deployed to detected network 
(network/artifact mismatch)

What you want is:

module.exports = function(deployer) {
    deployer.then(async () => {
        await deployer.deploy(ReentrancyPot);
        var reentrancyPotInstance = await ReentrancyPot.deployed();
        await deployer.deploy(ReentrancyAttack, reentrancyPotInstance.address)
  • That leaves me with the following problem when running truffle migrate: TypeError: Cannot read property 'address' of undefined at deployer.deploy.then (/Users/p/Dev/experimental/solidity-nemesis/tests/solidity/migrations/2_contract_migration.js:8:65) at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/deferredchain.js:20:1 at <anonymous> at process._tickCallback (internal/process/next_tick.js:118:7) – Peteris Apr 5 '18 at 20:23
  • 1
    my fault... I didn't remember right that deployer.deploy is not returning the instance. Let me rewrite the answer... – ivicaa Apr 5 '18 at 20:31
  • The answer is updated. Btw.. you can use await for better readability. – ivicaa Apr 5 '18 at 20:37
  • 1
    Thanks a lot! The following worked: deployer.deploy(ReentrancyPot).then(async () => { let reentrancyPotInstance = await ReentrancyPot.deployed(); await deployer.deploy(ReentrancyAttack, reentrancyPotInstance.address) }); – Peteris Apr 5 '18 at 20:42
  • 1
    I do use async / await in my tests, unfortunately chai was required because of a version problem (if I remember correctly). – Peteris Apr 5 '18 at 20:42

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.