From 63231fb67d684c3a4a49fab296a0c83e05e21ccc Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 6 May 2014 14:10:25 +1000 Subject: [PATCH] Extends test for custom Wallet change addresses --- test/wallet.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/wallet.js b/test/wallet.js index f83c160..dd4d2ed 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -478,17 +478,27 @@ describe('Wallet', function() { it('should allow custom changeAddress', function(){ var wallet = new Wallet(seed, {network: 'testnet'}) var address = wallet.generateAddress() - utxo = { - "hash":"b3c5fde139dc0a3bba2729bfd5b9e16f5894131dc3dc46a91151da3053e7e3a5", - "outputIndex": 0, - "address" : address, - "value": 100000 - } - var to = "mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue" + + wallet.setUnspentOutputs([{ + hash: fakeTxHash(0), + outputIndex: 0, + address: address, + value: value + }]) + assert.equal(wallet.getBalance(), value) + var changeAddress = 'mfrFjnKZUvTcvdAK2fUX5D8v1Epu5H8JCk' - wallet.setUnspentOutputs([utxo]) - var tx = wallet.createTx(to, 10000, 1000, changeAddress) + var to = 'mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue' + var toValue = value / 2 + var fee = 1e3 + + var tx = wallet.createTx(to, toValue, fee, changeAddress) assert.equal(tx.outs.length, 2) + assert.equal(tx.outs[0].address.toString(), to) + assert.equal(tx.outs[0].value, toValue) + + assert.equal(tx.outs[1].address.toString(), changeAddress) + assert.equal(tx.outs[1].value, value - (toValue + fee)) }) })