diff --git a/dapps/tests/app/config/contracts.js b/dapps/tests/app/config/contracts.js index 23f2babe60..55c41d496b 100644 --- a/dapps/tests/app/config/contracts.js +++ b/dapps/tests/app/config/contracts.js @@ -11,10 +11,8 @@ module.exports = { console.log("before deploying contracts"); console.log("=========================="); }, + interfaces: ['Ownable'], deploy: { - Ownable: { - deploy: false - }, Token: { deploy: false, args: [1000] diff --git a/packages/plugins/deploy-tracker/src/deploymentChecks.js b/packages/plugins/deploy-tracker/src/deploymentChecks.js index 6ffdf6e095..10f26b3356 100644 --- a/packages/plugins/deploy-tracker/src/deploymentChecks.js +++ b/packages/plugins/deploy-tracker/src/deploymentChecks.js @@ -4,11 +4,12 @@ import Web3 from "web3"; require("colors"); export default class DeploymentChecks { - constructor({trackingFunctions, events, logger}) { + constructor({trackingFunctions, events, logger, contractsConfig}) { this.trackingFunctions = trackingFunctions; this.events = events; this.logger = logger; this._web3 = null; + this.contractsConfig = contractsConfig || {}; this.events.on("blockchain:started", () => { this._web3 = null; @@ -33,6 +34,13 @@ export default class DeploymentChecks { return cb(null, params); } + const isInterface = this.contractsConfig.interfaces && this.contractsConfig.interfaces.includes(contract.className); + const isLibrary = this.contractsConfig.libraries && this.contractsConfig.libraries.includes(contract.className); + + if (isInterface || isLibrary) { + contract.deploy = false; + } + // check if contract set to not deploy in the config if (contract.deploy === false) { params.shouldDeploy = false; diff --git a/packages/plugins/deploy-tracker/src/index.js b/packages/plugins/deploy-tracker/src/index.js index aaa416b410..b59c6fa9a5 100644 --- a/packages/plugins/deploy-tracker/src/index.js +++ b/packages/plugins/deploy-tracker/src/index.js @@ -8,7 +8,7 @@ class DeployTracker { this.embark = embark; const trackingFunctions = new TrackingFunctions({config, fs, logger, events, trackContracts}); - const deploymentChecks = new DeploymentChecks({trackingFunctions, logger, events, plugins}); + const deploymentChecks = new DeploymentChecks({trackingFunctions, logger, events, plugins, contractsConfig: config.contractsConfig}); this.embark.registerActionForEvent("deployment:contract:deployed", trackingFunctions.trackAndSaveContract.bind(trackingFunctions)); this.embark.registerActionForEvent("deployment:contract:shouldDeploy", deploymentChecks.checkContractConfig.bind(deploymentChecks)); diff --git a/packages/plugins/deploy-tracker/src/test/deploymentChecksSpec.js b/packages/plugins/deploy-tracker/src/test/deploymentChecksSpec.js index 9cbf1a8e35..19e3bcd95d 100644 --- a/packages/plugins/deploy-tracker/src/test/deploymentChecksSpec.js +++ b/packages/plugins/deploy-tracker/src/test/deploymentChecksSpec.js @@ -77,7 +77,7 @@ describe('embark.deploymentChecks', function () { } }; trackingFunctions._web3 = _web3; - deploymentChecks = new DeploymentChecks({trackingFunctions, events, logger}); + deploymentChecks = new DeploymentChecks({trackingFunctions, events, logger, contractsConfig: {}}); deploymentChecks._web3 = _web3; }); afterEach(() => { diff --git a/site/source/docs/contracts_configuration.md b/site/source/docs/contracts_configuration.md index 7f332afe33..63d74e2464 100644 --- a/site/source/docs/contracts_configuration.md +++ b/site/source/docs/contracts_configuration.md @@ -127,6 +127,26 @@ production: { ... ``` +## Defining interfaces + +There are scenarios in which certain Smart Contract sources are used for inheritance or as interfaces. While their source has to be compiled, +we don't actually want to deploy them. To prevent such Smart Contracts from deploying, we can either take advantage of the `deploy: false` +propery discussed above, or use the more semantic `interfaces` and `libraries` configurations. + +Both of them are simple lists of Smart Contract names that should be treated as interfaces and libraries respectively. The following example +show how the `Ownable` Smart Contract is configured as interface and therefore won't be deployed: + +```json +... +development: + interfaces: ['Ownable'], + deploy: { + InheritsOwnable: {} + } +} +... +``` + ## Deployment strategies In order to give users full control over which Smart Contracts should be deployed, Embark comes with a configuration feature called "deployment strategies". Deployment strategies tell Embark whether it should deploy all of the user's Smart Contracts (and its (3rd-party) dependencies, or just deploy individual Smart Contracts.