Merge pull request #384 from embark-framework/chores/test-allpligin-apis

Small fixes for plugin APIs
This commit is contained in:
Iuri Matias 2018-04-26 17:06:05 -04:00 committed by GitHub
commit 17c33ad075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 93 additions and 19 deletions

View File

@ -19,6 +19,8 @@ const Templates = {
class CodeGenerator { class CodeGenerator {
constructor(options) { constructor(options) {
this.blockchainConfig = options.blockchainConfig || {}; this.blockchainConfig = options.blockchainConfig || {};
this.rpcHost = this.blockchainConfig.rpcHost || '';
this.rpcPort = this.blockchainConfig.rpcPort || '';
this.contractsConfig = options.contractsConfig || {}; this.contractsConfig = options.contractsConfig || {};
this.storageConfig = options.storageConfig || {}; this.storageConfig = options.storageConfig || {};
this.communicationConfig = options.communicationConfig || {}; this.communicationConfig = options.communicationConfig || {};

View File

@ -280,17 +280,17 @@ class Deploy {
// calling each beforeDeploy handler declared by the plugin // calling each beforeDeploy handler declared by the plugin
async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => { async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => {
function beforeDeployCb(resObj){
contract.code = resObj.contractCode;
eachCb();
}
beforeDeployFn({ beforeDeployFn({
embarkDeploy: self, embarkDeploy: self,
pluginConfig: plugin.pluginConfig, pluginConfig: plugin.pluginConfig,
deploymentAccount: deploymentAccount, deploymentAccount: deploymentAccount,
contract: contract, contract: contract,
callback: callback: beforeDeployCb
(function(resObj){ }, beforeDeployCb);
contract.code = resObj.contractCode;
eachCb();
})
});
}, () => { }, () => {
//self.logger.info('All beforeDeploy handlers of the plugin has processed.'); //self.logger.info('All beforeDeploy handlers of the plugin has processed.');
eachPluginCb(); eachPluginCb();

View File

@ -286,7 +286,7 @@ Config.prototype.loadFiles = function(files) {
} }
}); });
filesFromPlugins.filter(function(file) { 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); readFiles.push(file);
} }
}); });
@ -301,7 +301,7 @@ Config.prototype.loadPluginContractFiles = function() {
contractsPlugins.forEach(function(plugin) { contractsPlugins.forEach(function(plugin) {
plugin.contractsFiles.forEach(function(file) { plugin.contractsFiles.forEach(function(file) {
var filename = file.replace('./',''); 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)); callback(plugin.loadPluginFile(file));
}})); }}));
}); });

View File

@ -324,7 +324,9 @@ class Embark {
if (cmdPlugins.length > 0) { if (cmdPlugins.length > 0) {
cmdPlugin = cmdPlugins.find((pluginCmd) => { cmdPlugin = cmdPlugins.find((pluginCmd) => {
return pluginCmd.name == platform; return pluginCmd.uploadCmds.some(uploadCmd => {
return uploadCmd.cmd === platform;
});
}); });
} }
if (!cmdPlugin) { if (!cmdPlugin) {

View File

@ -0,0 +1,10 @@
pragma solidity ^0.4.18;
contract PluginStorage {
address public simpleStorageAddress;
address simpleStorageAddress2;
function PluginStorage(address addr) public {
simpleStorageAddress = addr;
}
}

View File

@ -0,0 +1 @@
console.log('File added to the pipeline using embark.addFileToPipeline');

View File

@ -1,12 +1,47 @@
var Haml = require('haml'); const Haml = require('haml');
module.exports = function(embark) { module.exports = function (embark) {
embark.registerServiceCheck('PluginService', function(cb) { embark.registerServiceCheck('PluginService', function (cb) {
cb({name: "ServiceName", status: "on"}); cb({name: "ServiceName", status: "on"});
}); });
embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function(opts) { embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function (opts) {
var source = opts.source; return Haml.render(opts.source);
return Haml.render(source);
}); });
embark.registerContractConfiguration({
"default": {
"contracts": {
"PluginStorage": {
"args": ["$SimpleStorage"]
}
}
}
});
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});
});
embark.registerClientWeb3Provider(function(options) {
return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));";
});
embark.registerConsoleCommand((cmd) => {
if (cmd === "hello") {
return "hello there!";
}
// continue to embark or next plugin;
return false;
});
embark.events.on("contractsDeployed", function() {
embark.logger.info("plugin says: your contracts have been deployed");
});
}; };

View File

@ -14,11 +14,11 @@
}, },
"dependencies": { "dependencies": {
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"embark-service": "./extensions/embark-service", "embark-service": "file:extensions/embark-service",
"jquery": "^1.11.3", "jquery": "^1.11.3",
"react": "^16.0.0", "react": "^16.0.0",
"react-bootstrap": "^0.32.0", "react-bootstrap": "^0.32.0",
"react-dom": "^16.2.0", "react-dom": "^16.2.0",
"zeppelin-solidity": "^1.8.0" "zeppelin-solidity": "1.8.0"
} }
} }

View File

@ -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);
});
});

View File

@ -13,8 +13,6 @@ describe("Token", function() {
var contractsConfig = { var contractsConfig = {
"ZAMyLib": { "ZAMyLib": {
}, },
"Token": {
},
"SimpleStorage": { "SimpleStorage": {
args: [100] args: [100]
}, },