wallet exposes unspent outputs via a getter

also add reverseEndian method to convert
This commit is contained in:
Wei Lu 2014-03-22 14:37:09 +08:00
parent 68e8834c66
commit 16dc68cbaa
4 changed files with 67 additions and 8 deletions

View file

@ -6,17 +6,13 @@ var SHA256 = require('crypto-js/sha256')
var Crypto = require('crypto-js')
describe('Wallet', function() {
var seed;
var seed, wallet;
beforeEach(function(){
seed = convert.wordArrayToBytes(SHA256("don't use a string seed like this in real life"))
wallet = new Wallet(seed)
})
describe('constructor', function() {
var wallet;
beforeEach(function() {
wallet = new Wallet(seed)
})
it('defaults to Bitcoin mainnet', function() {
assert.equal(wallet.getMasterKey().network, 'mainnet')
})
@ -47,7 +43,6 @@ describe('Wallet', function() {
})
describe('constructor options', function() {
var wallet;
beforeEach(function() {
wallet = new Wallet(seed, {network: 'testnet'})
})
@ -149,6 +144,36 @@ describe('Wallet', function() {
})
})
describe('Unspent Outputs', function(){
var expectedUtxo, expectedOutputKey;
beforeEach(function(){
expectedUtxo = [
{
"hash":"6a4062273ac4f9ea4ffca52d9fd102b08f6c32faa0a4d1318e3a7b2e437bb9c7",
"hashLittleEndian":"c7b97b432e7b3a8e31d1a4a0fa326c8fb002d19f2da5fc4feaf9c43a2762406a",
"outputIndex": 0,
"scriptPubKey":"76a91468edf28474ee22f68dfe7e56e76c017c1701b84f88ac",
"address" : "1azpkpcfczkduetfbqul4mokqai3m3hmxv",
"value": 20000
}
]
expectedOutputKey = expectedUtxo[0].hash + ":" + expectedUtxo[0].outputIndex
})
describe('getUnspentOutputs', function(){
it('parses wallet outputs to the expect format', function(){
wallet.outputs[expectedOutputKey] = {
output: expectedOutputKey,
scriptPubKey: expectedUtxo[0].scriptPubKey,
address: expectedUtxo[0].address,
value: expectedUtxo[0].value
}
assert.deepEqual(wallet.getUnspentOutputs(), expectedUtxo)
})
})
})
function assertEqual(obj1, obj2){
assert.equal(obj1.toString(), obj2.toString())
}