Browse Source

Merge pull request #1185 from fanatid/feature/immutable-network

Immutable network Object
patch-2
Braydon Fuller 10 years ago
parent
commit
fb591b39c1
  1. 5
      lib/networks.js
  2. 6
      test/networks.js

5
lib/networks.js

@ -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;
}

6
test/networks.js

@ -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)
});
});

Loading…
Cancel
Save