diff --git a/lib/deploy.js b/lib/deploy.js index 3650cd0a5..9378dbabc 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -117,8 +117,12 @@ Deploy.prototype.execute_cmds = function(cmds) { for (var i = 0; i < cmds.length; i++) { var cmd = cmds[i]; - // need to initialize all variables of deployed contracts making them - // available to deployment + for(className in this.deployedContracts) { + var contractAddress = this.deployedContracts[className]; + + var re = new RegExp("\\$" + className, 'g'); + cmd = cmd.replace(re, '"' + contractAddress + '"'); + } console.log("executing: " + cmd); eval(cmd); diff --git a/test/deploy.js b/test/deploy.js index e0655bbd2..c52ddfe35 100644 --- a/test/deploy.js +++ b/test/deploy.js @@ -135,7 +135,7 @@ describe('embark.deploy', function() { deploy.deploy_contracts("development"); it("should deploy contracts", function() { - var all_contracts = ['DataSource', 'Manager']; + var all_contracts = ['DataSource', 'MyDataSource', 'Manager']; for(var i=0; i < all_contracts.length; i++) { var className = all_contracts[i]; @@ -149,10 +149,17 @@ describe('embark.deploy', function() { data_source_abi = deploy.contractDB['DataSource'].compiled.info.abiDefinition; data_source_address = deploy.deployedContracts['DataSource']; + my_data_source_abi = deploy.contractDB['MyDataSource'].compiled.info.abiDefinition; + my_data_source_address = deploy.deployedContracts['MyDataSource']; + manager_abi = deploy.contractDB['Manager'].compiled.info.abiDefinition; + manager_address = deploy.deployedContracts['Manager']; DataSource = web3.eth.contract(data_source_abi).at(data_source_address); + MyDataSource = web3.eth.contract(my_data_source_abi).at(my_data_source_address); + ManagerSource = web3.eth.contract(manager_abi).at(manager_address); assert.equal(DataSource.storeData().toNumber(), 5); + assert.equal(Manager.data().toString(), my_data_source_address); }); }); diff --git a/test/support/arguments3.yml b/test/support/arguments3.yml index 9ade4a5ce..7fe418f86 100644 --- a/test/support/arguments3.yml +++ b/test/support/arguments3.yml @@ -1,6 +1,9 @@ development: DataSource: args: + MyDataSource: + args: + instanceOf: DataSource Manager: stubs: - DataSource @@ -8,4 +11,5 @@ development: - $DataSource onDeploy: - DataSource.set(5) + - Manager.update($MyDataSource) staging: diff --git a/test/support/contracts/manager.sol b/test/support/contracts/manager.sol index 78e390ba2..0445cee2e 100644 --- a/test/support/contracts/manager.sol +++ b/test/support/contracts/manager.sol @@ -1,8 +1,11 @@ contract Manager { - address data; + address public data; function Manager(address dataAddress) { data = dataAddress; } + function update(address _addr) { + data = _addr; + } }