Merge pull request #1185 from fanatid/feature/immutable-network
Immutable network Object
This commit is contained in:
commit
fb591b39c1
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue