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

View File

@ -36,6 +36,9 @@ describe('embark.Config', function() {
it('should load contract config correctly', function() {
config.loadContractsConfigFile();
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",
"contracts": {
"SimpleStorage": {