Merge branch 'develop' of github.com:iurimatias/embark-framework into develop

This commit is contained in:
Iuri Matias 2017-03-12 18:58:28 -04:00
commit 915fef9580
11 changed files with 622 additions and 538 deletions

View File

@ -51,16 +51,26 @@ $(document).ready(function() {
EmbarkJS.Storage.saveText(value).then(function(hash) { EmbarkJS.Storage.saveText(value).then(function(hash) {
$("span.textHash").html(hash); $("span.textHash").html(hash);
$("input.textHash").val(hash); $("input.textHash").val(hash);
});
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })"); addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS saveText Error => " + err.message);
}
});
}); });
$("#storage button.loadIpfsHash").click(function() { $("#storage button.loadIpfsHash").click(function() {
var value = $("#storage input.textHash").val(); var value = $("#storage input.textHash").val();
EmbarkJS.Storage.get(value).then(function(content) { EmbarkJS.Storage.get(value).then(function(content) {
$("span.ipfsText").html(content); $("span.ipfsText").html(content);
});
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })"); addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS get Error => " + err.message);
}
});
}); });
$("#storage button.uploadFile").click(function() { $("#storage button.uploadFile").click(function() {
@ -68,8 +78,13 @@ $(document).ready(function() {
EmbarkJS.Storage.uploadFile(input).then(function(hash) { EmbarkJS.Storage.uploadFile(input).then(function(hash) {
$("span.fileIpfsHash").html(hash); $("span.fileIpfsHash").html(hash);
$("input.fileIpfsHash").val(hash); $("input.fileIpfsHash").val(hash);
});
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })"); addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
})
.catch(function(err) {
if(err){
console.log("IPFS uploadFile Error => " + err.message);
}
});
}); });
$("#storage button.loadIpfsFile").click(function() { $("#storage button.loadIpfsFile").click(function() {

View File

@ -13,13 +13,25 @@ The current available storage is IPFS. it can be initialized as
.. code:: javascript .. code:: javascript
EmbarkJS.Storage.saveText("hello world").then(function(hash) {}); EmbarkJS.Storage.saveText("hello world")
.then(function(hash) {})
.catch(function(err) {
if(err){
console.log("IPFS saveText Error => " + err.message);
}
});
**Retrieving Data/Text** **Retrieving Data/Text**
.. code:: javascript .. code:: javascript
EmbarkJS.Storage.get(hash).then(function(content) {}); EmbarkJS.Storage.get(hash)
.then(function(content) {})
.catch(function(err) {
if(err){
console.log("IPFS get Error => " + err.message);
}
});
**Uploading a file** **Uploading a file**
@ -30,7 +42,13 @@ The current available storage is IPFS. it can be initialized as
.. code:: javascript .. code:: javascript
var input = $("input[type=file"]); var input = $("input[type=file"]);
EmbarkJS.Storage.uploadFile(input).then(function(hash) {}); EmbarkJS.Storage.uploadFile(input)
.then(function(hash) {})
.catch(function(err) {
if(err){
console.log("IPFS uploadFile Error => " + err.message);
}
});
**Generate URL to file** **Generate URL to file**

View File

@ -2,56 +2,82 @@ var EmbarkJS =
/******/ (function(modules) { // webpackBootstrap /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache /******/ // The module cache
/******/ var installedModules = {}; /******/ var installedModules = {};
/******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) /******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports; /******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = { /******/ var module = installedModules[moduleId] = {
/******/ exports: {}, /******/ i: moduleId,
/******/ id: moduleId, /******/ l: false,
/******/ loaded: false /******/ exports: {}
/******/ }; /******/ };
/******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.l = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__) /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules; /******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache /******/ // expose the module cache
/******/ __webpack_require__.c = installedModules; /******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__ /******/ // __webpack_public_path__
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(0); /******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
/* 0 */ /* 0 */
/***/ function(module, exports) { /***/ (function(module, exports) {
/*jshint esversion: 6 */ /*jshint esversion: 6 */
//var Ipfs = require('./ipfs.js'); //var Ipfs = require('./ipfs.js');
var EmbarkJS = { var EmbarkJS = {
}; };
EmbarkJS.Contract = function(options) { EmbarkJS.Contract = function(options) {
var self = this; var self = this;
var i, abiElement; var i, abiElement;
@ -148,9 +174,9 @@ var EmbarkJS =
} }
return false; return false;
}); });
}; };
EmbarkJS.Contract.prototype.deploy = function(args, _options) { EmbarkJS.Contract.prototype.deploy = function(args, _options) {
var self = this; var self = this;
var contractParams; var contractParams;
var options = _options || {}; var options = _options || {};
@ -182,15 +208,17 @@ var EmbarkJS =
return promise; return promise;
}; };
EmbarkJS.IPFS = 'ipfs'; EmbarkJS.Storage = {
IPFS : 'ipfs'
};
EmbarkJS.Storage = { EmbarkJS.Storage.setProvider = function(provider, options) {
}; if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
//I don't think currentStorage is used anywhere, this might not be needed
EmbarkJS.Storage.setProvider = function(provider, options) { //for now until additional storage providers are supported. But keeping it
if (provider === 'ipfs') { //anyways
this.currentStorage = EmbarkJS.Storage.IPFS; this.currentStorage = EmbarkJS.Storage.IPFS;
if (options === undefined) { if (options === undefined) {
this.ipfsConnection = IpfsApi('localhost', '5001'); this.ipfsConnection = IpfsApi('localhost', '5001');
@ -198,11 +226,11 @@ var EmbarkJS =
this.ipfsConnection = IpfsApi(options.server, options.port); this.ipfsConnection = IpfsApi(options.server, options.port);
} }
} else { } else {
throw Error('unknown provider'); throw Error('Unknown storage provider');
} }
}; };
EmbarkJS.Storage.saveText = function(text) { EmbarkJS.Storage.saveText = function(text) {
var self = this; var self = this;
if (!this.ipfsConnection) { if (!this.ipfsConnection) {
this.setProvider('ipfs'); this.setProvider('ipfs');
@ -218,9 +246,9 @@ var EmbarkJS =
}); });
return promise; return promise;
}; };
EmbarkJS.Storage.uploadFile = function(inputSelector) { EmbarkJS.Storage.uploadFile = function(inputSelector) {
var self = this; var self = this;
var file = inputSelector[0].files[0]; var file = inputSelector[0].files[0];
@ -249,9 +277,9 @@ var EmbarkJS =
}); });
return promise; return promise;
}; };
EmbarkJS.Storage.get = function(hash) { EmbarkJS.Storage.get = function(hash) {
var self = this; var self = this;
// TODO: detect type, then convert if needed // TODO: detect type, then convert if needed
//var ipfsHash = web3.toAscii(hash); //var ipfsHash = web3.toAscii(hash);
@ -262,22 +290,24 @@ var EmbarkJS =
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
self.ipfsConnection.object.get([hash]).then(function(node) { self.ipfsConnection.object.get([hash]).then(function(node) {
resolve(node.data); resolve(node.data);
}).catch(function (err){
reject(err);
}); });
}); });
return promise; return promise;
}; };
EmbarkJS.Storage.getUrl = function(hash) { EmbarkJS.Storage.getUrl = function(hash) {
//var ipfsHash = web3.toAscii(hash); //var ipfsHash = web3.toAscii(hash);
return 'http://localhost:8080/ipfs/' + hash; return 'http://localhost:8080/ipfs/' + hash;
}; };
EmbarkJS.Messages = { EmbarkJS.Messages = {
}; };
EmbarkJS.Messages.setProvider = function(provider, options) { EmbarkJS.Messages.setProvider = function(provider, options) {
var self = this; var self = this;
var ipfs; var ipfs;
if (provider === 'whisper') { if (provider === 'whisper') {
@ -308,20 +338,20 @@ var EmbarkJS =
} else { } else {
throw Error('unknown provider'); throw Error('unknown provider');
} }
}; };
EmbarkJS.Messages.sendMessage = function(options) { EmbarkJS.Messages.sendMessage = function(options) {
return this.currentMessages.sendMessage(options); return this.currentMessages.sendMessage(options);
}; };
EmbarkJS.Messages.listenTo = function(options) { EmbarkJS.Messages.listenTo = function(options) {
return this.currentMessages.listenTo(options); return this.currentMessages.listenTo(options);
}; };
EmbarkJS.Messages.Whisper = { EmbarkJS.Messages.Whisper = {
}; };
EmbarkJS.Messages.Whisper.sendMessage = function(options) { EmbarkJS.Messages.Whisper.sendMessage = function(options) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
var data = options.data || options.payload; var data = options.data || options.payload;
var identity = options.identity || this.identity || web3.shh.newIdentity(); var identity = options.identity || this.identity || web3.shh.newIdentity();
@ -359,9 +389,9 @@ var EmbarkJS =
}; };
return web3.shh.post(message, function() {}); return web3.shh.post(message, function() {});
}; };
EmbarkJS.Messages.Whisper.listenTo = function(options) { EmbarkJS.Messages.Whisper.listenTo = function(options) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
var _topics = []; var _topics = [];
@ -416,12 +446,12 @@ var EmbarkJS =
promise.filter = filter; promise.filter = filter;
return promise; return promise;
}; };
EmbarkJS.Messages.Orbit = { EmbarkJS.Messages.Orbit = {
}; };
EmbarkJS.Messages.Orbit.sendMessage = function(options) { EmbarkJS.Messages.Orbit.sendMessage = function(options) {
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
var data = options.data || options.payload; var data = options.data || options.payload;
@ -445,9 +475,9 @@ var EmbarkJS =
var payload = JSON.stringify(data); var payload = JSON.stringify(data);
this.orbit.send(topics, data); this.orbit.send(topics, data);
}; };
EmbarkJS.Messages.Orbit.listenTo = function(options) { EmbarkJS.Messages.Orbit.listenTo = function(options) {
var self = this; var self = this;
var topics = options.topic || options.topics; var topics = options.topic || options.topics;
@ -488,10 +518,10 @@ var EmbarkJS =
}); });
return promise; return promise;
}; };
module.exports = EmbarkJS; module.exports = EmbarkJS;
/***/ } /***/ })
/******/ ]); /******/ ]);

