0

I am having trouble with my JS tests for a Contract which depends on the deployment of another Contract first.

Contract A needs to be deployed, then pass it's address to Contract B.

I have already been able to migrate successfully, but still trying to get the tests to pass.

How do I fix my JS tests and instantiate/deploy properly?

Here is my test code:

beforeEach(async function() {
        let tx = await ContractA.deployed();
        contractB = await ContractB.deployed(tx.address);
    });

Deployment script:

module.exports = function(deployer) {
    deployer.deploy(ContractA).then(function() {
        deployer.deploy(ContractB, ContractA.address);
    });
};

Receiving this error:

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

What is ContractA in the deployment script? I think you need the address of the instantiated contract instead.

Try:

module.exports = function(deployer) {
    deployer.deploy(ContractA).then(function(contractA) {
        deployer.deploy(ContractB, contractA.address);
    });
};

(ContractA => contractA)

0

You don't want tx.address. Use:

deployer.deploy(contractA).then(function(){
    deployer.deploy(contractB, contractA.address)});

Make sure that contractB takes contractA's address in it's initialization function. Let me know if this works, took that from a truffle project I've been working on...

  • I've already done this. See my deployment script above. It's the JS test portion that I need help on. – The Nomad Nov 6 '17 at 3:36
0

If you want to use contracts automatically deployed by test suit, why don't just fetch them like this:

beforeEach(async function() {
    let contractA = await ContractA.deployed();
    let contractB = await ContractB.deployed();
});

If deployment went well, then this should work. Or you can ignore those contract and redeploy them in test again if you have a reason to.

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.