From 0c7c3e83feb9554fa6497349e9783581dcfb0629 Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Fri, 30 Aug 2019 05:27:01 +1000 Subject: [PATCH] fix(@embark/embark-deployment): Undeployed contract artifacts (#1815) Contract artifacts were not being generated nor run through the VM if the contracts/interfaces were not deployed. These features were executed as actions on the `deployment:contract:deployed` event. This PR runs executes the same actions for `deployment:contract:undeployed` event as the `deployment:contract:deployed` event, which occurs when a contract is not deployed. --- packages/embark-deployment/src/contract_deployer.js | 5 +++-- packages/embark-specialconfigs/src/index.js | 2 +- packages/embark-web3/src/index.js | 4 +++- packages/embark/src/cmd/dashboard/dashboard.js | 9 ++++++++- .../src/lib/modules/ethereum-blockchain-client/index.js | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/embark-deployment/src/contract_deployer.js b/packages/embark-deployment/src/contract_deployer.js index 2f35b0376..f02dd94c9 100644 --- a/packages/embark-deployment/src/contract_deployer.js +++ b/packages/embark-deployment/src/contract_deployer.js @@ -32,8 +32,9 @@ class ContractDeployer { (params, next) => { if (!params.shouldDeploy) { - this.events.emit("deployment:contract:undeployed", contract); - return next(null, null); + return this.plugins.emitAndRunActionsForEvent('deployment:contract:undeployed', {contract}, (err, _params) => { + next(err, null); + }); } // TODO: implement `blockchainType` a la `this.deployer[contract.blockchainType].apply(this.deployer, [contract, next])` diff --git a/packages/embark-specialconfigs/src/index.js b/packages/embark-specialconfigs/src/index.js index 2b16beae3..6ecf438cf 100644 --- a/packages/embark-specialconfigs/src/index.js +++ b/packages/embark-specialconfigs/src/index.js @@ -70,7 +70,7 @@ class SpecialConfigs { return this.functionConfigs.deployIfAction(params, cb); } return this.listConfigs.deployIfAction(params, cb); - } + } } diff --git a/packages/embark-web3/src/index.js b/packages/embark-web3/src/index.js index 36a9dd0e8..f8ebdd26f 100644 --- a/packages/embark-web3/src/index.js +++ b/packages/embark-web3/src/index.js @@ -25,9 +25,11 @@ class EmbarkWeb3 { this.events.on("blockchain:started", this.registerWeb3Object.bind(this)); embark.registerActionForEvent("pipeline:generateAll:before", this.addWeb3Artifact.bind(this)); embark.registerActionForEvent("deployment:contract:deployed", this.registerInVm.bind(this)); + embark.registerActionForEvent("deployment:contract:undeployed", this.registerInVm.bind(this)); embark.registerActionForEvent("deployment:contract:deployed", this.registerArtifact.bind(this)); + embark.registerActionForEvent("deployment:contract:undeployed", this.registerArtifact.bind(this)); - this.registerWeb3Help() + this.registerWeb3Help(); } async registerWeb3Object() { diff --git a/packages/embark/src/cmd/dashboard/dashboard.js b/packages/embark/src/cmd/dashboard/dashboard.js index f1c97e304..09ab719bd 100644 --- a/packages/embark/src/cmd/dashboard/dashboard.js +++ b/packages/embark/src/cmd/dashboard/dashboard.js @@ -69,7 +69,14 @@ class Dashboard { this.events.on("deployment:contract:deployed", (_contract) => { // self.events.emit('contractsState', self.contractsState()); this.events.request("contracts:state", (err, contracts) => { - monitor.setContracts(contracts) + monitor.setContracts(contracts); + }); + }); + + this.events.on("deployment:contract:undeployed", (_contract) => { + // self.events.emit('contractsState', self.contractsState()); + this.events.request("contracts:state", (err, contracts) => { + monitor.setContracts(contracts); }); }); diff --git a/packages/embark/src/lib/modules/ethereum-blockchain-client/index.js b/packages/embark/src/lib/modules/ethereum-blockchain-client/index.js index c80a856f3..906481c5c 100644 --- a/packages/embark/src/lib/modules/ethereum-blockchain-client/index.js +++ b/packages/embark/src/lib/modules/ethereum-blockchain-client/index.js @@ -13,6 +13,7 @@ class EthereumBlockchainClient { this.events = embark.events; this.logger = embark.logger; + this.embark.registerActionForEvent("deployment:contract:undeployed", this.addContractJSONToPipeline.bind(this)); this.embark.registerActionForEvent("deployment:contract:deployed", this.addContractJSONToPipeline.bind(this)); this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.determineArguments.bind(this)); this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.doLinking.bind(this));