From c0420d74a8fb6ae0510f2149e615fa531142a33a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 2 Aug 2015 20:50:12 -0400 Subject: [PATCH] support deploy commands specifying contract --- lib/deploy.js | 8 ++++++-- test/deploy.js | 9 ++++++++- test/support/arguments3.yml | 4 ++++ test/support/contracts/manager.sol | 5 ++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index 3650cd0a..9378dbab 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 e0655bbd..c52ddfe3 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 9ade4a5c..7fe418f8 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 78e390ba..0445cee2 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; + } }