restructure lib initialization
This commit is contained in:
parent
ad071bc1b2
commit
1a5ddea9a8
|
@ -3,10 +3,10 @@ var readYaml = require('read-yaml');
|
|||
BlockchainConfig = require('./blockchain.js');
|
||||
ContractsConfig = require('./contracts.js');
|
||||
|
||||
Config = {
|
||||
config = {
|
||||
Blockchain: BlockchainConfig,
|
||||
Contracts: ContractsConfig
|
||||
}
|
||||
|
||||
module.exports = Config
|
||||
module.exports = config
|
||||
|
||||
|
|
|
@ -4,21 +4,25 @@ var fs = require('fs');
|
|||
var Blockchain = require('./blockchain.js');
|
||||
var toposort = require('toposort');
|
||||
|
||||
ContractsConfig = function(files, blockchainConfig, web3) {
|
||||
ContractsConfig = function(blockchainConfig, web3) {
|
||||
this.blockchainConfig = blockchainConfig;
|
||||
this.web3 = web3;
|
||||
this.contractFiles = [];
|
||||
}
|
||||
|
||||
ContractsConfig.prototype.init = function(files) {
|
||||
this.all_contracts = [];
|
||||
this.contractDB = {};
|
||||
this.contractFiles = files;
|
||||
this.web3 = web3;
|
||||
this.contractDependencies = {};
|
||||
this.blockchainConfig = blockchainConfig;
|
||||
|
||||
try {
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + blockchainConfig.rpcHost + ":" + blockchainConfig.rpcPort));
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
|
||||
primaryAddress = this.web3.eth.coinbase;
|
||||
this.web3.eth.defaultAccount = primaryAddress;
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
throw new Error("can't connect to " + blockchainConfig.rpcHost + ":" + blockchainConfig.rpcPort + " check if an ethereum node is running");
|
||||
throw new Error("can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
|
||||
}
|
||||
|
||||
console.log("address is : " + primaryAddress);
|
||||
|
|
20
lib/index.js
20
lib/index.js
|
@ -12,12 +12,18 @@ var syncMe = require('sync-me');
|
|||
var methodmissing = require('methodmissing');
|
||||
var jasmine = require('jasmine');
|
||||
|
||||
embark = {}
|
||||
embark.Tests = require('./test.js');
|
||||
embark.Blockchain = require('./blockchain.js');
|
||||
embark.Deploy = require('./deploy.js');
|
||||
embark.Release = require('./ipfs.js');
|
||||
embark.Config = require('./config/config.js');
|
||||
var Tests = require('./test.js');
|
||||
var Blockchain = require('./blockchain.js');
|
||||
var Deploy = require('./deploy.js');
|
||||
var Release = require('./ipfs.js');
|
||||
var Config = require('./config/config.js');
|
||||
|
||||
module.exports = embark;
|
||||
Embark = {
|
||||
init: function() {
|
||||
this.blockchainConfig = (new Config.BlockchainConfig());
|
||||
this.contractsConfig = (new Config.ContractsConfig(this.blockchainConfig, web3));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Embark;
|
||||
|
||||
|
|
|
@ -6,14 +6,10 @@ require('mocha-sinon');
|
|||
|
||||
describe('embark.config.contracts', function() {
|
||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
||||
//sinon.stub(web3, "setProvider");
|
||||
//sinon.stub(web3.eth.compile, "solidity", function() {
|
||||
// return "compiled_code";
|
||||
//});
|
||||
|
||||
describe('#loadConfigFile', function() {
|
||||
it('should read and load yml file', function() {
|
||||
var contractsConfig = new Config.Contracts([], blockchainConfig, web3);
|
||||
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
||||
|
||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
||||
|
@ -47,8 +43,9 @@ describe('embark.config.contracts', function() {
|
|||
'test/support/contracts/simple_storage.sol',
|
||||
'test/support/contracts/another_storage.sol'
|
||||
]
|
||||
contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
||||
contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
||||
contractsConfig.init(files);
|
||||
contractsConfig.compileContracts();
|
||||
});
|
||||
|
||||
|
@ -65,8 +62,9 @@ describe('embark.config.contracts', function() {
|
|||
'test/support/contracts/another_storage.sol',
|
||||
'test/support/contracts/wallets.sol'
|
||||
]
|
||||
contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
||||
contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
||||
contractsConfig.init(files);
|
||||
contractsConfig.compileContracts('development');
|
||||
});
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@ describe('embark.deploy', function() {
|
|||
'test/support/contracts/wallets.sol'
|
||||
];
|
||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
||||
var contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
||||
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
||||
contractsConfig.init(files);
|
||||
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
||||
|
||||
describe('#deploy_contracts', function() {
|
||||
|
|
Loading…
Reference in New Issue