From 7dd36a7a3b56f90d1339c3b1940ad14d77359e4b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 12 Apr 2018 18:50:47 -0400 Subject: [PATCH] support getting contract from module; fix bug in which entire contract path was being replaced instead of just the beginning (if matching contracts in embark.json) --- lib/core/config.js | 7 ++++++- lib/modules/solidity/index.js | 3 ++- test_apps/test_app/config/contracts.json | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 89a66c36..bbc09cf2 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -146,8 +146,13 @@ Config.prototype.loadExternalContractsFiles = function() { let contracts = this.contractsConfig.contracts; for (let contractName in contracts) { let contract = contracts[contractName]; - if (contract.file) { + if (!contract.file) { + continue; + } + if (fs.existsSync(contract.file)) { this.contractsFiles.push(new File({filename: contract.file, type: "dapp_file", basedir: '', path: contract.file})); + } else if (fs.existsSync(path.join('./node_modules/', contract.file))) { + this.contractsFiles.push(new File({filename: path.join('./node_modules/', contract.file), type: "dapp_file", basedir: '', path: path.join('./node_modules/', contract.file)})); } } }; diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index c4db9dae..596cd414 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -22,7 +22,8 @@ class Solidity { let filename = file.filename; for (let directory of self.contractDirectories) { - filename = filename.replace(directory, ''); + let match = new RegExp("^" + directory); + filename = filename.replace(match, ''); } file.content(function(fileContent) { diff --git a/test_apps/test_app/config/contracts.json b/test_apps/test_app/config/contracts.json index 8ab61e18..c2cd9b55 100644 --- a/test_apps/test_app/config/contracts.json +++ b/test_apps/test_app/config/contracts.json @@ -63,6 +63,9 @@ 100 ] }, + "ERC20": { + "file": "zeppelin-solidity/contracts/token/ERC20/ERC20.sol" + }, "SimpleStorageTest": { "file": "./some_folder/test_contract.sol", "args": [