conflict in specialconfigs

This commit is contained in:
Jonathan Rainville 2018-10-18 08:37:28 -04:00 committed by Pascal Precht
parent f4d7636b7a
commit ac155ddb86
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
13 changed files with 117 additions and 90 deletions

View File

@ -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
self.events.setCommandHandler("config:contractsFiles:add", (filename) => {
self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) {
self.events.setCommandHandler("config:contractsFiles:add", (filename, resolver) => {
resolver = resolver || function(callback) {
callback(fs.readFileSync(filename).toString());
}}));
};
self.contractsFiles.push(new File({filename, type: File.types.custom, path: filename, resolver}));
});
};

View File

@ -85,6 +85,10 @@ class ContractSources {
// Branch counts are tracked in a different manner so we'll do these now
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][1] += coverageReport[file].b[id][1];
});

View File

@ -8,7 +8,7 @@ class SpecialConfigs {
this.events = embark.events;
this.buildDir = options.buildDir;
this.embark = embark;
this.contractsConfig = embark.config.contractsConfig;
this.config = embark.config;
this.registerAfterDeployAction();
this.registerOnDeployAction();
@ -69,7 +69,7 @@ class SpecialConfigs {
const self = this;
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.waterfall([
function replaceWithAddresses(next) {

View File

@ -199,9 +199,10 @@ class TestRunner {
}
runSolidityTests(files, options, cb) {
self.logger.info('Running solc tests');
this.logger.info('Running solc tests');
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;
async.waterfall([
function initEngine(next) {

View File

@ -1,7 +1,6 @@
const Test = require('./test');
const async = require('async');
const fs = require('fs-extra');
const File = require('./../../core/file');
const remixTests = require('remix-tests');
const Base = require('mocha/lib/reporters/base');
const color = Base.color;
@ -11,43 +10,45 @@ class SolcTest extends Test {
super(options);
this.assertLibCode = remixTests.assertLibCode;
}
init(cb) {
const self = this;
super.init(() => {
let assertFile = new File({
filename: 'remix_tests.sol',
type: File.types.custom,
path: 'remix_tests.sol',
resolver: (callback) => {
callback(self.assertLibCode);
}});
self.engine.config.contractsFiles.push(assertFile);
self.events.request('config:contractsFiles:add', 'remix_tests.sol', (callback) => {
callback(self.assertLibCode);
});
cb();
});
}
setupTests(files, cb) {
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([
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) {
self.initWeb3Provider(next);
},
function resetContracts(next) {
self.engine.events.request("contracts:reset:dependencies", next);
self.events.request("contracts:reset:dependencies", next);
},
function compile(next) {
console.info('Compiling contracts'.cyan);
self.engine.events.request("contracts:build", false, next);
self.events.request("contracts:build", false, next);
},
function determineContractsToDeploy(next) {
self.engine.events.request("contracts:list", (err, contracts) => {
let contractsToDeploy = contracts.filter((contract) => contract.filename.indexOf('_test.sol') >=0);
self.events.request("contracts:list", (err, contracts) => {
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];
next(null, [assertLib].concat(contractsToDeploy));
});
@ -58,45 +59,58 @@ class SolcTest extends Test {
contracts.forEach((contract) => {
contract._gasLimit = self.gasLimit;
let fn = (cb) => {
self.engine.events.request('deploy:contract', contract, cb);
self.events.request('deploy:contract', contract, cb);
};
fns.push(fn);
});
async.series(fns, next);
}
],cb);
], cb);
}
runTests(file, cb) {
console.info('Running tests'.cyan);
const self = this;
self.engine.events.request('contracts:all', (err, contracts) => {
let contractsToTest = [];
Object.keys(contracts).forEach((contract) => {
if(contracts[contract].filename === file) {
contractsToTest.push(contracts[contract]);
}
});
let fns = [];
contractsToTest.forEach((contract) => {
let contractObject = self._convertToWeb3(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, contractObject, self._prettyPrint.bind(self), _callback);
};
fns.push(fn);
});
async.series(fns, cb);
});
}
_convertToWeb3(contract) {
let contractObject = new this.web3.eth.Contract(contract.abiDefinition);
contractObject.options.address = contract.deployedAddress;
contractObject.options.from = contract.deploymentAccount;
contractObject.options.gas = contract.gas;
contractObject.filename = contract.filename;
return contractObject;
self.logger.info('Running tests'.cyan);
const forwardSlashFile = file.replace(/\\/g, '/');
async.waterfall([
function getContracts(next) {
self.events.request('contracts:all', (err, contracts) => {
if (err) {
return next(err);
}
const contractsToTest = [];
Object.keys(contracts).forEach((contract) => {
if (contracts[contract].filename &&
contracts[contract].filename.replace(/\\/g, '/') === forwardSlashFile) {
contractsToTest.push(contracts[contract]);
}
});
next(null, contractsToTest);
});
},
function getWeb3Object(contracts, next) {
self.events.request('blockchain:get', (web3) => {
next(null, contracts, web3);
});
},
function run(contracts, web3, next) {
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
// regexIndexOf has been added to String's prototype in remix-tests module
_prepareContractForTest(file) {
@ -110,13 +124,13 @@ class SolcTest extends Test {
_prettyPrint(obj) {
if (obj.type === 'contract') {
console.log(color('suite', '%s'), obj.value);
this.logger.info(color('suite', '%s'), obj.value);
} else if(obj.type === 'testPass') {
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') {
let fmt = color('fail', ' %s %s');
console.log(fmt, Base.symbols.err, obj.value);
this.logger.info(fmt, Base.symbols.err, obj.value);
}
}
}

View File

@ -49,8 +49,6 @@ class Test {
this.blockchainConnector.wait = false;
this.blockchainConnector.coverage = this.options.coverage;
// TODO change this
this.blockchainConnector.initWeb3(callback);
}
@ -247,7 +245,12 @@ class Test {
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) => {
async.each(contracts, (contract, eachCb) => {
@ -255,28 +258,10 @@ class Test {
self.contracts[contract.className] = {};
}
const newContract = Test.getWeb3Contract(contract, web3);
Object.setPrototypeOf(self.contracts[contract.className], newContract);
self.events.request('blockchain:get', (web3) => {
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();
});
eachCb();
}, (err) => {
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) {
const prefix = 'Embark/contracts/';
if (!path.startsWith(prefix)) {

View File

@ -3,7 +3,7 @@ const assert = require('assert');
const sinon = require('sinon');
const utils = require('../lib/utils/utils');
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 i18n = require('../lib/core/i18n/i18n.js');
i18n.setOrDetectLocale('en');

View File

@ -1,6 +1,6 @@
/*globals describe, it*/
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 Ipc = require('../lib/core/ipc.js');
let assert = require('assert');

View File

@ -2,7 +2,7 @@
const Config = require('../lib/core/config.js');
const Plugins = require('../lib/core/plugins.js');
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');
describe('embark.Config', function () {

View File

@ -3,7 +3,7 @@ let ContractsManager = require('../lib/modules/contracts_manager/index.js');
let Compiler = require('../lib/modules/compiler/');
let Logger = require('../lib/core/logger.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 Ipc = require('../lib/core/ipc.js');
let assert = require('assert');
@ -58,7 +58,7 @@ describe('embark.Contracts', function() {
}
}
}
}
};
let compiler = new Compiler(embarkObject, {plugins: plugins});

View File

@ -1,6 +1,6 @@
/*global describe, it, before*/
const assert = require('assert');
let TestLogger = require('../lib/tests/test_logger.js');
let TestLogger = require('../lib/utils/test_logger');
const Web3 = require('web3');
const i18n = require('../lib/core/i18n/i18n.js');
const constants = require('../lib/constants.json');

View File

@ -1,7 +1,7 @@
/*global describe, it, before, beforeEach*/
const assert = require('assert');
const sinon = require('sinon');
const TestLogger = require('../lib/tests/test_logger');
const TestLogger = require('../lib/utils/test_logger');
const path = require('path');
const ProcessLauncher = require('../lib/core/processes/processLauncher');