Immutable network Object

This commit is contained in:
Kirill Fomichev 2015-04-11 11:19:50 +03:00
parent f268298f25
commit ca96359f40
2 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@
var _ = require('lodash');
var BufferUtil = require('./util/buffer');
var JSUtil = require('./util/js');
var networks = [];
var networkMaps = {};
@ -64,7 +65,7 @@ function addNetwork(data) {
var network = new Network();
_.extend(network, {
JSUtil.defineImmutable(network, {
name: data.name,
alias: data.alias,
pubkeyhash: data.pubkeyhash,
@ -77,7 +78,7 @@ function addNetwork(data) {
dnsSeeds: data.dnsSeeds
});
_.each(_.values(network), function(value) {
_.each(network, function(value) {
if (!_.isUndefined(value) && !_.isObject(value)) {
networkMaps[value] = network;
}

View File

@ -93,4 +93,10 @@ describe('Networks', function() {
networks.livenet.toString().should.equal('livenet');
});
it('network object should be immutable', function() {
expect(networks.testnet.name).to.equal('testnet')
var fn = function() { networks.testnet.name = 'livenet' }
expect(fn).to.throw(TypeError)
});
});