Merge branch 'develop' into bug_fix/slow-pipeline

This commit is contained in:
Iuri Matias 2018-06-12 12:06:01 -04:00 committed by GitHub
commit 79282f8d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1034 additions and 30 deletions

View File

@ -1,9 +1,14 @@
var EmbarkJS = {
onReady: __embarkContext.execWhenReady
onReady: function(cb) {
if (typeof (__embarkContext) === 'undefined') {
return cb();
}
return __embarkContext.execWhenReady(cb);
}
};
EmbarkJS.isNewWeb3 = function() {
var _web3 = new Web3();
EmbarkJS.isNewWeb3 = function(web3Obj) {
var _web3 = web3Obj || (new Web3());
if (typeof(_web3.version) === "string") {
return true;
}
@ -17,19 +22,75 @@ EmbarkJS.Contract = function(options) {
this.abi = options.abi;
this.address = options.address;
this.gas = options.gas;
this.code = '0x' + options.code;
//this.web3 = options.web3 || web3;
this.web3 = options.web3 || window.web3;
this.web3 = options.web3;
if (!this.web3 && typeof (web3) !== 'undefined') {
this.web3 = web3;
} else if (!this.web3) {
this.web3 = window.web3;
}
if (EmbarkJS.isNewWeb3()) {
// TODO:
// add default **from** address
// add gasPrice
if (EmbarkJS.isNewWeb3(this.web3)) {
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
ContractClass.setProvider(this.web3.currentProvider);
ContractClass.options.data = this.code;
ContractClass.options.from = this.from;
ContractClass.abi = ContractClass.options.abi;
ContractClass.address = this.address;
ContractClass.gas = this.gas;
let originalMethods = Object.keys(ContractClass);
ContractClass._jsonInterface.forEach((abi) => {
if (originalMethods.indexOf(abi.name) >= 0) {
console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event");
return;
}
if (!abi.inputs) {
return;
}
let numExpectedInputs = abi.inputs.length;
if (abi.type === 'function' && abi.constant) {
ContractClass[abi.name] = function() {
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
if (typeof (arguments[numExpectedInputs]) === 'function') {
cb = arguments[numExpectedInputs];
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
options = arguments[numExpectedInputs];
cb = arguments[numExpectedInputs + 1];
}
let ref = ContractClass.methods[abi.name];
let call = ref.apply(ref, ...arguments).call;
return call.apply(call, []);
};
} else if (abi.type === 'function') {
ContractClass[abi.name] = function() {
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
if (typeof (arguments[numExpectedInputs]) === 'function') {
cb = arguments[numExpectedInputs];
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
options = arguments[numExpectedInputs];
cb = arguments[numExpectedInputs + 1];
}
let ref = ContractClass.methods[abi.name];
let send = ref.apply(ref, args).send;
return send.apply(send, [options, cb]);
};
} else if (abi.type === 'event') {
ContractClass[abi.name] = function(options, cb) {
let ref = ContractClass.events[abi.name];
return ref.apply(ref, [options, cb]);
}
}
});
return ContractClass;
} else {
ContractClass = this.web3.eth.contract(this.abi);
@ -315,9 +376,9 @@ EmbarkJS.Names.lookup = function(identifier) {
// To Implement
/*
// register a name
// register a name
EmbarkJS.Names.register = function(name, options) {
}
*/

396
js/embark_node.js Normal file
View File

@ -0,0 +1,396 @@
var EmbarkJS = {
onReady: function(cb) {
if (typeof (__embarkContext) === 'undefined') {
return cb();
}
return __embarkContext.execWhenReady(cb);
}
};
EmbarkJS.isNewWeb3 = function(web3Obj) {
var _web3 = web3Obj || (new Web3());
if (typeof(_web3.version) === "string") {
return true;
}
return parseInt(_web3.version.api.split('.')[0], 10) >= 1;
};
EmbarkJS.Contract = function(options) {
var self = this;
var i, abiElement;
var ContractClass;
this.abi = options.abi;
this.address = options.address;
this.gas = options.gas;
this.code = '0x' + options.code;
//this.web3 = options.web3 || web3;
this.web3 = options.web3;
if (!this.web3 && typeof (web3) !== 'undefined') {
this.web3 = web3;
} else if (!this.web3) {
this.web3 = window.web3;
}
if (EmbarkJS.isNewWeb3(this.web3)) {
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
ContractClass.setProvider(this.web3.currentProvider);
ContractClass.options.data = this.code;
ContractClass.options.from = this.from;
ContractClass.abi = ContractClass.options.abi;
ContractClass.address = this.address;
ContractClass.gas = this.gas;
let originalMethods = Object.keys(ContractClass);
ContractClass._jsonInterface.forEach((abi) => {
if (originalMethods.indexOf(abi.name) >= 0) {
console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event");
return;
}
if (!abi.inputs) {
return;
}
let numExpectedInputs = abi.inputs.length;
if (abi.type === 'function' && abi.constant) {
ContractClass[abi.name] = function() {
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
if (typeof (arguments[numExpectedInputs]) === 'function') {
cb = arguments[numExpectedInputs];
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
options = arguments[numExpectedInputs];
cb = arguments[numExpectedInputs + 1];
}
let ref = ContractClass.methods[abi.name];
let call = ref.apply(ref, ...arguments).call;
return call.apply(call, []);
};
} else if (abi.type === 'function') {
ContractClass[abi.name] = function() {
let options = {}, cb = null, args = Array.from(arguments || []).slice(0, numExpectedInputs);
if (typeof (arguments[numExpectedInputs]) === 'function') {
cb = arguments[numExpectedInputs];
} else if (typeof (arguments[numExpectedInputs]) === 'object') {
options = arguments[numExpectedInputs];
cb = arguments[numExpectedInputs + 1];
}
let ref = ContractClass.methods[abi.name];
let send = ref.apply(ref, args).send;
return send.apply(send, [options, cb]);
};
} else if (abi.type === 'event') {
ContractClass[abi.name] = function(options, cb) {
let ref = ContractClass.events[abi.name];
return ref.apply(ref, [options, cb]);
}
}
});
return ContractClass;
} else {
ContractClass = this.web3.eth.contract(this.abi);
this.eventList = [];
if (this.abi) {
for (i = 0; i < this.abi.length; i++) {
abiElement = this.abi[i];
if (abiElement.type === 'event') {
this.eventList.push(abiElement.name);
}
}
}
var messageEvents = function() {
this.cb = function() {};
};
messageEvents.prototype.then = function(cb) {
this.cb = cb;
};
messageEvents.prototype.error = function(err) {
return err;
};
this._originalContractObject = ContractClass.at(this.address);
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function(p) {
// TODO: check for forbidden properties
if (self.eventList.indexOf(p) >= 0) {
self[p] = function() {
var promise = new messageEvents();
var args = Array.prototype.slice.call(arguments);
args.push(function(err, result) {
if (err) {
promise.error(err);
} else {
promise.cb(result);
}
});
self._originalContractObject[p].apply(self._originalContractObject[p], args);
return promise;
};
return true;
} else if (typeof self._originalContractObject[p] === 'function') {
self[p] = function(_args) {
var args = Array.prototype.slice.call(arguments);
var fn = self._originalContractObject[p];
var props = self.abi.find((x) => x.name == p);
var promise = new Promise(function(resolve, reject) {
args.push(function(err, transaction) {
promise.tx = transaction;
if (err) {
return reject(err);
}
var getConfirmation = function() {
self.web3.eth.getTransactionReceipt(transaction, function(err, receipt) {
if (err) {
return reject(err);
}
if (receipt !== null) {
return resolve(receipt);
}
setTimeout(getConfirmation, 1000);
});
};
if (typeof(transaction) !== "string" || props.constant) {
resolve(transaction);
} else {
getConfirmation();
}
});
fn.apply(fn, args);
});
return promise;
};
return true;
}
return false;
});
}
};
EmbarkJS.Contract.prototype.deploy = function(args, _options) {
var self = this;
var contractParams;
var options = _options || {};
contractParams = args || [];
contractParams.push({
from: this.web3.eth.accounts[0],
data: this.code,
gas: options.gas || 800000
});
var contractObject = this.web3.eth.contract(this.abi);
var promise = new Promise(function(resolve, reject) {
contractParams.push(function(err, transaction) {
if (err) {
reject(err);
} else if (transaction.address !== undefined) {
resolve(new EmbarkJS.Contract({
abi: self.abi,
code: self.code,
address: transaction.address
}));
}
});
// returns promise
// deploys contract
// wraps it around EmbarkJS.Contract
contractObject["new"].apply(contractObject, contractParams);
});
return promise;
};
EmbarkJS.Contract.prototype.new = EmbarkJS.Contract.prototype.deploy;
EmbarkJS.Contract.prototype.at = function(address) {
return new EmbarkJS.Contract({ abi: this.abi, code: this.code, address: address });
};
EmbarkJS.Contract.prototype.send = function(value, unit, _options) {
var options, wei;
if (typeof unit === 'object') {
options = unit;
wei = value;
} else {
options = _options || {};
wei = this.web3.toWei(value, unit);
}
options.to = this.address;
options.value = wei;
this.web3.eth.sendTransaction(options);
};
EmbarkJS.Storage = {};
EmbarkJS.Storage.Providers = {};
EmbarkJS.Storage.saveText = function(text) {
if (!this.currentStorage) {
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
}
return this.currentStorage.saveText(text);
};
EmbarkJS.Storage.get = function(hash) {
if (!this.currentStorage) {
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
}
return this.currentStorage.get(hash);
};
EmbarkJS.Storage.uploadFile = function(inputSelector) {
if (!this.currentStorage) {
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
}
return this.currentStorage.uploadFile(inputSelector);
};
EmbarkJS.Storage.getUrl = function(hash) {
if (!this.currentStorage) {
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
}
return this.currentStorage.getUrl(hash);
};
EmbarkJS.Storage.registerProvider = function(providerName, obj) {
EmbarkJS.Storage.Providers[providerName] = obj;
};
EmbarkJS.Storage.setProvider = function(provider, options) {
let providerObj = this.Providers[provider];
if (!providerObj) {
throw new Error('Unknown storage provider');
}
this.currentStorage = providerObj;
return providerObj.setProvider(options);
};
EmbarkJS.Storage.isAvailable = function(){
if (!this.currentStorage) {
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
}
return this.currentStorage.isAvailable();
};
EmbarkJS.Messages = {};
EmbarkJS.Messages.Providers = {};
EmbarkJS.Messages.registerProvider = function(providerName, obj) {
EmbarkJS.Messages.Providers[providerName] = obj;
};
EmbarkJS.Messages.setProvider = function(provider, options) {
let providerObj = this.Providers[provider];
if (!providerObj) {
throw new Error('Unknown messages provider');
}
this.currentMessages = providerObj;
return providerObj.setProvider(options);
};
EmbarkJS.Messages.isAvailable = function(){
return this.currentMessages.isAvailable();
};
EmbarkJS.Messages.sendMessage = function(options) {
if (!this.currentMessages) {
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
}
return this.currentMessages.sendMessage(options);
};
EmbarkJS.Messages.listenTo = function(options, callback) {
if (!this.currentMessages) {
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
}
return this.currentMessages.listenTo(options, callback);
};
EmbarkJS.Names = {};
EmbarkJS.Names.Providers = {};
EmbarkJS.Names.registerProvider = function(providerName, obj) {
EmbarkJS.Names.Providers[providerName] = obj;
}
EmbarkJS.Names.setProvider = function(provider, options) {
let providerObj = this.Providers[provider];
if (!providerObj) {
throw new Error('Unknown name system provider');
}
this.currentNameSystems = providerObj;
return providerObj.setProvider(options);
};
// resolve resolves a name into an identifier of some kind
EmbarkJS.Names.resolve = function(name) {
if (!this.currentNameSystems) {
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
}
return this.currentNameSystems.resolve(name);
}
// the reverse of resolve, resolves using an identifier to get to a name
EmbarkJS.Names.lookup = function(identifier) {
if (!this.currentNameSystems) {
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
}
return this.currentNameSystems.lookup(identifier);
}
// To Implement
/*
// register a name
EmbarkJS.Names.register = function(name, options) {
}
*/
EmbarkJS.Utils = {
fromAscii: function(str) {
var _web3 = new Web3();
return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str);
},
toAscii: function(str) {
var _web3 = new Web3();
return _web3.utils.toAscii(str);
}
};
module.exports = EmbarkJS;

View File

@ -3,6 +3,7 @@ const child_process = require('child_process');
const _ = require('underscore');
const fs = require('../../core/fs.js');
const constants = require('../../constants.json');
const GethCommands = require('./geth_commands.js');
@ -48,6 +49,8 @@ var Blockchain = function(options) {
verbosity: this.blockchainConfig.verbosity
};
this.setupProxy();
if (this.blockchainConfig === {} || JSON.stringify(this.blockchainConfig) === '{"enabled":true}') {
this.config.account = {};
this.config.account.password = fs.embarkPath("templates/boilerplate/config/development/password");
@ -72,6 +75,24 @@ var Blockchain = function(options) {
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
};
Blockchain.prototype.setupProxy = function() {
this.config.proxy = true;
if (this.blockchainConfig.proxy === false) {
this.config.proxy = false;
return;
}
const proxy = require('../../core/proxy');
const Ipc = require('../../core/ipc');
let ipcObject = new Ipc({ipcRole: 'client'});
proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false);
proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true);
this.config.rpcPort += constants.blockchain.servicePortOnProxy;
this.config.wsPort += constants.blockchain.servicePortOnProxy;
};
Blockchain.prototype.runCommand = function(cmd, options, callback) {
console.log(__("running: %s", cmd.underline).green);
if (this.blockchainConfig.silent) {

View File

@ -1,4 +1,7 @@
let shelljs = require('shelljs');
let proxy = require('../core/proxy');
const Ipc = require('../core/ipc');
const constants = require('../constants.json');
class Simulator {
constructor(options) {
@ -17,8 +20,12 @@ class Simulator {
process.exit();
}
cmds.push("-p " + (options.port || this.blockchainConfig.rpcPort || 8545));
cmds.push("-h " + (options.host || this.blockchainConfig.rpcHost || 'localhost'));
let useProxy = this.blockchainConfig.proxy || false;
let host = (options.host || this.blockchainConfig.rpcHost || 'localhost');
let port = (options.port || this.blockchainConfig.rpcPort || 8545);
cmds.push("-p " + (port + (useProxy ? constants.blockchain.servicePortOnProxy : 0)));
cmds.push("-h " + host);
cmds.push("-a " + (options.numAccounts || 10));
cmds.push("-e " + (options.defaultBalance || 100));
cmds.push("-l " + (options.gasLimit || 8000000));
@ -36,7 +43,14 @@ class Simulator {
}
const program = ganache ? 'ganache-cli' : 'testrpc';
shelljs.exec(`${program} ${cmds.join(' ')}`, {async : true});
if(useProxy){
let ipcObject = new Ipc({ipcRole: 'client'});
proxy.serve(ipcObject, host, port, false);
}
}
}

View File

@ -35,7 +35,8 @@
"blockchain": {
"blockchainReady": "blockchainReady",
"init": "init",
"initiated": "initiated"
"initiated": "initiated",
"servicePortOnProxy": 10
},
"storage": {
"init": "init",

View File

@ -184,12 +184,17 @@ class Engine {
});
this.ipc = new IPC({logger: this.logger, ipcRole: options.ipcRole});
if (this.ipc.isServer()) {
this.ipc.serve();
}
this.registerModule('solidity', {ipc: this.ipc});
this.registerModule('vyper');
this.registerModule('profiler');
this.registerModule('fuzzer');
this.registerModule('deploytracker');
this.registerModule('specialconfigs');
this.registerModule('console_listener', {ipc: this.ipc});
const ContractsManager = require('../contracts/contracts.js');
this.contractsManager = new ContractsManager({

125
lib/core/proxy.js Normal file
View File

@ -0,0 +1,125 @@
const httpProxy = require('http-proxy');
const http = require('http');
const constants = require('../constants.json');
let commList = {};
let transactions = {};
let receipts = {};
const parseRequest = function(reqBody){
let jsonO;
try {
jsonO = JSON.parse(reqBody);
} catch(e){
return; // Request is not a json. Do nothing
}
if(jsonO.method === "eth_sendTransaction"){
commList[jsonO.id] = {
type: 'contract-log',
address: jsonO.params[0].to,
data: jsonO.params[0].data
};
} else if(jsonO.method === "eth_getTransactionReceipt"){
if(transactions[jsonO.params[0]]){
transactions[jsonO.params[0]].receiptId = jsonO.id;
receipts[jsonO.id] = transactions[jsonO.params[0]].commListId;
}
}
};
const parseResponse = function(ipc, resBody){
let jsonO;
try {
jsonO = JSON.parse(resBody);
} catch(e) {
return; // Response is not a json. Do nothing
}
if(commList[jsonO.id]){
commList[jsonO.id].transactionHash = jsonO.result;
transactions[jsonO.result] = {commListId: jsonO.id};
} else if(receipts[jsonO.id] && jsonO.result && jsonO.result.blockNumber){
commList[receipts[jsonO.id]].blockNumber = jsonO.result.blockNumber;
commList[receipts[jsonO.id]].gasUsed = jsonO.result.gasUsed;
commList[receipts[jsonO.id]].status = jsonO.result.status;
if(ipc.connected && !ipc.connecting){
ipc.request('log', commList[receipts[jsonO.id]]);
} else {
ipc.connecting = true;
ipc.connect(() => {
ipc.connecting = false;
});
}
delete transactions[commList[receipts[jsonO.id]].transactionHash];
delete receipts[jsonO.id];
delete commList[jsonO.id];
}
};
exports.serve = function(ipc, host, port, ws){
let proxy = httpProxy.createProxyServer({
target: {
host,
port: port + constants.blockchain.servicePortOnProxy
},
ws: ws
});
proxy.on('error', function () {
console.log(__("Error forwarding requests to blockchain/simulator"));
process.exit();
});
proxy.on('proxyRes', (proxyRes) => {
let resBody = [];
proxyRes.on('data', (b) => resBody.push(b));
proxyRes.on('end', function () {
resBody = Buffer.concat(resBody).toString();
if(resBody){
parseResponse(ipc, resBody);
}
});
});
let server = http.createServer((req, res) => {
let reqBody = [];
req.on('data', (b) => { reqBody.push(b); })
.on('end', () => {
reqBody = Buffer.concat(reqBody).toString();
if(reqBody){
parseRequest(reqBody);
}
});
if(!ws){
proxy.web(req, res);
}
});
if(ws){
const WsParser = require('simples/lib/parsers/ws'); // npm install simples
server.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
proxy.on('open', (proxySocket) => {
proxySocket.on('data', (data) => {
parseResponse(ipc, data.toString().substr(data.indexOf("{")));
});
});
proxy.on('proxyReqWs', (proxyReq, req, socket) => {
var parser = new WsParser(0, false);
socket.pipe(parser);
parser.on('frame', function (frame) {
parseRequest(frame.data);
});
});
}
server.listen(port);
};

View File

@ -51,7 +51,10 @@ class Embark {
simulator(options) {
this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain];
let Simulator = require('./cmds/simulator.js');
let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig, logger: this.logger});
let simulator = new Simulator({
blockchainConfig: this.config.blockchainConfig,
logger: this.logger
});
simulator.run(options);
}

View File

@ -0,0 +1,92 @@
const utils = require('../../utils/utils.js');
class ConsoleListener {
constructor(embark, options) {
this.logger = embark.logger;
this.ipc = options.ipc;
this.events = embark.events;
this.addressToContract = [];
this.contractsConfig = embark.config.contractsConfig;
this.contractsDeployed = false;
this._listenForLogRequests();
this.events.on("contractsDeployed", () => {
this.contractsDeployed = true;
this._updateContractList();
});
}
_updateContractList(){
this.events.request("contracts:list", (_err, contractsList) => {
if(_err) {
this.logger.error(__("no contracts found"));
return;
}
contractsList.forEach(contract => {
if(!contract.deployedAddress) return;
let address = contract.deployedAddress.toLowerCase();
if(!this.addressToContract[address]){
let funcSignatures = {};
contract.abiDefinition
.filter(func => func.type == "function")
.map(func => {
const name = func.name +
'(' +
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
')';
funcSignatures[utils.sha3(name).substring(0, 10)] = {
name,
abi: func,
functionName: func.name
};
});
this.addressToContract[address] = {
name: contract.className,
functions: funcSignatures
};
}
});
});
}
_listenForLogRequests(){
if(this.ipc.ipcRole !== 'server') return;
this.ipc.on('log', (request) => {
if(request.type == 'contract-log'){
if(!this.contractsDeployed) return;
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
if(!this.addressToContract[address]){
this._updateContractList();
}
if(!this.addressToContract[address]) return;
const name = this.addressToContract[address].name;
const func = this.addressToContract[address].functions[data.substring(0, 10)];
const functionName = func.functionName;
const decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10));
let paramString = "";
if(func.abi.inputs){
func.abi.inputs.forEach((input) => {
let quote = input.type.indexOf("int") == -1 ? '"' : '';
paramString += quote + decodedParameters[input.name] + quote + ", ";
});
paramString = paramString.substring(0, paramString.length - 2);
}
gasUsed = utils.hexToNumber(gasUsed);
blockNumber = utils.hexToNumber(blockNumber);
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
} else {
this.logger.info(JSON.stringify(request));
}
});
}
}
module.exports = ConsoleListener;

View File

@ -47,7 +47,6 @@ class SolcW {
});
if (this.ipc.isServer()) {
this.ipc.serve();
this.ipc.on('compile', self.compile.bind(this));
}

View File

@ -107,7 +107,7 @@ class Pipeline {
webpackProcess.send({action: constants.pipeline.build, file, importsList});
webpackProcess.once('result', constants.pipeline.built, (msg) => {
webpackProcess.disconnect();
webpackProcess.kill();
return next(msg.error);
});
},

View File

@ -8,6 +8,8 @@ const cloneDeep = require('clone-deep');
const AccountParser = require('../contracts/accountParser');
const Provider = require('../contracts/provider');
const EmbarkJS = require('../../js/embark_node');
function getSimulator() {
try {
return require('ganache-cli');
@ -241,12 +243,13 @@ class Test {
} else {
data = self.contracts[contractName].options.data;
}
Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.deployedAddress,
{from: self.web3.eth.defaultAccount, gas: 6000000}));
Object.assign(self.contracts[contractName], new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.deployedAddress, from: self.web3.eth.defaultAccount, gas: 6000000, web3: self.web3}));
self.contracts[contractName].address = contract.deployedAddress;
if (self.contracts[contractName].options) {
self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount;
self.contracts[contractName].options.data = data;
self.contracts[contractName].options.gas = 6000000;
}
eachCb();
}, (err) => {
@ -288,10 +291,10 @@ class Test {
contract = this.engine.contractsManager.contracts[contractNames[0]];
}
}
this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address,
{from: this.web3.eth.defaultAccount, gas: 6000000});
this.contracts[contractName] = new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.address, from: this.web3.eth.defaultAccount, gas: 6000000, web3: this.web3});
this.contracts[contractName].address = contract.address;
this.contracts[contractName].options.data = contract.code;
this.contracts[contractName].options.gas = 6000000;
this.web3.eth.getAccounts().then((accounts) => {
this.contracts[contractName].options.from = contract.from || accounts[0];
});

