This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure values are distinct unless explicitly grouped. This method uncovered bug BG-16466. Issue: BG-16465
- Loading branch information
1 parent
06f0b92
commit c9f367a
Showing
2 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* global describe, it */ | ||
const assert = require('assert') | ||
|
||
const { networks, coins } = require('../src') | ||
|
||
describe('networks', function () { | ||
// Ideally, all properties for all coins should be distinct. | ||
// However, there are some exceptions and some networks share the same properties. | ||
|
||
// Here we define some groups of networks that are allowed to share properties. | ||
const bitcoinSharedMessagePrefix = [ | ||
'bitcoin', 'testnet', | ||
'bitcoincash', 'bitcoincashTestnet', | ||
'bitcoinsv', 'bitcoinsvTestnet' | ||
] | ||
|
||
const bitcoinMainnetSharedPubkeyPrefix = [ | ||
'bitcoin', | ||
'bitcoincash', | ||
'bitcoinsv' | ||
] | ||
|
||
const bitcoinMainnetSharedScriptPrefix = bitcoinMainnetSharedPubkeyPrefix.filter(() => true) | ||
|
||
const bitcoinTestnetSharedPubkeyPrefix = [ | ||
'testnet', | ||
'bitcoincashTestnet', | ||
'bitcoinsvTestnet', | ||
'litecoinTest' | ||
] | ||
|
||
const bitcoinTestnetSharedScriptPrefix = bitcoinTestnetSharedPubkeyPrefix.filter(n => n !== 'litecoinTest') | ||
|
||
const bitcoinMainnetSharedWIFPrefix = [ | ||
'bitcoin', | ||
'bitcoincash', | ||
'bitcoingold', | ||
'bitcoinsv', | ||
'zcash' | ||
] | ||
|
||
const bitcoinTestnetSharedWIFPrefix = [ | ||
'testnet', | ||
'bitcoincashTestnet', | ||
'bitcoinsvTestnet', | ||
'dashTest', | ||
'zcashTest' | ||
] | ||
|
||
// FIXME(BG-16466): this is a bug, they should be distinct | ||
const litecoinSharedWIFPrefix = [ | ||
'litecoin', | ||
'litecoinTest' | ||
] | ||
|
||
const bech32Coins = [ | ||
'bitcoin', 'testnet', | ||
'bitcoingold', | ||
'litecoin', 'litecoinTest' | ||
] | ||
|
||
function sameGroup (group, name, otherName) { | ||
return group.includes(name) && group.includes(otherName) | ||
} | ||
|
||
for (const name in networks) { | ||
const network = networks[name] | ||
|
||
describe(`networks.${name}`, function () { | ||
it('has expected properties', function () { | ||
assert.strictEqual(typeof network, 'object') | ||
assert.strictEqual(typeof network.messagePrefix, 'string') | ||
assert.strictEqual(typeof network.bech32, bech32Coins.includes(name) ? 'string' : 'undefined') | ||
assert.strictEqual(typeof network.bip32, 'object') | ||
assert.strictEqual(typeof network.pubKeyHash, 'number') | ||
assert.strictEqual(typeof network.scriptHash, 'number') | ||
assert.strictEqual(typeof network.wif, 'number') | ||
assert.strictEqual(typeof network.coin, 'string') | ||
}) | ||
|
||
for (const otherName in networks) { | ||
if (name === otherName) { | ||
continue | ||
} | ||
|
||
it(`has distinct properties with ${otherName}`, function () { | ||
const otherNetwork = networks[otherName] | ||
|
||
assert.strictEqual( | ||
(network.messagePrefix === otherNetwork.messagePrefix), | ||
(network.coin === otherNetwork.coin) || | ||
sameGroup(bitcoinSharedMessagePrefix, name, otherName) | ||
) | ||
|
||
assert.strictEqual( | ||
(network.pubKeyHash === otherNetwork.pubKeyHash), | ||
sameGroup(bitcoinMainnetSharedPubkeyPrefix, name, otherName) || | ||
sameGroup(bitcoinTestnetSharedPubkeyPrefix, name, otherName) | ||
) | ||
|
||
assert.strictEqual( | ||
(network.scriptHash === otherNetwork.scriptHash), | ||
sameGroup(bitcoinMainnetSharedScriptPrefix, name, otherName) || | ||
sameGroup(bitcoinTestnetSharedScriptPrefix, name, otherName) | ||
) | ||
|
||
assert.strictEqual( | ||
(network.wif === otherNetwork.wif), | ||
sameGroup(bitcoinMainnetSharedWIFPrefix, name, otherName) || | ||
sameGroup(bitcoinTestnetSharedWIFPrefix, name, otherName) || | ||
// FIXME(BG-16466): this group should not exist | ||
sameGroup(litecoinSharedWIFPrefix, name, otherName) | ||
) | ||
}) | ||
} | ||
}) | ||
} | ||
}) |