From 9ece2f78edd921a9d3761095e4503c32cff30261 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Tue, 24 Mar 2015 16:28:13 -0400 Subject: [PATCH 1/3] Fix bug if no value is supplied. --- lib/networks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/networks.js b/lib/networks.js index 51062f060..5e47b6c6a 100644 --- a/lib/networks.js +++ b/lib/networks.js @@ -75,7 +75,7 @@ function addNetwork(data) { }); _.each(_.values(network), function(value) { - if (!_.isObject(value)) { + if (value && !_.isObject(value)) { networkMaps[value] = network; } }); From a7d75cb25bf7993aaf298713edc57972ecd650b3 Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Tue, 24 Mar 2015 16:38:02 -0400 Subject: [PATCH 2/3] Add test for patch. --- test/networks.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/networks.js b/test/networks.js index ddcd07a59..21c05c5c8 100644 --- a/test/networks.js +++ b/test/networks.js @@ -40,6 +40,25 @@ describe('Networks', function() { } } }); + + it('should not set a network map for an undefined value', function() { + var custom = { + name: 'somenet', + pubkeyhash: 0x13, + privatekey: 0x93, + scripthash: 0x11, + xpubkey: 0x0278b20f, + xprivkey: 0x0278ade5, + networkMagic: 0xe7beb4d5, + port: 20008, + dnsSeeds: [ + 'somenet.localhost' + ] + }; + networks.add(custom); + var network = networks.get(undefined); + should.not.exist( network ); + }); var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey']; From c7594013735a0ee8ef312b8bc6d5ca1df35e17af Mon Sep 17 00:00:00 2001 From: Eric Martindale Date: Tue, 24 Mar 2015 17:57:39 -0400 Subject: [PATCH 3/3] Fix tests, address commentary from @braydonf. --- lib/networks.js | 2 +- test/networks.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/networks.js b/lib/networks.js index 5e47b6c6a..96e6176f2 100644 --- a/lib/networks.js +++ b/lib/networks.js @@ -75,7 +75,7 @@ function addNetwork(data) { }); _.each(_.values(network), function(value) { - if (value && !_.isObject(value)) { + if (!_.isUndefined(value) && !_.isObject(value)) { networkMaps[value] = network; } }); diff --git a/test/networks.js b/test/networks.js index 21c05c5c8..d019479ba 100644 --- a/test/networks.js +++ b/test/networks.js @@ -20,7 +20,7 @@ describe('Networks', function() { pubkeyhash: 0x10, privatekey: 0x90, scripthash: 0x08, - xpubkey: 0x0278b20e, + xpubkey: 0x0278b20e, xprivkey: 0x0278ade4, networkMagic: 0xe7beb4d4, port: 20001, @@ -47,7 +47,7 @@ describe('Networks', function() { pubkeyhash: 0x13, privatekey: 0x93, scripthash: 0x11, - xpubkey: 0x0278b20f, + xpubkey: 0x0278b20f, xprivkey: 0x0278ade5, networkMagic: 0xe7beb4d5, port: 20008, @@ -57,7 +57,7 @@ describe('Networks', function() { }; networks.add(custom); var network = networks.get(undefined); - should.not.exist( network ); + should.not.exist(network); }); var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey'];