View File

@ -186,6 +186,16 @@ function getExternalContractUrl(file) {
};
}
function hexToNumber(hex){
const Web3 = require('web3');
return Web3.utils.hexToNumber(hex);
}
function decodeParams(typesArray, hexString){
var Web3EthAbi = require('web3-eth-abi');
return Web3EthAbi.decodeParameters(typesArray, hexString);
}
function toChecksumAddress(address) {
const Web3 = require('web3');
return Web3.utils.toChecksumAddress(address);
@ -256,6 +266,8 @@ module.exports = {
httpsGet: httpsGet,
httpGetJson: httpGetJson,
httpsGetJson: httpsGetJson,
hexToNumber: hexToNumber,
decodeParams: decodeParams,
runCmd: runCmd,
cd: cd,
sed: sed,

262
package-lock.json generated
View File

@ -50,7 +50,7 @@
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.2.tgz",
"integrity": "sha512-Q3FWsbdmkQd1ib11A4XNWQvRD//5KpPoGawA8aB2DR7pWKoW9XQv3+dGxD/Z1eVFze23Okdo27ZQytVFlweKvQ==",
"requires": {
"@types/node": "10.1.4"
"@types/node": "10.3.1"
}
},
"@types/lockfile": {
@ -59,16 +59,16 @@
"integrity": "sha512-pD6JuijPmrfi84qF3/TzGQ7zi0QIX+d7ZdetD6jUA6cp+IsCzAquXZfi5viesew+pfpOTIdAVKuh1SHA7KeKzg=="
},
"@types/node": {
"version": "10.1.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.1.4.tgz",
"integrity": "sha512-GpQxofkdlHYxjHad98UUdNoMO7JrmzQZoAaghtNg14Gwg7YkohcrCoJEcEMSgllx4VIZ+mYw7ZHjfaeIagP/rg=="
"version": "10.3.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.1.tgz",
"integrity": "sha512-IsX9aDHDzJohkm3VCDB8tkzl5RQ34E/PFA29TQk6uDGb7Oc869ZBtmdKVDBzY3+h9GnXB8ssrRXEPVZrlIOPOw=="
},
"@types/node-fetch": {
"version": "1.6.9",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-1.6.9.tgz",
"integrity": "sha512-n2r6WLoY7+uuPT7pnEtKJCmPUGyJ+cbyBR8Avnu4+m1nzz7DwBVuyIvvlBzCZ/nrpC7rIgb3D6pNavL7rFEa9g==",
"requires": {
"@types/node": "10.1.4"
"@types/node": "10.3.1"
}
},
"@types/semver": {
@ -81,7 +81,7 @@
"resolved": "https://registry.npmjs.org/@types/tar/-/tar-4.0.0.tgz",
"integrity": "sha512-YybbEHNngcHlIWVCYsoj7Oo1JU9JqONuAlt1LlTH/lmL8BMhbzdFUgReY87a05rY1j8mfK47Del+TCkaLAXwLw==",
"requires": {
"@types/node": "10.1.4"
"@types/node": "10.3.1"
}
},
"@types/url-join": {
@ -1913,6 +1913,11 @@
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
"integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk="
},
"bufferhelper": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/bufferhelper/-/bufferhelper-0.2.0.tgz",
"integrity": "sha1-7C842SU4dpzqKQFIeTXp4h2Bc7M="
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
@ -2842,6 +2847,11 @@
"source-map": "0.5.7"
}
},
"ctype": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz",
"integrity": "sha1-gsGMJGH3QRTvFsE1IkrQuRRMoS8="
},
"currently-unhandled": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz",
@ -5745,6 +5755,23 @@
"resolved": "https://registry.npmjs.org/http-https/-/http-https-1.0.0.tgz",
"integrity": "sha1-L5CN1fHbQGjAWM1ubUzjkskTOJs="
},
"http-proxy": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.17.0.tgz",
"integrity": "sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==",
"requires": {
"eventemitter3": "3.1.0",
"follow-redirects": "1.4.1",
"requires-port": "1.0.0"
},
"dependencies": {
"eventemitter3": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.0.tgz",
"integrity": "sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA=="
}
}
},
"http-shutdown": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-shutdown/-/http-shutdown-1.2.0.tgz",
@ -8355,6 +8382,214 @@
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.4.tgz",
"integrity": "sha512-8Df0906+tq/omxuCZD6PqhPaQDYuyJ1d+VITgxoIA8zvQd1ru+nMJcDChHH324MWitIgbVkAkQoGEEVJNpn/PA=="
},
"node-http-proxy": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/node-http-proxy/-/node-http-proxy-0.2.3.tgz",
"integrity": "sha1-ZFv8yESYGkEnBz//Php2ff50NLc=",
"requires": {
"bufferhelper": "0.2.0",
"commander": "2.6.0",
"pm": "2.2.5",
"request": "2.51.0"
},
"dependencies": {
"asn1": {
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz",
"integrity": "sha1-VZvhg3bQik7E2+gId9J4GGObLfc="
},
"assert-plus": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz",
"integrity": "sha1-7nQAlBMALYTOxyGcasgRgS5yMWA="
},
"async": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
"integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
},
"aws-sign2": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz",
"integrity": "sha1-xXED96F/wDfwLXwuZLYC6iI/fWM="
},
"bl": {
"version": "0.9.5",
"resolved": "https://registry.npmjs.org/bl/-/bl-0.9.5.tgz",
"integrity": "sha1-wGt5evCF6gC8Unr8jvzxHeIjIFQ=",
"requires": {
"readable-stream": "1.0.34"
}
},
"boom": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/boom/-/boom-0.4.2.tgz",
"integrity": "sha1-emNune1O/O+xnO9JR6PGffrukRs=",
"requires": {
"hoek": "0.9.1"
}
},
"caseless": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.8.0.tgz",
"integrity": "sha1-W8oogdQUN/VLJAfr40iIx7mtT30="
},
"combined-stream": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz",
"integrity": "sha1-ATfmV7qlp1QcV6w3rF/AfXO03B8=",
"requires": {
"delayed-stream": "0.0.5"
}
},
"commander": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.6.0.tgz",
"integrity": "sha1-nfflL7Kgyw+4kFjugMMQQiXzfh0="
},
"cryptiles": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz",
"integrity": "sha1-7ZH/HxetE9N0gohZT4pIoNJvMlw=",
"requires": {
"boom": "0.4.2"
}
},
"delayed-stream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz",
"integrity": "sha1-1LH0OpPoKW3+AmlPRoC8N6MTxz8="
},
"forever-agent": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz",
"integrity": "sha1-bQ4JxJIflKJ/Y9O0nF/v8epMUTA="
},
"form-data": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-0.2.0.tgz",
"integrity": "sha1-Jvi8JtpkQOKZy9z7aQNcT3em5GY=",
"requires": {
"async": "0.9.2",
"combined-stream": "0.0.7",
"mime-types": "2.0.14"
},
"dependencies": {
"mime-types": {
"version": "2.0.14",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.14.tgz",
"integrity": "sha1-MQ4VnbI+B3+Lsit0jav6SVcUCqY=",
"requires": {
"mime-db": "1.12.0"
}
}
}
},
"hawk": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/hawk/-/hawk-1.1.1.tgz",
"integrity": "sha1-h81JH5tG5OKurKM1QWdmiF0tHtk=",
"requires": {
"boom": "0.4.2",
"cryptiles": "0.2.2",
"hoek": "0.9.1",
"sntp": "0.2.4"
}
},
"hoek": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz",
"integrity": "sha1-PTIkYrrfB3Fup+uFuviAec3c5QU="
},
"http-signature": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz",
"integrity": "sha1-T72sEyVZqoMjEh5UB3nAoBKyfmY=",
"requires": {
"asn1": "0.1.11",
"assert-plus": "0.1.5",
"ctype": "0.5.3"
}
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"mime-db": {
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.12.0.tgz",
"integrity": "sha1-PQxjGA9FjrENMlqqN9fFiuMS6dc="
},
"mime-types": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-1.0.2.tgz",
"integrity": "sha1-mVrhOSq4r/y/yyZB3QVOlDwNXc4="
},
"oauth-sign": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.5.0.tgz",
"integrity": "sha1-12f1FpMlYg6rLgh+8MRy53PbZGE="
},
"qs": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz",
"integrity": "sha1-6eha2+ddoLvkyOBHaghikPhjtAQ="
},
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "0.0.1",
"string_decoder": "0.10.31"
}
},
"request": {
"version": "2.51.0",
"resolved": "https://registry.npmjs.org/request/-/request-2.51.0.tgz",
"integrity": "sha1-NdALvswBLlX5B7G9ng29V3v+8m4=",
"requires": {
"aws-sign2": "0.5.0",
"bl": "0.9.5",
"caseless": "0.8.0",
"combined-stream": "0.0.7",
"forever-agent": "0.5.2",
"form-data": "0.2.0",
"hawk": "1.1.1",
"http-signature": "0.10.1",
"json-stringify-safe": "5.0.1",
"mime-types": "1.0.2",
"node-uuid": "1.4.8",
"oauth-sign": "0.5.0",
"qs": "2.3.3",
"stringstream": "0.0.5",
"tough-cookie": "2.3.4",
"tunnel-agent": "0.4.3"
}
},
"sntp": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz",
"integrity": "sha1-+4hfGLDzqtGJ+CSGJTa87ux1CQA=",
"requires": {
"hoek": "0.9.1"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"tunnel-agent": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz",
"integrity": "sha1-Y3PbdpCf5XDgjXNYM2Xtgop07us="
}
}
},
"node-ipc": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz",
@ -8465,6 +8700,11 @@
}
}
},
"node-uuid": {
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz",
"integrity": "sha1-sEDrCSOWivq/jTL7HxfxFn/auQc="
},
"nodeify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/nodeify/-/nodeify-1.0.1.tgz",
@ -9144,6 +9384,11 @@
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==",
"dev": true
},
"pm": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/pm/-/pm-2.2.5.tgz",
"integrity": "sha1-IgJZn1m/trOID6naI0rdL0NLYK8="
},
"posix-character-classes": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz",
@ -10231,6 +10476,11 @@
"resolve-from": "1.0.1"
}
},
"requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
},
"resolve": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz",

