fix defaults when contracts config file is not present

This commit is contained in:
Iuri Matias 2017-12-16 08:12:38 -05:00
parent e093ff5b30
commit 747237de76
2 changed files with 26 additions and 15 deletions

View File

@ -75,19 +75,24 @@ Config.prototype.loadBlockchainConfigFile = function() {
Config.prototype.loadContractsConfigFile = function() { Config.prototype.loadContractsConfigFile = function() {
var configObject = { var configObject = {
"versions": { "default": {
"web3.js": "0.19.1", "versions": {
"solc": "0.4.17" "web3.js": "1.0.0-beta",
}, "solc": "0.4.17"
"deployment": { },
"host": "localhost", "deployment": {
"port": 8545, "host": "localhost",
"type": "rpc" "port": 8545,
}, "type": "rpc"
"dappConnection": [ },
"$WEB3", "dappConnection": [
"localhost:8545" "$WEB3",
] "localhost:8545"
],
"gas": "auto",
"contracts": {
}
}
}; };
var configPlugins = this.plugins.getPluginsFor('contractsConfig'); var configPlugins = this.plugins.getPluginsFor('contractsConfig');
@ -99,8 +104,11 @@ Config.prototype.loadContractsConfigFile = function() {
}); });
} }
var contractsConfig = fs.readJSONSync(this.configDir + "contracts.json"); var contractsConfig;
configObject = utils.recursiveMerge(configObject, contractsConfig); if (fs.existsSync(this.configDir + "contracts.json")) {
contractsConfig = fs.readJSONSync(this.configDir + "contracts.json");
configObject = utils.recursiveMerge(configObject, contractsConfig);
}
var defaultContractsConfig = configObject['default']; var defaultContractsConfig = configObject['default'];
var envContractsConfig = configObject[this.env]; var envContractsConfig = configObject[this.env];

View File

@ -36,6 +36,9 @@ describe('embark.Config', function() {
it('should load contract config correctly', function() { it('should load contract config correctly', function() {
config.loadContractsConfigFile(); config.loadContractsConfigFile();
let expectedConfig = { let expectedConfig = {
versions: { 'web3.js': '1.0.0-beta', solc: '0.4.17' },
deployment: { host: 'localhost', port: 8545, type: 'rpc' },
dappConnection: [ '$WEB3', 'localhost:8545' ],
"gas": "auto", "gas": "auto",
"contracts": { "contracts": {
"SimpleStorage": { "SimpleStorage": {