feat: apply contract change to test

Give the same ability to config function on test
than when running with embark run
This commit is contained in:
Anthony Laibe 2018-12-19 10:14:32 +00:00 committed by Iuri Matias
parent 3a8808e2f5
commit e3a7b74284
4 changed files with 52 additions and 37 deletions

View File

@ -8,10 +8,11 @@ const web3 = require('web3');
const constants = require('../constants');
const {canonicalHost, defaultHost} = require('../utils/host');
const cloneDeep = require('lodash.clonedeep');
import { extendZeroAddressShorthand, replaceZeroAddressShorthand } from '../utils/addressUtils';
import { replaceZeroAddressShorthand } from '../utils/addressUtils';
import { unitRegex } from "../utils/regexConstants";
import * as utilsContractsConfig from "../utils/contractsConfig";
const DEFAULT_CONFIG_PATH = 'config/';
const unitRegex = /([0-9]+) ([a-zA-Z]+)/;
var Config = function(options) {
const self = this;
@ -329,39 +330,7 @@ Config.prototype.loadContractsConfigFile = function() {
});
}
Object.keys(newContractsConfig.contracts).forEach(contractName => {
const gas = newContractsConfig.contracts[contractName].gas;
const gasPrice = newContractsConfig.contracts[contractName].gasPrice;
const address = newContractsConfig.contracts[contractName].address;
const args = newContractsConfig.contracts[contractName].args;
const onDeploy = newContractsConfig.contracts[contractName].onDeploy;
if (gas && gas.match(unitRegex)) {
newContractsConfig.contracts[contractName].gas = utils.getWeiBalanceFromString(gas, web3);
}
if (gasPrice && gasPrice.match(unitRegex)) {
newContractsConfig.contracts[contractName].gasPrice = utils.getWeiBalanceFromString(gasPrice, web3);
}
if (address) {
newContractsConfig.contracts[contractName].address = extendZeroAddressShorthand(address);
}
if (args && args.length) {
newContractsConfig.contracts[contractName].args = args.map(val => {
if (typeof val === 'string') {
return extendZeroAddressShorthand(val);
}
return val;
});
}
if (Array.isArray(onDeploy)) {
newContractsConfig.contracts[contractName].onDeploy = onDeploy.map(replaceZeroAddressShorthand);
}
});
newContractsConfig = utilsContractsConfig.prepare(newContractsConfig);
const afterDeploy = newContractsConfig.afterDeploy;

View File

@ -1,3 +1,5 @@
import * as utilsContractsConfig from "../../utils/contractsConfig";
const async = require('async');
const AccountParser = require('../../utils/accountParser');
const EmbarkJS = require('embarkjs');
@ -236,7 +238,8 @@ class Test {
async _deploy(config, callback) {
const self = this;
async.waterfall([
function getConfig(next) {
function setConfig(next) {
utilsContractsConfig.prepare(config);
self.events.request('config:contractsConfig:set',
{contracts: config.contracts, versions: self.versions_default}, next);
},

View File

@ -0,0 +1,42 @@
import { extendZeroAddressShorthand, replaceZeroAddressShorthand } from "./addressUtils";
import { unitRegex } from "./regexConstants";
const web3 = require("web3");
const utils = require("./utils.js");
export function prepare(config: any) {
Object.keys(config.contracts).forEach((contractName) => {
const gas = config.contracts[contractName].gas;
const gasPrice = config.contracts[contractName].gasPrice;
const address = config.contracts[contractName].address;
const args = config.contracts[contractName].args;
const onDeploy = config.contracts[contractName].onDeploy;
if (gas && gas.match(unitRegex)) {
config.contracts[contractName].gas = utils.getWeiBalanceFromString(gas, web3);
}
if (gasPrice && gasPrice.match(unitRegex)) {
config.contracts[contractName].gasPrice = utils.getWeiBalanceFromString(gasPrice, web3);
}
if (address) {
config.contracts[contractName].address = extendZeroAddressShorthand(address);
}
if (args && args.length) {
config.contracts[contractName].args = args.map((val: any) => {
if (typeof val === "string") {
return extendZeroAddressShorthand(val);
}
return val;
});
}
if (Array.isArray(onDeploy)) {
config.contracts[contractName].onDeploy = onDeploy.map(replaceZeroAddressShorthand);
}
});
return config;
}

View File

@ -0,0 +1 @@
export const unitRegex = /([0-9]+) ([a-zA-Z]+)/;