use constants instead of magic numbers

This commit is contained in:
Jonathan Rainville 2018-10-16 11:16:47 -04:00 committed by Pascal Precht
parent df218397cd
commit 7a70f5df26
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
7 changed files with 33 additions and 15 deletions

View File

@ -1,5 +1,6 @@
let async = require('async');
const constants = require('../lib/constants');
const Logger = require('../lib/core/logger');
require('colors');
@ -18,7 +19,7 @@ class EmbarkController {
let Config = require('../lib/core/config.js');
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.loadConfigFiles(options);
@ -539,7 +540,7 @@ class EmbarkController {
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logFile: options.logFile,
logLevel: options.logLevel,
logLevel: options.logLevel || Logger.logLevels.warn,
context: this.context,
useDashboard: options.useDashboard,
webpackConfigName: options.webpackConfigName,

View File

@ -45,5 +45,11 @@
"storage": {
"init": "init",
"initiated": "initiated"
},
"tests": {
"gasLimit": 6000000
},
"codeGenerator": {
"gasLimit": 6000000
}
}

View File

@ -4,13 +4,21 @@ let fs = require('./fs.js');
class Logger {
constructor(options) {
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.logFunction = options.logFunction || console.log;
this.logFile = options.logFile;
}
}
Logger.logLevels = {
error: 'error',
warn: 'warn',
info: 'info',
debug: 'debug',
trace: 'trace'
};
Logger.prototype.writeToFile = function () {
if (!this.logFile) {
return;

View File

@ -1,6 +1,7 @@
let async = require('async');
let fs = require('../../core/fs.js');
const utils = require('../../utils/utils.js');
const constants = require('../../constants');
require('ejs');
const Templates = {
@ -149,7 +150,7 @@ class CodeGenerator {
if (useLoader === false) {
for (let contract of contractsList) {
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;
}
@ -177,7 +178,7 @@ class CodeGenerator {
let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined";
block += Templates.embarkjs_contract({className: contract.className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates});
} 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});

View File

@ -65,7 +65,7 @@ class SolcW {
self.compilerLoaded = true;
done();
});
// FIXME
this.solcProcess.send({action: "init", options: {logger: self.logger, showSpinner: !self.useDashboard}});
if (this.ipc.isServer()) {

View File

@ -7,6 +7,7 @@ const assert = require('assert');
const Test = require('./test');
const EmbarkSpec = require('./reporter');
const SolcTest = require('./solc_test');
const constants = require('../../constants');
class TestRunner {
constructor(embark, options) {
@ -122,10 +123,9 @@ class TestRunner {
runJSTests(files, options, cb) {
const self = this;
const loglevel = options.loglevel || 'warn';
async.waterfall([
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});
global.embark = test;
global.assert = assert;
@ -166,7 +166,7 @@ class TestRunner {
mocha.reporter(EmbarkSpec, {
events: self.events,
gasDetails: options.gasDetails,
gasLimit: 6000000
gasLimit: constants.tests.gasLimit
});
mocha.addFile(file);
@ -201,9 +201,8 @@ class TestRunner {
runSolidityTests(files, options, cb) {
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});
global.embark = solcTest;
async.waterfall([

View File

@ -2,6 +2,9 @@ const async = require('async');
const AccountParser = require('../../utils/accountParser');
const EmbarkJS = require('embarkjs');
const utils = require('../../utils/utils');
const constants = require('../../constants');
const BALANCE_10_ETHER_IN_HEX = '0x8AC7230489E80000';
class Test {
constructor(options) {
@ -22,7 +25,7 @@ class Test {
}
init(callback) {
this.gasLimit = 6000000;
this.gasLimit = constants.tests.gasLimit;
this.events.request('deploy:setGasLimit', this.gasLimit);
if (this.options.node !== 'embark') {
this.showNodeHttpWarning();
@ -51,7 +54,7 @@ class Test {
if (this.simOptions.accounts) {
this.simOptions.accounts = this.simOptions.accounts.map((account) => {
if (!account.hexBalance) {
account.hexBalance = '0x8AC7230489E80000'; // 10 ether
account.hexBalance = BALANCE_10_ETHER_IN_HEX;
}
return {balance: account.hexBalance, secretKey: account.privateKey};
});
@ -289,7 +292,7 @@ class Test {
abi: contract.abiDefinition,
address: contract.deployedAddress,
from: contract.deploymentAccount || web3.eth.defaultAccount,
gas: 6000000,
gas: constants.tests.gasLimit,
web3: web3
});
@ -300,7 +303,7 @@ class Test {
if (!newContract.options.data.startsWith('0x')) {
newContract.options.data = '0x' + newContract.options.data;
}
newContract.options.gas = 6000000;
newContract.options.gas = constants.tests.gasLimit;
}
return newContract;