Browse Source

Immutable network Object

patch-2
Kirill Fomichev 10 years ago
parent
commit
ca96359f40
  1. 5
      lib/networks.js
  2. 6
      test/networks.js

5
lib/networks.js

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

6
test/networks.js

@ -93,4 +93,10 @@ describe('Networks', function() {
networks.livenet.toString().should.equal('livenet'); 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)
});
}); });

Loading…
Cancel
Save