View File

@ -49,11 +49,13 @@
"ganache-cli": "^6.1.0",
"globule": "^1.1.0",
"hard-source-webpack-plugin": "^0.6.6",
"http-proxy": "^1.17.0",
"http-shutdown": "^1.2.0",
"i18n": "^0.8.3",
"ipfs-api": "17.2.4",
"live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git",
"merge": "^1.2.0",
"node-http-proxy": "^0.2.3",
"node-ipc": "^9.1.1",
"os-locale": "^2.1.0",
"p-iteration": "^1.1.7",
@ -63,6 +65,7 @@
"request": "^2.85.0",
"serve-static": "^1.11.1",
"shelljs": "^0.5.0",
"simples": "^0.8.8",
"solc": "0.4.24",
"string-replace-async": "^1.2.1",
"style-loader": "^0.19.0",

View File

@ -12,6 +12,7 @@
"rpcHost": "localhost",
"rpcPort": 8545,
"rpcCorsDomain": "auto",
"proxy": true,
"account": {
"password": "config/development/password"
},

View File

@ -12,6 +12,7 @@
"rpcHost": "localhost",
"rpcPort": 8545,
"rpcCorsDomain": "auto",
"proxy": true,
"account": {
"password": "config/development/password"
},

View File

@ -1,5 +1,6 @@
/*globals describe, it*/
const Blockchain = require('../lib/cmds/blockchain/blockchain');
const constants = require('../lib/constants.json');
const assert = require('assert');
@ -39,10 +40,15 @@ describe('embark.Blockchain', function () {
targetGasLimit: false,
fast: false,
light: false,
verbosity: undefined
verbosity: undefined,
proxy: true
};
let blockchain = new Blockchain(config, 'geth');
if(config.proxy){
config.wsPort += constants.blockchain.servicePortOnProxy;
config.rpcPort += constants.blockchain.servicePortOnProxy;
}
assert.deepEqual(blockchain.config, config);
done();
});
@ -77,10 +83,16 @@ describe('embark.Blockchain', function () {
targetGasLimit: false,
fast: false,
light: false,
verbosity: undefined
verbosity: undefined,
proxy: true
};
let blockchain = new Blockchain(config, 'geth');
if(config.proxy){
config.wsPort += constants.blockchain.servicePortOnProxy;
config.rpcPort += constants.blockchain.servicePortOnProxy;
}
assert.deepEqual(blockchain.config, config);
done();
});

View File

@ -19,8 +19,8 @@
"wsOrigins": "auto",
"wsRPC": true,
"wsHost": "localhost",
"wsPort": 8546
"wsPort": 8546,
"proxy": true
},
"testnet": {
"networkType": "testnet",

View File

@ -40,6 +40,11 @@ contract("AnotherStorage", function() {
assert.equal(result.toString(), SimpleStorage.options.address);
});
it("set SimpleStorage address with alternative syntax", async function() {
let result = await AnotherStorage.simpleStorageAddress();
assert.equal(result.toString(), SimpleStorage.options.address);
});
it('should set the balance correctly', async function () {
const balance = await web3.eth.getBalance(accounts[0]);
assert.ok(balance < 5000000000000000000);