I'm having trouble getting my test harness set up in truffle. I have 2 contracts. The first is an Issuing authority and in order for the second to be deployed, the creation address must be registered with the first. I'm having a hard time figuring out how to best do this with truffle testing because I can't deploy the contract without it failing in my migration because the contract creation code throws(as expected).
I tried the below in my migration code, but the 'here i am' comment never gets hit. I'm thinking it is because I don't really have a good space to do this in and it would be for moot anyway since each test creates its own little sand box.
var IssuingAuthority = artifacts.require("./IssuingAuthority.sol");
var CitizenAccount = artifacts.require("./CitizenAccount.sol");
module.exports = function(deployer) {
console.log('about to deploy')
deployer.deploy(IssuingAuthority).then(function(){
console.log('about to deplyoy 2');
IssuingAuthority.deployed().then(function(instance){
console.log('about to call add citizen');
instance.addCitizen.call(accounts[1]).then( function(result){
console.log('here i am');
console.log(result);
deployer.link(IssuingAuthority, CitizenAccount);
console.log(IssuingAuthority.address);
deployer.deploy(CitizenAccount,IssuingAuthority.address);
});
});
});
}
I'm wondering if I can get access to the deployer inside of a test so that I can deploy my contract to the network at test time. something like this:
var IssuingAuthority = artifacts.require("./IssuingAuthority.sol");
var CitizenAccount = artifacts.require("./CitizenAccount.sol");
contract('CitizenAccount', function(accounts) {
it("should be authorized", function() {
var ia = null;
return IssuingAuthority.deployed().then(function(instance) {
ia = instance;
return instance.addCitizen.call(accounts[1]);
}).then(function(result) {
assert.equal(result, true, "citizen wasnt added");
///////////////////
// I need to do a deployment here now that the issuer contract
// has the address I want.
/////////////////////////
return CitizenAccount.deployed(ia.address);
}).then(function(caInstance){
});
});
});
Here is the code for my citizen account contract. Feel free to point me to a better pattern if this just isn't going to work:
pragma solidity ^0.4.2;
import "./IssuingAuthority.sol";
contract CitizenAccount {
address public issuingAuthority;
address owner;
function CitizenAccount(address _issuingAuthority) {
IssuingAuthority i = IssuingAuthority(_issuingAuthority);
bool isCitizen = i.isCitizen(msg.sender);
if(isCitizen){
issuingAuthority = _issuingAuthority;
}
else{
throw;
}
}
}