View File

@ -137,13 +137,15 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
return promise; return promise;
}; };
EmbarkJS.IPFS = 'ipfs';
EmbarkJS.Storage = { EmbarkJS.Storage = {
IPFS : 'ipfs'
}; };
EmbarkJS.Storage.setProvider = function(provider, options) { EmbarkJS.Storage.setProvider = function(provider, options) {
if (provider === 'ipfs') { if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
//I don't think currentStorage is used anywhere, this might not be needed
//for now until additional storage providers are supported. But keeping it
//anyways
this.currentStorage = EmbarkJS.Storage.IPFS; this.currentStorage = EmbarkJS.Storage.IPFS;
if (options === undefined) { if (options === undefined) {
this.ipfsConnection = IpfsApi('localhost', '5001'); this.ipfsConnection = IpfsApi('localhost', '5001');
@ -151,7 +153,7 @@ EmbarkJS.Storage.setProvider = function(provider, options) {
this.ipfsConnection = IpfsApi(options.server, options.port); this.ipfsConnection = IpfsApi(options.server, options.port);
} }
} else { } else {
throw Error('unknown provider'); throw Error('Unknown storage provider');
} }
}; };
@ -215,6 +217,8 @@ EmbarkJS.Storage.get = function(hash) {
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
self.ipfsConnection.object.get([hash]).then(function(node) { self.ipfsConnection.object.get([hash]).then(function(node) {
resolve(node.data); resolve(node.data);
}).catch(function (err){
reject(err);
}); });
}); });

