use constants instead of magic numbers
This commit is contained in:
parent
df218397cd
commit
7a70f5df26
|
@ -1,5 +1,6 @@
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
const constants = require('../lib/constants');
|
const constants = require('../lib/constants');
|
||||||
|
const Logger = require('../lib/core/logger');
|
||||||
|
|
||||||
require('colors');
|
require('colors');
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class EmbarkController {
|
||||||
let Config = require('../lib/core/config.js');
|
let Config = require('../lib/core/config.js');
|
||||||
|
|
||||||
this.events = new Events();
|
this.events = new Events();
|
||||||
this.logger = new Logger({logLevel: 'debug', events: this.events});
|
this.logger = new Logger({logLevel: Logger.logLevels.debug, events: this.events});
|
||||||
|
|
||||||
this.config = new Config({env: env, logger: this.logger, events: this.events, context: this.context});
|
this.config = new Config({env: env, logger: this.logger, events: this.events, context: this.context});
|
||||||
this.config.loadConfigFiles(options);
|
this.config.loadConfigFiles(options);
|
||||||
|
@ -539,7 +540,7 @@ class EmbarkController {
|
||||||
version: this.version,
|
version: this.version,
|
||||||
embarkConfig: options.embarkConfig || 'embark.json',
|
embarkConfig: options.embarkConfig || 'embark.json',
|
||||||
logFile: options.logFile,
|
logFile: options.logFile,
|
||||||
logLevel: options.logLevel,
|
logLevel: options.logLevel || Logger.logLevels.warn,
|
||||||
context: this.context,
|
context: this.context,
|
||||||
useDashboard: options.useDashboard,
|
useDashboard: options.useDashboard,
|
||||||
webpackConfigName: options.webpackConfigName,
|
webpackConfigName: options.webpackConfigName,
|
||||||
|
|
|
@ -45,5 +45,11 @@
|
||||||
"storage": {
|
"storage": {
|
||||||
"init": "init",
|
"init": "init",
|
||||||
"initiated": "initiated"
|
"initiated": "initiated"
|
||||||
|
},
|
||||||
|
"tests": {
|
||||||
|
"gasLimit": 6000000
|
||||||
|
},
|
||||||
|
"codeGenerator": {
|
||||||
|
"gasLimit": 6000000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,21 @@ let fs = require('./fs.js');
|
||||||
class Logger {
|
class Logger {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.events = options.events || {emit: function(){}};
|
this.events = options.events || {emit: function(){}};
|
||||||
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
this.logLevels = Object.keys(Logger.logLevels);
|
||||||
this.logLevel = options.logLevel || 'info';
|
this.logLevel = options.logLevel || 'info';
|
||||||
this.logFunction = options.logFunction || console.log;
|
this.logFunction = options.logFunction || console.log;
|
||||||
this.logFile = options.logFile;
|
this.logFile = options.logFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.logLevels = {
|
||||||
|
error: 'error',
|
||||||
|
warn: 'warn',
|
||||||
|
info: 'info',
|
||||||
|
debug: 'debug',
|
||||||
|
trace: 'trace'
|
||||||
|
};
|
||||||
|
|
||||||
Logger.prototype.writeToFile = function () {
|
Logger.prototype.writeToFile = function () {
|
||||||
if (!this.logFile) {
|
if (!this.logFile) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
let fs = require('../../core/fs.js');
|
let fs = require('../../core/fs.js');
|
||||||
const utils = require('../../utils/utils.js');
|
const utils = require('../../utils/utils.js');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
|
||||||
require('ejs');
|
require('ejs');
|
||||||
const Templates = {
|
const Templates = {
|
||||||
|
@ -149,7 +150,7 @@ class CodeGenerator {
|
||||||
if (useLoader === false) {
|
if (useLoader === false) {
|
||||||
for (let contract of contractsList) {
|
for (let contract of contractsList) {
|
||||||
let abi = JSON.stringify(contract.abiDefinition);
|
let abi = JSON.stringify(contract.abiDefinition);
|
||||||
result += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: 6000000});
|
result += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: constants.codeGenerator.gasLimit});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +178,7 @@ class CodeGenerator {
|
||||||
let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined";
|
let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined";
|
||||||
block += Templates.embarkjs_contract({className: contract.className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates});
|
block += Templates.embarkjs_contract({className: contract.className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates});
|
||||||
} else {
|
} else {
|
||||||
block += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: (isDeployment ? 6000000 : false)});
|
block += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: (isDeployment ? constants.codeGenerator.gasLimit : false)});
|
||||||
}
|
}
|
||||||
result += Templates.exec_when_ready({block: block});
|
result += Templates.exec_when_ready({block: block});
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class SolcW {
|
||||||
self.compilerLoaded = true;
|
self.compilerLoaded = true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
// FIXME
|
|
||||||
this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}});
|
this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}});
|
||||||
|
|
||||||
if (this.ipc.isServer()) {
|
if (this.ipc.isServer()) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ const assert = require('assert');
|
||||||
const Test = require('./test');
|
const Test = require('./test');
|
||||||
const EmbarkSpec = require('./reporter');
|
const EmbarkSpec = require('./reporter');
|
||||||
const SolcTest = require('./solc_test');
|
const SolcTest = require('./solc_test');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
|
||||||
class TestRunner {
|
class TestRunner {
|
||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
|
@ -122,10 +123,9 @@ class TestRunner {
|
||||||
|
|
||||||
runJSTests(files, options, cb) {
|
runJSTests(files, options, cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const loglevel = options.loglevel || 'warn';
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function setupGlobalNamespace(next) {
|
function setupGlobalNamespace(next) {
|
||||||
const test = new Test({loglevel, node: options.node, events: self.events, logger: self.logger,
|
const test = new Test({loglevel: options.loglevel, node: options.node, events: self.events, logger: self.logger,
|
||||||
config: self.embark.config, ipc: self.ipc});
|
config: self.embark.config, ipc: self.ipc});
|
||||||
global.embark = test;
|
global.embark = test;
|
||||||
global.assert = assert;
|
global.assert = assert;
|
||||||
|
@ -166,7 +166,7 @@ class TestRunner {
|
||||||
mocha.reporter(EmbarkSpec, {
|
mocha.reporter(EmbarkSpec, {
|
||||||
events: self.events,
|
events: self.events,
|
||||||
gasDetails: options.gasDetails,
|
gasDetails: options.gasDetails,
|
||||||
gasLimit: 6000000
|
gasLimit: constants.tests.gasLimit
|
||||||
});
|
});
|
||||||
|
|
||||||
mocha.addFile(file);
|
mocha.addFile(file);
|
||||||
|
@ -201,9 +201,8 @@ class TestRunner {
|
||||||
|
|
||||||
runSolidityTests(files, options, cb) {
|
runSolidityTests(files, options, cb) {
|
||||||
console.info('Running solc tests');
|
console.info('Running solc tests');
|
||||||
const loglevel = options.loglevel || 'warn';
|
|
||||||
|
|
||||||
let solcTest = new SolcTest({loglevel, node: options.node, events: this.events, logger: this.logger,
|
let solcTest = new SolcTest({loglevel: options.loglevel, node: options.node, events: this.events, logger: this.logger,
|
||||||
config: this.embark.config, ipc: this.ipc});
|
config: this.embark.config, ipc: this.ipc});
|
||||||
global.embark = solcTest;
|
global.embark = solcTest;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|
|
@ -2,6 +2,9 @@ const async = require('async');
|
||||||
const AccountParser = require('../../utils/accountParser');
|
const AccountParser = require('../../utils/accountParser');
|
||||||
const EmbarkJS = require('embarkjs');
|
const EmbarkJS = require('embarkjs');
|
||||||
const utils = require('../../utils/utils');
|
const utils = require('../../utils/utils');
|
||||||
|
const constants = require('../../constants');
|
||||||
|
|
||||||
|
const BALANCE_10_ETHER_IN_HEX = '0x8AC7230489E80000';
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -22,7 +25,7 @@ class Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
init(callback) {
|
init(callback) {
|
||||||
this.gasLimit = 6000000;
|
this.gasLimit = constants.tests.gasLimit;
|
||||||
this.events.request('deploy:setGasLimit', this.gasLimit);
|
this.events.request('deploy:setGasLimit', this.gasLimit);
|
||||||
if (this.options.node !== 'embark') {
|
if (this.options.node !== 'embark') {
|
||||||
this.showNodeHttpWarning();
|
this.showNodeHttpWarning();
|
||||||
|
@ -51,7 +54,7 @@ class Test {
|
||||||
if (this.simOptions.accounts) {
|
if (this.simOptions.accounts) {
|
||||||
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
|
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
|
||||||
if (!account.hexBalance) {
|
if (!account.hexBalance) {
|
||||||
account.hexBalance = '0x8AC7230489E80000'; // 10 ether
|
account.hexBalance = BALANCE_10_ETHER_IN_HEX;
|
||||||
}
|
}
|
||||||
return {balance: account.hexBalance, secretKey: account.privateKey};
|
return {balance: account.hexBalance, secretKey: account.privateKey};
|
||||||
});
|
});
|
||||||
|
@ -289,7 +292,7 @@ class Test {
|
||||||
abi: contract.abiDefinition,
|
abi: contract.abiDefinition,
|
||||||
address: contract.deployedAddress,
|
address: contract.deployedAddress,
|
||||||
from: contract.deploymentAccount || web3.eth.defaultAccount,
|
from: contract.deploymentAccount || web3.eth.defaultAccount,
|
||||||
gas: 6000000,
|
gas: constants.tests.gasLimit,
|
||||||
web3: web3
|
web3: web3
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -300,7 +303,7 @@ class Test {
|
||||||
if (!newContract.options.data.startsWith('0x')) {
|
if (!newContract.options.data.startsWith('0x')) {
|
||||||
newContract.options.data = '0x' + newContract.options.data;
|
newContract.options.data = '0x' + newContract.options.data;
|
||||||
}
|
}
|
||||||
newContract.options.gas = 6000000;
|
newContract.options.gas = constants.tests.gasLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newContract;
|
return newContract;
|
||||||
|
|
Loading…
Reference in New Issue