Skip to content

Commit 17c33ad

Browse files
authored
Merge pull request #384 from embark-framework/chores/test-allpligin-apis
Small fixes for plugin APIs
2 parents 6a3add8 + 5de20c6 commit 17c33ad

File tree

10 files changed

+93
-19
lines changed

10 files changed

+93
-19
lines changed

lib/contracts/code_generator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const Templates = {
1919
class CodeGenerator {
2020
constructor(options) {
2121
this.blockchainConfig = options.blockchainConfig || {};
22+
this.rpcHost = this.blockchainConfig.rpcHost || '';
23+
this.rpcPort = this.blockchainConfig.rpcPort || '';
2224
this.contractsConfig = options.contractsConfig || {};
2325
this.storageConfig = options.storageConfig || {};
2426
this.communicationConfig = options.communicationConfig || {};

lib/contracts/deploy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,17 @@ class Deploy {
280280

281281
// calling each beforeDeploy handler declared by the plugin
282282
async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => {
283+
function beforeDeployCb(resObj){
284+
contract.code = resObj.contractCode;
285+
eachCb();
286+
}
283287
beforeDeployFn({
284288
embarkDeploy: self,
285289
pluginConfig: plugin.pluginConfig,
286290
deploymentAccount: deploymentAccount,
287291
contract: contract,
288-
callback:
289-
(function(resObj){
290-
contract.code = resObj.contractCode;
291-
eachCb();
292-
})
293-
});
292+
callback: beforeDeployCb
293+
}, beforeDeployCb);
294294
}, () => {
295295
//self.logger.info('All beforeDeploy handlers of the plugin has processed.');
296296
eachPluginCb();

lib/core/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Config.prototype.loadFiles = function(files) {
286286
}
287287
});
288288
filesFromPlugins.filter(function(file) {
289-
if (utils.fileMatchesPattern(files, file.intendedPath)) {
289+
if ((file.intendedPath && utils.fileMatchesPattern(files, file.intendedPath)) || utils.fileMatchesPattern(files, file.file)) {
290290
readFiles.push(file);
291291
}
292292
});
@@ -301,7 +301,7 @@ Config.prototype.loadPluginContractFiles = function() {
301301
contractsPlugins.forEach(function(plugin) {
302302
plugin.contractsFiles.forEach(function(file) {
303303
var filename = file.replace('./','');
304-
self.contractsFiles.push(new File({filename: filename, type: File.types.custom, resolver: function(callback) {
304+
self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) {
305305
callback(plugin.loadPluginFile(file));
306306
}}));
307307
});

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ class Embark {
324324

325325
if (cmdPlugins.length > 0) {
326326
cmdPlugin = cmdPlugins.find((pluginCmd) => {
327-
return pluginCmd.name == platform;
327+
return pluginCmd.uploadCmds.some(uploadCmd => {
328+
return uploadCmd.cmd === platform;
329+
});
328330
});
329331
}
330332
if (!cmdPlugin) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pragma solidity ^0.4.18;
2+
contract PluginStorage {
3+
address public simpleStorageAddress;
4+
address simpleStorageAddress2;
5+
6+
function PluginStorage(address addr) public {
7+
simpleStorageAddress = addr;
8+
}
9+
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('File added to the pipeline using embark.addFileToPipeline');
Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
1-
var Haml = require('haml');
1+
const Haml = require('haml');
22

3-
module.exports = function(embark) {
4-
embark.registerServiceCheck('PluginService', function(cb) {
3+
module.exports = function (embark) {
4+
embark.registerServiceCheck('PluginService', function (cb) {
55
cb({name: "ServiceName", status: "on"});
66
});
77

8-
embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function(opts) {
9-
var source = opts.source;
10-
return Haml.render(source);
8+
embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function (opts) {
9+
return Haml.render(opts.source);
1110
});
11+
12+
embark.registerContractConfiguration({
13+
"default": {
14+
"contracts": {
15+
"PluginStorage": {
16+
"args": ["$SimpleStorage"]
17+
}
18+
}
19+
}
20+
});
21+
embark.addContractFile("./contracts/pluginSimpleStorage.sol");
22+
23+
embark.addFileToPipeline('./fileInPipeline.js');
24+
embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js');
25+
26+
embark.registerBeforeDeploy(function (options, callback) {
27+
// Just calling register to prove it works. We don't actually want to change the contracts
28+
callback({contractCode: options.contract.code});
29+
});
30+
31+
embark.registerClientWeb3Provider(function(options) {
32+
return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));";
33+
});
34+
35+
embark.registerConsoleCommand((cmd) => {
36+
if (cmd === "hello") {
37+
return "hello there!";
38+
}
39+
// continue to embark or next plugin;
40+
return false;
41+
});
42+
43+
embark.events.on("contractsDeployed", function() {
44+
embark.logger.info("plugin says: your contracts have been deployed");
45+
});
46+
1247
};

test_apps/test_app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
},
1515
"dependencies": {
1616
"bootstrap": "^3.3.6",
17-
"embark-service": "./extensions/embark-service",
17+
"embark-service": "file:extensions/embark-service",
1818
"jquery": "^1.11.3",
1919
"react": "^16.0.0",
2020
"react-bootstrap": "^0.32.0",
2121
"react-dom": "^16.2.0",
22-
"zeppelin-solidity": "^1.8.0"
22+
"zeppelin-solidity": "1.8.0"
2323
}
2424
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*global contract, before, EmbarkSpec, PluginStorage, SimpleStorage, it*/
2+
const assert = require('assert');
3+
4+
contract("PluginSimpleStorage", function () {
5+
this.timeout(0);
6+
7+
before((done) => {
8+
const contractsConfig = {
9+
"SimpleStorage": {
10+
args: [100]
11+
},
12+
"PluginStorage": {
13+
args: ["$SimpleStorage"]
14+
}
15+
};
16+
EmbarkSpec.deployAll(contractsConfig, () => {
17+
done();
18+
});
19+
});
20+
21+
it("set SimpleStorage address", async function () {
22+
let result = await PluginStorage.methods.simpleStorageAddress().call();
23+
assert.equal(result.toString(), SimpleStorage.options.address);
24+
});
25+
26+
});

test_apps/test_app/test/token_spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ describe("Token", function() {
1313
var contractsConfig = {
1414
"ZAMyLib": {
1515
},
16-
"Token": {
17-
},
1816
"SimpleStorage": {
1917
args: [100]
2018
},

0 commit comments

Comments
 (0)