Skip to content

Commit

Permalink
Added tests for xpub address generation with alternate interal/extern…
Browse files Browse the repository at this point in the history
…al(change) option.
  • Loading branch information
tboydston committed Feb 9, 2022
1 parent 267b350 commit 5e6a55c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
node_modules/
test.js
.DS_Store
2 changes: 1 addition & 1 deletion hdAddressGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ class AddressGenerator {

/**
* Checks if a coin has a test in the 'coins' folder.
* @param {sting} coinName Short name of the coin.
* @param {string} coinName Short name of the coin.
*/
coinHasTest(coinName){

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hdaddressgenerator",
"version": "1.0.7",
"version": "1.1.7",
"description": "Generate hierarchical deterministic(HD) coin specific crypto addresses ( legacy, segwit, bech32 ) from single master key pair for over 190 different cryptocurrencies.",
"main": "hdAddressGenerator.js",
"scripts": {
Expand Down
20 changes: 19 additions & 1 deletion tests/coinTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ for (const coin in coinData) {
let withExtPub44 = false
let withExtPub49 = false
let withExtPub84 = false
let withExtPub44Internal = false

try{ bip44 = Gen.withMnemonic(settings.mnemonic,false,ref.shortName) } catch(e){}
try{ bip44WithPassPhrase = Gen.withMnemonic(settings.mnemonic,settings.passphrase,ref.shortName,false) } catch(e){}
Expand All @@ -60,8 +61,10 @@ for (const coin in coinData) {
try{ bip141 = Gen.withMnemonicBIP141(settings.mnemonic,false,ref.shortName,"m/0'/0'","p2wpkhInP2sh") } catch(e){}
try{ bip141seed = Gen.withSeedBIP141(settings.bip32Seed,ref.shortName,"m/0'/0'","p2wpkhInP2sh") } catch(e){}
try{ withExtPub44 = Gen.withExtPub(ref.bip44AccountExtPubKey,ref.shortName ) } catch(e){}
try{ withExtPub44Internal = Gen.withExtPub(ref.bip44AccountExtPubKey,ref.shortName,44,0,1) } catch(e){}
try{ withExtPub49 = Gen.withExtPub(ref.bip49AccountExtPubKey,ref.shortName,49 ) } catch(e){}
try{ withExtPub84 = Gen.withExtPub(ref.bip84AccountExtPubKey,ref.shortName,84 ) } catch(e){}
try{ withExtPub84 = Gen.withExtPub(ref.bip84AccountExtPubKey,ref.shortName,84 ) } catch(e){}


// Test root Keys
if ( ref.bip32RootKeyBip44 != undefined ){
Expand Down Expand Up @@ -274,6 +277,21 @@ for (const coin in coinData) {
})
}

if ( ref.bip44AccountExtPubKey !== undefined && ref.addressBip44index0 != undefined && ref.addressBip44index1 != undefined && ref.shortName == "BTC" ){
it('Expect extPub generated address using internal option ( i.e. m/44\'/0\'/0\'/1/0 ) with addressBip44index0 and addressBip44index1 address and pub keys to match reference.', async () => {

let addresses = await withExtPub44Internal.generate(2)

assert.strictEqual(addresses[0].address,ref.addressBip44index0Internal)
assert.strictEqual(addresses[0].pubKey,ref.pubKeyBip44index0Internal)
assert.strictEqual(addresses[0].privKey,'')
assert.strictEqual(addresses[1].address,ref.addressBip44index1Internal)
assert.strictEqual(addresses[1].pubKey,ref.pubKeyBip44index1Internal)
assert.strictEqual(addresses[1].privKey,'')

})
}

if ( ref.bip49AccountExtPubKey !== undefined && ref.addressBip49index0 != undefined && ref.addressBip49index1 != undefined ){
it('Expect extPub generated address addressBip49index0 and addressBip49index1 address and pub keys to match reference.', async () => {

Expand Down
7 changes: 7 additions & 0 deletions tests/coins/BTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ module.exports = {
pubKeyBip44EncryptedIndex0:"0430175f65585b898540016463ac077776b5da6e8dcfd18e086e3d5f9735293c4236e68d79975b57a124d434d9c0ff73bd726bc9286fb88c0e1e867c551c85edce",
privKeyBip44EncryptedIndex0:"6PRVD9KM1EmjTZ2xrmg83qpeDoKnhxgJSsRJEUroWTViF1fkFzJXJz3GSq",

addressBip44index0Internal:"19TGQmBdTsS6ghQrkZs6b4LLuAMnLzNke8",
pubKeyBip44index0Internal:"037922ca607a670dbfc7108ae779d593b0fcd6436bc7887dad4fd138bd389c0337",

addressBip44index1Internal:"1PT3h8jPVzisaEGSx4S9Xudpax7M6hX63U",
pubKeyBip44index1Internal:"03904cb21857450eb62eed84815bba65f895a8b4624ab451952e9acc5e663b016e",


// BIP 49 Addresses
addressBip49index0:"34Rqef93KR98XMaLneHEhzkr1kxaHg5AAA",
pubKeyBip49index0:"0269c38d634710f8db4c543b62754abf5cc276b5227e81ef82be13ebfac7804d01",
Expand Down

0 comments on commit 5e6a55c

Please sign in to comment.