From af942f9b064db0addbe8a8a3b0a2a1df17ef32b7 Mon Sep 17 00:00:00 2001 From: olalonde Date: Wed, 7 May 2014 08:38:45 +0800 Subject: [PATCH] Armory: added tests --- lib/Armory.js | 9 +++++ test/test.Armory.js | 92 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/test.Armory.js diff --git a/lib/Armory.js b/lib/Armory.js index 4d9194f76..2e5acc2b3 100644 --- a/lib/Armory.js +++ b/lib/Armory.js @@ -41,6 +41,15 @@ Armory.prototype.next = function () { return new Armory(this.chaincode, next_pubkey); }; +/** + * PS: MPK here represents the pubkey concatenated + * with the chain code. It is an unofficial standard. + * + * Armory will soon release an officially supported + * format: + * + * https://github.com/etotheipi/BitcoinArmory/issues/204#issuecomment-42217801 + */ Armory.fromMasterPublicKey = function (mpk) { var pubkey = mpk.substr(0, 130); var chaincode = mpk.substr(130, mpk.length); diff --git a/test/test.Armory.js b/test/test.Armory.js new file mode 100644 index 000000000..8be6fe3b1 --- /dev/null +++ b/test/test.Armory.js @@ -0,0 +1,92 @@ +'use strict'; + +var chai = chai || require('chai'); +var bitcore = bitcore || require('../bitcore'); + +var should = chai.should(); + +var Armory = bitcore.Armory; +var Address = bitcore.Address; + +/** + * This is the Armory root code that was used to generated the hard coded values in + * those tests: + */ + +var seed = [ + 'aagh hjfj sihk ietj giik wwai awtd uodh hnji', + 'soss uaku egod utai itos fijj ihgi jhau jtoo' +].join('\n'); + +/* + * It was retrieved by creating a wallet in Armory and creating a paper backup. + * + * This is the public key as presented on the generated Armory paper wallets: + */ + +var PublicX = '9df5 23e7 18b9 1f59 a790 2d46 999f 9357 ccf8 7208 24d4 3076 4516 b809 f7ab ce4e'; +var PublicY = '66ba 5d21 4682 0dae 401d 9506 8437 2516 79f9 0c56 4186 cc50 07df c6d0 6989 1ff4'; +var pubkey = '04' + PublicX.split(' ').join('') + PublicY.split(' ').join(''); + +/* + * This chain code was derived from the seed above: + */ +var chaincode = '84ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e'; + +/* + * This is some addresses generated from the wallet: + */ +var address = [ + '1PUzLkds8eHGjHPaW7v7h23bzmHjrRMVqz', + '1CGrip2uQUwhP2f3ARfbcrmtdwvWzELRmj', + '1BfBauMP4PX1ZBYrqH4K4R8KWrFfskrs7E', + '15emDCBVgBJLDP5cKxuwZ4Q77sfqEcwZvC', + '16tDJhMYBv1szZgRZCohWrzEvzX2bG7vEQ' +]; + +var instance, fromseed, first; + +describe('Armory', function() { + it('should initialze the main object', function() { + should.exist(Armory); + }); + + it('should be able to create instance from chaincode, pubkey', function() { + instance = new Armory(chaincode, pubkey); + should.exist(instance); + }); + + it('should be able to create instance from seed', function() { + fromseed = Armory.fromSeed(seed); + should.exist(fromseed); + }); + + it('fromseed should generate the expected chain code', function() { + should.equal(fromseed.chaincode.toString('hex'), chaincode.toString('hex')); + should.equal(fromseed.chaincode.toString('hex'), instance.chaincode.toString('hex')); + }); + + it('fromseed should be able to generate the first public key', function() { + first = fromseed.next(); + should.exist(first); + }); + + it('instance created from chaincode,pubkey and the first instance generated by fromseed should match', function() { + should.equal(first.pubkey.toString('hex'), instance.pubkey.toString('hex')); + should.equal(first.chaincode.toString('hex'), instance.chaincode.toString('hex')); + }); + + it('armory should generate the expected addresses for the given chaincode,pubkey', function() { + var addr, a; + a = instance; + for (var i = 0; i < address.length; i++) { + should.equal(Address.fromPubKey(a.pubkey).as('base58'), address[i]); + a = a.next(); + } + }); +}); + + + + +