View File

@ -1,14 +1,6 @@
var async = require('async');
var Web3 = require('web3');
var Engine = require('./engine.js');
var RunCode = require('./runCode.js');
var TestLogger = require('./test_logger.js');
var getSimulator = function() { var getSimulator = function() {
try { try {
var sim = require('ethereumjs-testrpc'); return require('ethereumjs-testrpc');
return sim;
} catch (e) { } catch (e) {
if (e.code === 'MODULE_NOT_FOUND') { if (e.code === 'MODULE_NOT_FOUND') {
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"'); console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
@ -25,28 +17,42 @@ var getSimulator = function() {
} }
}; };
var Test = function(options) { var Test;
this.options = options || {}; Test = (function (options) {
var simOptions = this.options.simulatorOptions || {}; var async = require('async');
var opts = options === undefined ? {} : options;
opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug';
opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {};
var sim = getSimulator();
this.engine = new Engine({ function newWebThree() {
env: this.options.env || 'test', try {
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(sim.provider(opts.simulatorOptions));
return web3;
} catch (e) {
throw new Error(e);
}
}
function deployAll(contractsConfig, cb) {
var RunCode = require('./runCode.js');
var self = this;
function newEngine () {
var Engine = require('./engine.js');
return new Engine({
env: opts.env || 'test',
// TODO: confi will need to detect if this is a obj // TODO: confi will need to detect if this is a obj
embarkConfig: this.options.embarkConfig || 'embark.json', embarkConfig: opts.embarkConfig || 'embark.json',
interceptLogs: false interceptLogs: false
}); });
}
this.engine.init({ self.web3 = newWebThree();
logger: new TestLogger({logLevel: this.options.logLevel || 'debug'}) self.engine = newEngine();
}); self.engine.init();
this.sim = getSimulator();
this.web3 = new Web3();
this.web3.setProvider(this.sim.provider(simOptions));
};
Test.prototype.deployAll = function(contractsConfig, cb) {
var self = this;
async.waterfall([ async.waterfall([
function getConfig(callback) { function getConfig(callback) {
@ -63,24 +69,24 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
callback(); callback();
}, },
function deploy(callback) { function deploy(callback) {
self.engine.events.on('abi-contracts-vanila', function(vanillaABI) { self.engine.events.on('abi-contracts-vanila', function (vanillaABI) {
callback(null, vanillaABI); callback(null, vanillaABI);
}); });
self.engine.deployManager.deployContracts(function(err, result) { self.engine.deployManager.deployContracts(function (err, result) {
if (err) { if (err) {
console.log(err); console.log(err);
callback(err); callback(err);
} }
}); });
} }
], function(err, result) { ], function (err, result) {
if (err) { if (err) {
console.log("got error"); console.log("got error");
process.exit(); process.exit();
} }
// this should be part of the waterfall and not just something done at the // this should be part of the waterfall and not just something done at the
// end // end
self.web3.eth.getAccounts(function(err, accounts) { self.web3.eth.getAccounts(function (err, accounts) {
if (err) { if (err) {
throw new Error(err); throw new Error(err);
} }
@ -89,6 +95,13 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
cb(); cb();
}); });
}); });
}; }
return {
deployAll: deployAll,
sim: sim
};
}());
module.exports = Test; module.exports = Test;

View File

@ -1,13 +1,11 @@
/*jshint esversion: 6 */ /*jshint esversion: 6 */
var async = require('async'); var async = require('async');
//require("./utils/debug_util.js")(__filename, async); // require("./utils/debug_util.js")(__filename, async);
var colors = require('colors'); var colors = require('colors');
var Engine = require('./core/engine.js'); var Engine = require('./core/engine.js');
var Test = require('./core/test.js');
var IPFS = require('./upload/ipfs.js'); var IPFS = require('./upload/ipfs.js');
var Swarm = require('./upload/swarm.js'); var Swarm = require('./upload/swarm.js');
@ -167,6 +165,7 @@ var Embark = (function () {
} }
function initTests (options) { function initTests (options) {
var Test = require('./core/test.js');
return new Test(options); return new Test(options);
} }

View File

@ -2,8 +2,8 @@ var Embark = require('../lib/index');
var Cmd = require('../lib/cmd'); var Cmd = require('../lib/cmd');
describe('embark.Cmd', function () { describe('embark.Cmd', function () {
this.timeout(0);
var cmd = new Cmd(Embark); var cmd = new Cmd(Embark);
describe('#new', function () { describe('#new', function () {
it('it should not create an app without a name', function (done) { it('it should not create an app without a name', function (done) {
cmd.newApp(undefined, function (output) { cmd.newApp(undefined, function (output) {
@ -27,4 +27,15 @@ describe('embark.Cmd', function () {
done(); done();
}); });
}); });
// describe("#help", function () {
// it('it should spit out helpful text if no arguments are supplied', function (done) {
// cmd.process([], function (output) {
// var lines = output.split('\n');
// assert.equal(lines[0], '\n');
// assert.equal(lines[1], 'Usage:');
// done();
// });
// })
// })
}); });

View File

@ -10,7 +10,7 @@
"license": "ISC", "license": "ISC",
"homepage": "", "homepage": "",
"devDependencies": { "devDependencies": {
"embark": "../", "embark": "file:../",
"mocha": "^2.2.5" "mocha": "^2.2.5"
}, },
"dependencies": { "dependencies": {

View File

@ -1,7 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("AnotherStorage", function() { describe("AnotherStorage", function() {
before(function(done) { before(function(done) {

View File

@ -1,7 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("SimpleStorage", function() { describe("SimpleStorage", function() {
before(function(done) { before(function(done) {

View File

@ -1,7 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark'); var EmbarkSpec = require('embark/lib/core/test.js');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("Token", function() { describe("Token", function() {
before(function(done) { before(function(done) {