3

I'm using a contract to manage my contracts, and am not sure how to write a test.

The problem I'm facing is that I can't see how to get my coolerDb contract address.

This is my test.js

contract('CMC', function(accounts) {
  "use strict";

  it("check deployment", function(done) {
    let cmc = CMC.deployed();
    let coolerDb = CoolerDb.deployed();
    cmc.addContract("coolerDb", coolerDb).then(function(rc) {
      assert.equal(rc.c[0], true, 'Assert fail: not added');
    }).then(done).catch(done);
  });
});

The error is:

Error: Contract address not set - deployed() relies on the contract class having a static 'address' value; please set that before using deployed().

1

The address is shown when you run truffle migrate. The complete set of commands to deploy the contract is:

# --compile-all recompiles all contracts.
# Omitting the flag compiles only those files that have been modified or added   
truffle compile --compile-all 
# Then deploy (here is where the address at which the contract is stored
# in the block chain is shown).
truffle migrate

Use that address in future contracts.

  • Hi Sebi, This is strange - I'm getting Unknown command: migrate. I'm running truffle v1.0.3 – Martin Aug 9 '16 at 11:35
  • Upgrade to v2.0.4. – Sebi Aug 9 '16 at 11:46
0

Sebi gave the a great hint to look at the truffle command. The actual way that I got the contract was

  1. made sure all the contracts were in truffle.js (and it was missing)
  2. truffle deploy
  3. read the address from the output

    Deployed: CoolerDb to address:xxxxxxxxxxxxxx

Luckily I didn't need to hard code the address because

let coolerDb = CoolerDb.deployed();

seems to get the 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.