You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('should return the appropriate Network when calling static fromPublic58() ', () => {
// get a random type from network.types
const networksjs = require('../lib/protocol/networks');
const type = networksjs.types[Math.floor(Math.random() * networksjs.types.length)];
// Point A
const network = Network.get(type);
const result = Network.fromPublic58(network.keyPrefix.xpubkey58);
assert.strictEqual(result, network);
});
then calls
* Get a network by its xpubkey base58 prefix.
* @param {String} prefix
* @param {Network?} network
* @returns {Network}
*/
static fromPublic58(prefix, network) {
return Network.by(prefix, cmpPub58, network, 'xpubkey');
}
which in turn calls,
/**
* Get a network by an associated comparator.
* @private
* @param {Object} value
* @param {Function} compare
* @param {Network|null} network
* @param {String} name
* @returns {Network}
*/
static by(value, compare, network, name) {
if (network) {
network = Network.get(network);
if (compare(network, value))
return network;
throw new Error(`Network mismatch for ${name}.`);
}
for (const type of networks.types) {
network = networks[type];
if (compare(network, value))
return Network.get(type);
}
throw new Error(`Network not found for ${name}.`);
}
Assuming at Point A in the unit test, the type equals regtest and so the Network object which is the expected return value is a proper Regtest Network object.
The second file, network.js :: fromPublic58(), calls Network.by() with the 'tpub' prefix defined in Regtest, and the cmpPub58 comparator.
Network.by, the third code block above, when it is called, does not have a network object, so it skips the first section. It then iterates through the networks.types, comparing first for main, and then testnet. Since the prefix for testnet and regtest match, it returns the testnet Network object.
The expected behavior is that it returns a regtest Network object. I think.
The text was updated successfully, but these errors were encountered:
The test...
then calls
which in turn calls,
Assuming at Point A in the unit test, the type equals regtest and so the Network object which is the expected return value is a proper Regtest Network object.
The second file, network.js :: fromPublic58(), calls Network.by() with the 'tpub' prefix defined in Regtest, and the cmpPub58 comparator.
Network.by, the third code block above, when it is called, does not have a network object, so it skips the first section. It then iterates through the networks.types, comparing first for main, and then testnet. Since the prefix for testnet and regtest match, it returns the testnet Network object.
The expected behavior is that it returns a regtest Network object. I think.
The text was updated successfully, but these errors were encountered: