diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index bcd9882c2..13efc8948 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -146,6 +146,8 @@ class ContractsManager { self.logger.trace(self.contracts); callback(); }, + /*eslint complexity: ["error", 16]*/ + /*eslint max-depth: ["error", 16]*/ function determineDependencies(callback) { let className, contract; for (className in self.contracts) { @@ -167,6 +169,14 @@ class ContractsManager { self.contractDependencies[className] = self.contractDependencies[className] || []; self.contractDependencies[className].push(arg.substr(1)); } + if (Array.isArray(arg)) { + for (let sub_arg of arg) { + if (sub_arg[0] === "$") { + self.contractDependencies[className] = self.contractDependencies[className] || []; + self.contractDependencies[className].push(sub_arg.substr(1)); + } + } + } } // look in onDeploy for dependencies diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 3a3b09bb5..d14deab78 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -33,6 +33,18 @@ class Deploy { contractName = arg.substr(1); referedContract = this.contractsManager.getContract(contractName); realArgs.push(referedContract.deployedAddress); + } else if (Array.isArray(arg)) { + let subRealArgs = []; + for (let sub_arg of arg) { + if (sub_arg[0] === "$") { + contractName = sub_arg.substr(1); + referedContract = this.contractsManager.getContract(contractName); + subRealArgs.push(referedContract.deployedAddress); + } else { + subRealArgs.push(sub_arg); + } + } + realArgs.push(subRealArgs); } else { realArgs.push(arg); } diff --git a/test_app/app/contracts/some_contract.sol b/test_app/app/contracts/some_contract.sol index a8b0d7f99..fa69a88b3 100644 --- a/test_app/app/contracts/some_contract.sol +++ b/test_app/app/contracts/some_contract.sol @@ -5,9 +5,9 @@ contract SomeContract { function() public payable { } - function SomeContract(address _addresses, uint initialValue) public { - //addr_1 = _addresses[0]; - //addr_2 = _addresses[1]; + function SomeContract(address[] _addresses, uint initialValue) public { + addr_1 = _addresses[0]; + addr_2 = _addresses[1]; value = initialValue; } diff --git a/test_app/config/contracts.json b/test_app/config/contracts.json index 5dca2a91d..633a227ec 100644 --- a/test_app/config/contracts.json +++ b/test_app/config/contracts.json @@ -54,6 +54,12 @@ }, "MyToken3": { "instanceOf": "Tokn" + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } }, "afterDeploy": [ diff --git a/test_app/test/another_storage_spec.js b/test_app/test/another_storage_spec.js index f0feec87c..8b65fa74f 100644 --- a/test_app/test/another_storage_spec.js +++ b/test_app/test/another_storage_spec.js @@ -19,6 +19,12 @@ contract("AnotherStorage", function() { "MyToken2": { instanceOf: "Token", args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } }; EmbarkSpec.deployAll(contractsConfig, () => { done() }); diff --git a/test_app/test/array_references_spec.js b/test_app/test/array_references_spec.js new file mode 100644 index 000000000..238697b4c --- /dev/null +++ b/test_app/test/array_references_spec.js @@ -0,0 +1,48 @@ +contract("SomeContract", function() { + this.timeout(0); + before(function(done) { + this.timeout(0); + var contractsConfig = { + "SimpleStorage": { + args: [100] + }, + "AnotherStorage": { + args: ["$SimpleStorage"] + }, + "Token": { + deploy: false, + args: [1000] + }, + "MyToken": { + instanceOf: "Token" + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] + } + }; + EmbarkSpec.deployAll(contractsConfig, () => { done() }); + }); + + it("set MyToken2 address", function(done) { + SomeContract.methods.addr_1().call().then(function(address) { + assert.equal(address, MyToken2.options.address); + done(); + }); + }); + + it("set SimpleStorage address", function(done) { + SomeContract.methods.addr_2().call().then(function(address) { + assert.equal(address, SimpleStorage.options.address); + done(); + }); + }); + +}); + diff --git a/test_app/test/lib_test_spec.js b/test_app/test/lib_test_spec.js index f1886be2c..a0b878d45 100644 --- a/test_app/test/lib_test_spec.js +++ b/test_app/test/lib_test_spec.js @@ -24,6 +24,12 @@ contract("Test", function() { "MyToken2": { instanceOf: "Token", args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } }; diff --git a/test_app/test/simple_storage_spec.js b/test_app/test/simple_storage_spec.js index e8f2cedf6..c0d7eeffd 100644 --- a/test_app/test/simple_storage_spec.js +++ b/test_app/test/simple_storage_spec.js @@ -26,6 +26,12 @@ contract("SimpleStorage", function() { "MyToken2": { instanceOf: "Token", args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } }; EmbarkSpec.deployAll(contractsConfig, () => { done() }); diff --git a/test_app/test/token_spec.js b/test_app/test/token_spec.js index 9974dbabf..51a9c68b1 100644 --- a/test_app/test/token_spec.js +++ b/test_app/test/token_spec.js @@ -35,6 +35,12 @@ describe("Token", function() { onDeploy: [ "Test.methods.changeAddress('$MyToken').send()" ] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } }; EmbarkSpec.deployAll(contractsConfig, () => { done() });