|
|
@ -141,10 +141,14 @@ describe('Wallet', function() { |
|
|
|
wallet.generateAddress() |
|
|
|
wallet.generateAddress() |
|
|
|
|
|
|
|
assertEqual(wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X"), |
|
|
|
wallet.getExternalAccount().derive(1).priv) |
|
|
|
assertEqual(wallet.getPrivateKeyForAddress("mnXiDR4MKsFxcKJEZjx4353oXvo55iuptn"), |
|
|
|
wallet.getInternalAccount().derive(0).priv) |
|
|
|
assertEqual( |
|
|
|
wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X"), |
|
|
|
wallet.getExternalAccount().derive(1).priv |
|
|
|
) |
|
|
|
assertEqual( |
|
|
|
wallet.getPrivateKeyForAddress("mnXiDR4MKsFxcKJEZjx4353oXvo55iuptn"), |
|
|
|
wallet.getInternalAccount().derive(0).priv |
|
|
|
) |
|
|
|
}) |
|
|
|
|
|
|
|
it('raises an error when address is not found', function(){ |
|
|
@ -463,7 +467,10 @@ describe('Wallet', function() { |
|
|
|
var to = 'mt7MyTVVEWnbwpF5hBn6fgnJcv95Syk2ue' |
|
|
|
var wallet = new Wallet(seed, {network: 'testnet'}) |
|
|
|
var tx = wallet.createTx(to, value) |
|
|
|
|
|
|
|
assert.equal(tx.outs.length, 1) |
|
|
|
assert.equal(tx.outs[0].address.toString(), to) |
|
|
|
assert.equal(tx.outs[0].value, value) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
@ -471,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)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|