From c818326f2e50df6a880f5a4d5d316957d817965c Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 25 Apr 2018 13:05:58 -0400 Subject: [PATCH 1/6] test add config and contract and add test --- lib/core/config.js | 2 +- .../contracts/pluginSimpleStorage.sol | 10 +++++++ .../extensions/embark-service/index.js | 22 +++++++++++----- .../test_app/test/plugin_storage_spec.js | 26 +++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol create mode 100644 test_apps/test_app/test/plugin_storage_spec.js diff --git a/lib/core/config.js b/lib/core/config.js index 75e5b86f3..89dd2b499 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -301,7 +301,7 @@ Config.prototype.loadPluginContractFiles = function() { contractsPlugins.forEach(function(plugin) { plugin.contractsFiles.forEach(function(file) { var filename = file.replace('./',''); - self.contractsFiles.push(new File({filename: filename, type: File.types.custom, resolver: function(callback) { + self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) { callback(plugin.loadPluginFile(file)); }})); }); diff --git a/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol b/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol new file mode 100644 index 000000000..4d01d6b32 --- /dev/null +++ b/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.4.18; +contract PluginStorage { + address public simpleStorageAddress; + address simpleStorageAddress2; + + function PluginStorage(address addr) public { + simpleStorageAddress = addr; + } + +} diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index 0ca3ff1d5..7b0d62613 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -1,12 +1,22 @@ -var Haml = require('haml'); +const Haml = require('haml'); -module.exports = function(embark) { - embark.registerServiceCheck('PluginService', function(cb) { +module.exports = function (embark) { + embark.registerServiceCheck('PluginService', function (cb) { cb({name: "ServiceName", status: "on"}); }); - embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function(opts) { - var source = opts.source; - return Haml.render(source); + embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function (opts) { + return Haml.render(opts.source); }); + + embark.registerContractConfiguration({ + "default": { + "contracts": { + "PluginStorage": { + "args": ["$SimpleStorage"] + } + } + } + }); + embark.addContractFile("./contracts/pluginSimpleStorage.sol"); }; diff --git a/test_apps/test_app/test/plugin_storage_spec.js b/test_apps/test_app/test/plugin_storage_spec.js new file mode 100644 index 000000000..24a58c4e8 --- /dev/null +++ b/test_apps/test_app/test/plugin_storage_spec.js @@ -0,0 +1,26 @@ +/*global contract, before, EmbarkSpec, PluginStorage, SimpleStorage, it*/ +const assert = require('assert'); + +contract("PluginSimpleStorage", function () { + this.timeout(0); + + before((done) => { + const contractsConfig = { + "SimpleStorage": { + args: [100] + }, + "PluginStorage": { + args: ["$SimpleStorage"] + } + }; + EmbarkSpec.deployAll(contractsConfig, () => { + done(); + }); + }); + + it("set SimpleStorage address", async function () { + let result = await PluginStorage.methods.simpleStorageAddress().call(); + assert.equal(result.toString(), SimpleStorage.options.address); + }); + +}); From 61be2c7bd78864ac6483975fe2ace845e700575c Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 25 Apr 2018 15:01:01 -0400 Subject: [PATCH 2/6] addFileToPipeline test and registerBeforeDeploy with new arg --- lib/contracts/deploy.js | 12 ++++++------ lib/core/config.js | 2 +- .../extensions/embark-service/fileInPipeline.js | 1 + .../test_app/extensions/embark-service/index.js | 8 ++++++++ test_apps/test_app/package.json | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 test_apps/test_app/extensions/embark-service/fileInPipeline.js diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index d1b87ade3..f37abec47 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -280,17 +280,17 @@ class Deploy { // calling each beforeDeploy handler declared by the plugin async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => { + function beforeDeployCb(resObj){ + contract.code = resObj.contractCode; + eachCb(); + } beforeDeployFn({ embarkDeploy: self, pluginConfig: plugin.pluginConfig, deploymentAccount: deploymentAccount, contract: contract, - callback: - (function(resObj){ - contract.code = resObj.contractCode; - eachCb(); - }) - }); + callback: beforeDeployCb + }, beforeDeployCb); }, () => { //self.logger.info('All beforeDeploy handlers of the plugin has processed.'); eachPluginCb(); diff --git a/lib/core/config.js b/lib/core/config.js index 89dd2b499..7061faddd 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -286,7 +286,7 @@ Config.prototype.loadFiles = function(files) { } }); filesFromPlugins.filter(function(file) { - if (utils.fileMatchesPattern(files, file.intendedPath)) { + if ((file.intendedPath && utils.fileMatchesPattern(files, file.intendedPath)) || utils.fileMatchesPattern(files, file.file)) { readFiles.push(file); } }); diff --git a/test_apps/test_app/extensions/embark-service/fileInPipeline.js b/test_apps/test_app/extensions/embark-service/fileInPipeline.js new file mode 100644 index 000000000..85f768539 --- /dev/null +++ b/test_apps/test_app/extensions/embark-service/fileInPipeline.js @@ -0,0 +1 @@ +console.log('File added to the pipeline using embark.addFileToPipeline'); diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index 7b0d62613..be4f4366e 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -19,4 +19,12 @@ module.exports = function (embark) { } }); embark.addContractFile("./contracts/pluginSimpleStorage.sol"); + + embark.addFileToPipeline('./fileInPipeline.js'); + embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js'); + + embark.registerBeforeDeploy(function(options, callback) { + // Just calling register to prove it works. We don't actually want to change the contracts + callback({contractCode: options.contract.code}); + }); }; diff --git a/test_apps/test_app/package.json b/test_apps/test_app/package.json index 8711dde1d..80985c8d1 100644 --- a/test_apps/test_app/package.json +++ b/test_apps/test_app/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "bootstrap": "^3.3.6", - "embark-service": "./extensions/embark-service", + "embark-service": "file:extensions/embark-service", "jquery": "^1.11.3", "react": "^16.0.0", "react-bootstrap": "^0.32.0", From e4566f9f817ab15156febf4130e34abff1b483fb Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 25 Apr 2018 16:27:47 -0400 Subject: [PATCH 3/6] add more registers but generation one fails in run --- lib/contracts/code_generator.js | 2 ++ .../extensions/embark-service/index.js | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 3072cd81b..6b8306aec 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -19,6 +19,8 @@ const Templates = { class CodeGenerator { constructor(options) { this.blockchainConfig = options.blockchainConfig || {}; + this.rpcHost = this.blockchainConfig.rpcHost || ''; + this.rpcPort = this.blockchainConfig.rpcPort || ''; this.contractsConfig = options.contractsConfig || {}; this.storageConfig = options.storageConfig || {}; this.communicationConfig = options.communicationConfig || {}; diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index be4f4366e..773c00b13 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -23,8 +23,33 @@ module.exports = function (embark) { embark.addFileToPipeline('./fileInPipeline.js'); embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js'); - embark.registerBeforeDeploy(function(options, callback) { + embark.registerBeforeDeploy(function (options, callback) { // Just calling register to prove it works. We don't actually want to change the contracts callback({contractCode: options.contract.code}); }); + + embark.registerClientWeb3Provider(function(options) { + return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));"; + }); + + /*embark.registerContractsGeneration(function (options) { + const contractGenerations = []; + Object.keys(options.contracts).map(className => { + const contract = options.contracts[className]; + const abi = JSON.stringify(contract.abiDefinition); + + contractGenerations.push(`${className} = new this.web3.eth.contract('${abi}').at('${contract.deployedAddress}')`); + }); + return contractGenerations.join('\n'); + // return ''; + });*/ + + embark.registerConsoleCommand((cmd) => { + if (cmd === "hello") { + return "hello there!"; + } + // continue to embark or next plugin; + return false; + }); + }; From d046feb83da2295e714d2991f800a1c47f64db79 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 26 Apr 2018 14:00:41 -0400 Subject: [PATCH 4/6] fix a bug where upload cmd used plugin name --- lib/index.js | 4 +++- .../test_app/extensions/embark-service/index.js | 16 ++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index e321a4be2..f1a2454fa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -312,7 +312,9 @@ class Embark { if (cmdPlugins.length > 0) { cmdPlugin = cmdPlugins.find((pluginCmd) => { - return pluginCmd.name == platform; + return pluginCmd.uploadCmds.some(uploadCmd => { + return uploadCmd.cmd === platform; + }); }); } if (!cmdPlugin) { diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index 773c00b13..fb5a56bd4 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -32,18 +32,6 @@ module.exports = function (embark) { return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));"; }); - /*embark.registerContractsGeneration(function (options) { - const contractGenerations = []; - Object.keys(options.contracts).map(className => { - const contract = options.contracts[className]; - const abi = JSON.stringify(contract.abiDefinition); - - contractGenerations.push(`${className} = new this.web3.eth.contract('${abi}').at('${contract.deployedAddress}')`); - }); - return contractGenerations.join('\n'); - // return ''; - });*/ - embark.registerConsoleCommand((cmd) => { if (cmd === "hello") { return "hello there!"; @@ -52,4 +40,8 @@ module.exports = function (embark) { return false; }); + embark.events.on("contractsDeployed", function() { + embark.logger.info("plugin says: your contracts have been deployed"); + }); + }; From 797e43cedc26c6a7d3dbf717dbe5758b9abd2aa4 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 26 Apr 2018 15:09:39 -0400 Subject: [PATCH 5/6] remove duplicated entry --- test_apps/test_app/test/token_spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test_apps/test_app/test/token_spec.js b/test_apps/test_app/test/token_spec.js index c76728c04..88dfc1a87 100644 --- a/test_apps/test_app/test/token_spec.js +++ b/test_apps/test_app/test/token_spec.js @@ -13,8 +13,6 @@ describe("Token", function() { var contractsConfig = { "ZAMyLib": { }, - "Token": { - }, "SimpleStorage": { args: [100] }, From 5de20c6bafbe65cf73fcc6c856ec5a5721ed05d2 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 26 Apr 2018 16:35:00 -0400 Subject: [PATCH 6/6] force zepplein version for travis --- test_apps/test_app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_apps/test_app/package.json b/test_apps/test_app/package.json index 80985c8d1..b29e3d6ca 100644 --- a/test_apps/test_app/package.json +++ b/test_apps/test_app/package.json @@ -19,6 +19,6 @@ "react": "^16.0.0", "react-bootstrap": "^0.32.0", "react-dom": "^16.2.0", - "zeppelin-solidity": "^1.8.0" + "zeppelin-solidity": "1.8.0" } }