add contract to chain
This commit is contained in:
parent
ea54f7524d
commit
fab0df5c8b
|
@ -1,7 +1,10 @@
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var web3 = require('web3');
|
var web3 = require('web3');
|
||||||
|
var sha3_256 = require('js-sha3').sha3_256;
|
||||||
|
|
||||||
ChainManager = function() { }
|
ChainManager = function() {
|
||||||
|
this.currentChain = {};
|
||||||
|
}
|
||||||
|
|
||||||
ChainManager.prototype.loadConfigFile = function(filename) {
|
ChainManager.prototype.loadConfigFile = function(filename) {
|
||||||
try {
|
try {
|
||||||
|
@ -26,7 +29,16 @@ ChainManager.prototype.init = function(env, blockchainConfig) {
|
||||||
var chainId = web3.eth.getBlock(0).hash;
|
var chainId = web3.eth.getBlock(0).hash;
|
||||||
|
|
||||||
if (this.chainManagerConfig[chainId] === undefined) {
|
if (this.chainManagerConfig[chainId] === undefined) {
|
||||||
this.chainManagerConfig[chainId] = {contracts: []};
|
this.chainManagerConfig[chainId] = {contracts: {}};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentChain = this.chainManagerConfig[chainId];
|
||||||
|
}
|
||||||
|
|
||||||
|
ChainManager.prototype.addContract = function(contractName, code, address) {
|
||||||
|
this.currentChain.contracts[sha3_256(code)] = {
|
||||||
|
name: contractName,
|
||||||
|
address: address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"hashmerge": "^1.0.2",
|
"hashmerge": "^1.0.2",
|
||||||
"jasmine": "^2.3.1",
|
"jasmine": "^2.3.1",
|
||||||
|
"js-sha3": "^0.3.1",
|
||||||
"meteor-build-client": "^0.1.6",
|
"meteor-build-client": "^0.1.6",
|
||||||
"methodmissing": "^0.0.3",
|
"methodmissing": "^0.0.3",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
|
|
|
@ -11,9 +11,23 @@ describe('embark.chain_manager', function() {
|
||||||
chainManager.init('development', blockchainConfig);
|
chainManager.init('development', blockchainConfig);
|
||||||
|
|
||||||
it('should initialize chain', function() {
|
it('should initialize chain', function() {
|
||||||
assert.equal(chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f'] != undefined, true);
|
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
|
||||||
assert.equal(chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f'].contracts.length, 0);
|
assert.equal(chain != undefined, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addContract', function() {
|
||||||
|
|
||||||
|
it('should register a contract in the chain', function() {
|
||||||
|
chainManager.addContract("Foo", "123456", "0x123");
|
||||||
|
|
||||||
|
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
|
||||||
|
var contract = chain.contracts["d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e"]
|
||||||
|
|
||||||
|
assert.equal(contract.name, "Foo");
|
||||||
|
assert.equal(contract.address, "0x123");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue