mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-28 07:01:33 +00:00
conflict in specialconfigs
This commit is contained in:
parent
f4d7636b7a
commit
ac155ddb86
@ -44,10 +44,11 @@ var Config = function(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: refactor this so reading the file can be done with a normal resolver or something that takes advantage of the plugin api
|
// TODO: refactor this so reading the file can be done with a normal resolver or something that takes advantage of the plugin api
|
||||||
self.events.setCommandHandler("config:contractsFiles:add", (filename) => {
|
self.events.setCommandHandler("config:contractsFiles:add", (filename, resolver) => {
|
||||||
self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) {
|
resolver = resolver || function(callback) {
|
||||||
callback(fs.readFileSync(filename).toString());
|
callback(fs.readFileSync(filename).toString());
|
||||||
}}));
|
};
|
||||||
|
self.contractsFiles.push(new File({filename, type: File.types.custom, path: filename, resolver}));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,6 +85,10 @@ class ContractSources {
|
|||||||
|
|
||||||
// Branch counts are tracked in a different manner so we'll do these now
|
// Branch counts are tracked in a different manner so we'll do these now
|
||||||
Object.keys(coverageReport[file].b).forEach((id) => {
|
Object.keys(coverageReport[file].b).forEach((id) => {
|
||||||
|
// FIXME in solc-tests, this is sometimes empty
|
||||||
|
if (!this.coverageReport[file].b[id] || !this.coverageReport[file].b[id].length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.coverageReport[file].b[id][0] += coverageReport[file].b[id][0];
|
this.coverageReport[file].b[id][0] += coverageReport[file].b[id][0];
|
||||||
this.coverageReport[file].b[id][1] += coverageReport[file].b[id][1];
|
this.coverageReport[file].b[id][1] += coverageReport[file].b[id][1];
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@ class SpecialConfigs {
|
|||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.contractsConfig = embark.config.contractsConfig;
|
this.config = embark.config;
|
||||||
|
|
||||||
this.registerAfterDeployAction();
|
this.registerAfterDeployAction();
|
||||||
this.registerOnDeployAction();
|
this.registerOnDeployAction();
|
||||||
@ -69,7 +69,7 @@ class SpecialConfigs {
|
|||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
||||||
let afterDeployCmds = self.contractsConfig.afterDeploy || [];
|
let afterDeployCmds = self.config.contractsConfig.afterDeploy || [];
|
||||||
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function replaceWithAddresses(next) {
|
function replaceWithAddresses(next) {
|
||||||
|
@ -199,9 +199,10 @@ class TestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runSolidityTests(files, options, cb) {
|
runSolidityTests(files, options, cb) {
|
||||||
self.logger.info('Running solc tests');
|
this.logger.info('Running solc tests');
|
||||||
const loglevel = options.loglevel || 'warn';
|
const loglevel = options.loglevel || 'warn';
|
||||||
let solcTest = new SolcTest({loglevel, node: options.node});
|
|
||||||
|
let solcTest = new SolcTest({loglevel, node: options.node, events: this.events, logger: this.logger, config: this.embark.config});
|
||||||
global.embark = solcTest;
|
global.embark = solcTest;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function initEngine(next) {
|
function initEngine(next) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const Test = require('./test');
|
const Test = require('./test');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const File = require('./../../core/file');
|
|
||||||
const remixTests = require('remix-tests');
|
const remixTests = require('remix-tests');
|
||||||
const Base = require('mocha/lib/reporters/base');
|
const Base = require('mocha/lib/reporters/base');
|
||||||
const color = Base.color;
|
const color = Base.color;
|
||||||
@ -11,43 +10,45 @@ class SolcTest extends Test {
|
|||||||
super(options);
|
super(options);
|
||||||
this.assertLibCode = remixTests.assertLibCode;
|
this.assertLibCode = remixTests.assertLibCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(cb) {
|
init(cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
super.init(() => {
|
super.init(() => {
|
||||||
let assertFile = new File({
|
self.events.request('config:contractsFiles:add', 'remix_tests.sol', (callback) => {
|
||||||
filename: 'remix_tests.sol',
|
callback(self.assertLibCode);
|
||||||
type: File.types.custom,
|
});
|
||||||
path: 'remix_tests.sol',
|
|
||||||
resolver: (callback) => {
|
|
||||||
callback(self.assertLibCode);
|
|
||||||
}});
|
|
||||||
self.engine.config.contractsFiles.push(assertFile);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTests(files, cb) {
|
setupTests(files, cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
files.forEach((file) => {
|
|
||||||
let testFile = self._prepareContractForTest(file);
|
|
||||||
self.engine.config.contractsFiles.push(new File({filename: file, type: File.types.custom, path: file, resolver: function (callback) {
|
|
||||||
callback(testFile);
|
|
||||||
}}));
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function addContracts(next) {
|
||||||
|
files.forEach((file) => {
|
||||||
|
let testFile = self._prepareContractForTest(file);
|
||||||
|
self.events.request('config:contractsFiles:add', file, (callback) => {
|
||||||
|
callback(testFile);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
},
|
||||||
function initWeb3Provider(next) {
|
function initWeb3Provider(next) {
|
||||||
self.initWeb3Provider(next);
|
self.initWeb3Provider(next);
|
||||||
},
|
},
|
||||||
function resetContracts(next) {
|
function resetContracts(next) {
|
||||||
self.engine.events.request("contracts:reset:dependencies", next);
|
self.events.request("contracts:reset:dependencies", next);
|
||||||
},
|
},
|
||||||
function compile(next) {
|
function compile(next) {
|
||||||
console.info('Compiling contracts'.cyan);
|
console.info('Compiling contracts'.cyan);
|
||||||
self.engine.events.request("contracts:build", false, next);
|
self.events.request("contracts:build", false, next);
|
||||||
},
|
},
|
||||||
function determineContractsToDeploy(next) {
|
function determineContractsToDeploy(next) {
|
||||||
self.engine.events.request("contracts:list", (err, contracts) => {
|
self.events.request("contracts:list", (err, contracts) => {
|
||||||
let contractsToDeploy = contracts.filter((contract) => contract.filename.indexOf('_test.sol') >=0);
|
let contractsToDeploy = contracts.filter((contract) => {
|
||||||
|
return contract.filename && contract.filename.indexOf('_test.sol') >= 0;
|
||||||
|
});
|
||||||
let assertLib = contracts.filter((contract) => contract.filename === 'remix_tests.sol')[0];
|
let assertLib = contracts.filter((contract) => contract.filename === 'remix_tests.sol')[0];
|
||||||
next(null, [assertLib].concat(contractsToDeploy));
|
next(null, [assertLib].concat(contractsToDeploy));
|
||||||
});
|
});
|
||||||
@ -58,45 +59,58 @@ class SolcTest extends Test {
|
|||||||
contracts.forEach((contract) => {
|
contracts.forEach((contract) => {
|
||||||
contract._gasLimit = self.gasLimit;
|
contract._gasLimit = self.gasLimit;
|
||||||
let fn = (cb) => {
|
let fn = (cb) => {
|
||||||
self.engine.events.request('deploy:contract', contract, cb);
|
self.events.request('deploy:contract', contract, cb);
|
||||||
};
|
};
|
||||||
fns.push(fn);
|
fns.push(fn);
|
||||||
});
|
});
|
||||||
async.series(fns, next);
|
async.series(fns, next);
|
||||||
}
|
}
|
||||||
],cb);
|
], cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
runTests(file, cb) {
|
runTests(file, cb) {
|
||||||
console.info('Running tests'.cyan);
|
|
||||||
const self = this;
|
const self = this;
|
||||||
self.engine.events.request('contracts:all', (err, contracts) => {
|
self.logger.info('Running tests'.cyan);
|
||||||
let contractsToTest = [];
|
const forwardSlashFile = file.replace(/\\/g, '/');
|
||||||
Object.keys(contracts).forEach((contract) => {
|
|
||||||
if(contracts[contract].filename === file) {
|
async.waterfall([
|
||||||
contractsToTest.push(contracts[contract]);
|
function getContracts(next) {
|
||||||
}
|
self.events.request('contracts:all', (err, contracts) => {
|
||||||
});
|
if (err) {
|
||||||
let fns = [];
|
return next(err);
|
||||||
contractsToTest.forEach((contract) => {
|
}
|
||||||
let contractObject = self._convertToWeb3(contract);
|
const contractsToTest = [];
|
||||||
let fn = (_callback) => {
|
|
||||||
// TODO: web3 is not injected into the function. Issue has been raised on remixTests.
|
Object.keys(contracts).forEach((contract) => {
|
||||||
// To fix once web3 has been made injectable.
|
if (contracts[contract].filename &&
|
||||||
remixTests.runTest(contract.className, contractObject, self._prettyPrint.bind(self), _callback);
|
contracts[contract].filename.replace(/\\/g, '/') === forwardSlashFile) {
|
||||||
};
|
contractsToTest.push(contracts[contract]);
|
||||||
fns.push(fn);
|
}
|
||||||
});
|
});
|
||||||
async.series(fns, cb);
|
next(null, contractsToTest);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
_convertToWeb3(contract) {
|
function getWeb3Object(contracts, next) {
|
||||||
let contractObject = new this.web3.eth.Contract(contract.abiDefinition);
|
self.events.request('blockchain:get', (web3) => {
|
||||||
contractObject.options.address = contract.deployedAddress;
|
next(null, contracts, web3);
|
||||||
contractObject.options.from = contract.deploymentAccount;
|
});
|
||||||
contractObject.options.gas = contract.gas;
|
},
|
||||||
contractObject.filename = contract.filename;
|
function run(contracts, web3, next) {
|
||||||
return contractObject;
|
let fns = [];
|
||||||
|
contracts.forEach((contract) => {
|
||||||
|
let fn = (_callback) => {
|
||||||
|
// TODO: web3 is not injected into the function. Issue has been raised on remixTests.
|
||||||
|
// To fix once web3 has been made injectable.
|
||||||
|
remixTests.runTest(contract.className, Test.getWeb3Contract(contract, web3),
|
||||||
|
self._prettyPrint.bind(self), _callback);
|
||||||
|
};
|
||||||
|
fns.push(fn);
|
||||||
|
});
|
||||||
|
async.series(fns, next);
|
||||||
|
}
|
||||||
|
], cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dynamically insert Assert library as an import
|
// dynamically insert Assert library as an import
|
||||||
// regexIndexOf has been added to String's prototype in remix-tests module
|
// regexIndexOf has been added to String's prototype in remix-tests module
|
||||||
_prepareContractForTest(file) {
|
_prepareContractForTest(file) {
|
||||||
@ -110,13 +124,13 @@ class SolcTest extends Test {
|
|||||||
|
|
||||||
_prettyPrint(obj) {
|
_prettyPrint(obj) {
|
||||||
if (obj.type === 'contract') {
|
if (obj.type === 'contract') {
|
||||||
console.log(color('suite', '%s'), obj.value);
|
this.logger.info(color('suite', '%s'), obj.value);
|
||||||
} else if(obj.type === 'testPass') {
|
} else if(obj.type === 'testPass') {
|
||||||
let fmt = color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s');
|
let fmt = color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s');
|
||||||
console.log(fmt, obj.value);
|
this.logger.info(fmt, obj.value);
|
||||||
} else if(obj.type === 'testFailure') {
|
} else if(obj.type === 'testFailure') {
|
||||||
let fmt = color('fail', ' %s %s');
|
let fmt = color('fail', ' %s %s');
|
||||||
console.log(fmt, Base.symbols.err, obj.value);
|
this.logger.info(fmt, Base.symbols.err, obj.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,6 @@ class Test {
|
|||||||
this.blockchainConnector.wait = false;
|
this.blockchainConnector.wait = false;
|
||||||
this.blockchainConnector.coverage = this.options.coverage;
|
this.blockchainConnector.coverage = this.options.coverage;
|
||||||
|
|
||||||
// TODO change this
|
|
||||||
|
|
||||||
|
|
||||||
this.blockchainConnector.initWeb3(callback);
|
this.blockchainConnector.initWeb3(callback);
|
||||||
}
|
}
|
||||||
@ -247,7 +245,12 @@ class Test {
|
|||||||
next(null, accounts);
|
next(null, accounts);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function createContractObject(accounts, next) {
|
function getWeb3Object(accounts, next) {
|
||||||
|
self.events.request('blockchain:get', (web3) => {
|
||||||
|
next(null, accounts, web3);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function createContractObject(accounts, web3, next) {
|
||||||
self.events.request('contracts:all', (err, contracts) => {
|
self.events.request('contracts:all', (err, contracts) => {
|
||||||
|
|
||||||
async.each(contracts, (contract, eachCb) => {
|
async.each(contracts, (contract, eachCb) => {
|
||||||
@ -255,28 +258,10 @@ class Test {
|
|||||||
self.contracts[contract.className] = {};
|
self.contracts[contract.className] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newContract = Test.getWeb3Contract(contract, web3);
|
||||||
|
Object.setPrototypeOf(self.contracts[contract.className], newContract);
|
||||||
|
|
||||||
self.events.request('blockchain:get', (web3) => {
|
eachCb();
|
||||||
let newContract = new EmbarkJS.Blockchain.Contract({
|
|
||||||
abi: contract.abiDefinition,
|
|
||||||
address: contract.deployedAddress,
|
|
||||||
from: web3.eth.defaultAccount,
|
|
||||||
gas: 6000000,
|
|
||||||
web3: web3
|
|
||||||
});
|
|
||||||
|
|
||||||
if (newContract.options) {
|
|
||||||
newContract.options.from = web3.eth.defaultAccount;
|
|
||||||
newContract.options.data = contract.code;
|
|
||||||
if (!newContract.options.data.startsWith('0x')) {
|
|
||||||
newContract.options.data = '0x' + newContract.options.data;
|
|
||||||
}
|
|
||||||
newContract.options.gas = 6000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.setPrototypeOf(self.contracts[contract.className], newContract);
|
|
||||||
eachCb();
|
|
||||||
});
|
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
next(err, accounts);
|
next(err, accounts);
|
||||||
});
|
});
|
||||||
@ -293,6 +278,28 @@ class Test {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getWeb3Contract(contract, web3) {
|
||||||
|
const newContract = new EmbarkJS.Blockchain.Contract({
|
||||||
|
abi: contract.abiDefinition,
|
||||||
|
address: contract.deployedAddress,
|
||||||
|
from: contract.deploymentAccount || web3.eth.defaultAccount,
|
||||||
|
gas: 6000000,
|
||||||
|
web3: web3
|
||||||
|
});
|
||||||
|
|
||||||
|
newContract.filename = contract.filename;
|
||||||
|
if (newContract.options) {
|
||||||
|
newContract.options.from = contract.deploymentAccount || web3.eth.defaultAccount;
|
||||||
|
newContract.options.data = contract.code;
|
||||||
|
if (!newContract.options.data.startsWith('0x')) {
|
||||||
|
newContract.options.data = '0x' + newContract.options.data;
|
||||||
|
}
|
||||||
|
newContract.options.gas = 6000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newContract;
|
||||||
|
}
|
||||||
|
|
||||||
require(path) {
|
require(path) {
|
||||||
const prefix = 'Embark/contracts/';
|
const prefix = 'Embark/contracts/';
|
||||||
if (!path.startsWith(prefix)) {
|
if (!path.startsWith(prefix)) {
|
||||||
|
@ -3,7 +3,7 @@ const assert = require('assert');
|
|||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const utils = require('../lib/utils/utils');
|
const utils = require('../lib/utils/utils');
|
||||||
const AccountParser = require('../lib/utils/accountParser');
|
const AccountParser = require('../lib/utils/accountParser');
|
||||||
let TestLogger = require('../lib/tests/test_logger.js');
|
let TestLogger = require('../lib/utils/test_logger');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const i18n = require('../lib/core/i18n/i18n.js');
|
const i18n = require('../lib/core/i18n/i18n.js');
|
||||||
i18n.setOrDetectLocale('en');
|
i18n.setOrDetectLocale('en');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
let SolidityCompiler = require('../lib/modules/solidity');
|
let SolidityCompiler = require('../lib/modules/solidity');
|
||||||
let TestLogger = require('../lib/tests/test_logger.js');
|
let TestLogger = require('../lib/utils/test_logger');
|
||||||
let File = require('../lib/core/file.js');
|
let File = require('../lib/core/file.js');
|
||||||
let Ipc = require('../lib/core/ipc.js');
|
let Ipc = require('../lib/core/ipc.js');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
const Config = require('../lib/core/config.js');
|
const Config = require('../lib/core/config.js');
|
||||||
const Plugins = require('../lib/core/plugins.js');
|
const Plugins = require('../lib/core/plugins.js');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const TestLogger = require('../lib/tests/test_logger.js');
|
const TestLogger = require('../lib/utils/test_logger');
|
||||||
const Events = require('../lib/core/events');
|
const Events = require('../lib/core/events');
|
||||||
|
|
||||||
describe('embark.Config', function () {
|
describe('embark.Config', function () {
|
||||||
|
@ -3,7 +3,7 @@ let ContractsManager = require('../lib/modules/contracts_manager/index.js');
|
|||||||
let Compiler = require('../lib/modules/compiler/');
|
let Compiler = require('../lib/modules/compiler/');
|
||||||
let Logger = require('../lib/core/logger.js');
|
let Logger = require('../lib/core/logger.js');
|
||||||
let File = require('../lib/core/file.js');
|
let File = require('../lib/core/file.js');
|
||||||
let TestLogger = require('../lib/tests/test_logger.js');
|
let TestLogger = require('../lib/utils/test_logger');
|
||||||
let Events = require('../lib/core/events');
|
let Events = require('../lib/core/events');
|
||||||
let Ipc = require('../lib/core/ipc.js');
|
let Ipc = require('../lib/core/ipc.js');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
@ -58,7 +58,7 @@ describe('embark.Contracts', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let compiler = new Compiler(embarkObject, {plugins: plugins});
|
let compiler = new Compiler(embarkObject, {plugins: plugins});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*global describe, it, before*/
|
/*global describe, it, before*/
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
let TestLogger = require('../lib/tests/test_logger.js');
|
let TestLogger = require('../lib/utils/test_logger');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const i18n = require('../lib/core/i18n/i18n.js');
|
const i18n = require('../lib/core/i18n/i18n.js');
|
||||||
const constants = require('../lib/constants.json');
|
const constants = require('../lib/constants.json');
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*global describe, it, before, beforeEach*/
|
/*global describe, it, before, beforeEach*/
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const TestLogger = require('../lib/tests/test_logger');
|
const TestLogger = require('../lib/utils/test_logger');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const ProcessLauncher = require('../lib/core/processes/processLauncher');
|
const ProcessLauncher = require('../lib/core/processes/processLauncher');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user