sign tx
This commit is contained in:
parent
8f0413da98
commit
913b48e87f
3 changed files with 32 additions and 11 deletions
|
@ -18,7 +18,8 @@
|
||||||
"mocha": "1.18.2",
|
"mocha": "1.18.2",
|
||||||
"istanbul": "0.1.30",
|
"istanbul": "0.1.30",
|
||||||
"uglify-js": "2.4.13",
|
"uglify-js": "2.4.13",
|
||||||
"node-browserify": "https://github.com/substack/node-browserify/tarball/master"
|
"node-browserify": "https://github.com/substack/node-browserify/tarball/master",
|
||||||
|
"sinon": "^1.9.0"
|
||||||
},
|
},
|
||||||
"testling": {
|
"testling": {
|
||||||
"browsers": [
|
"browsers": [
|
||||||
|
|
|
@ -201,7 +201,8 @@ var Wallet = function (seed, options) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: sign tx
|
this.sign(tx)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ var fixtureTxes = require('./fixtures/mainnet_tx')
|
||||||
var fixtureTx1Hex = fixtureTxes.prevTx
|
var fixtureTx1Hex = fixtureTxes.prevTx
|
||||||
var fixtureTx2Hex = fixtureTxes.tx
|
var fixtureTx2Hex = fixtureTxes.tx
|
||||||
|
|
||||||
|
var sinon = require('sinon')
|
||||||
|
|
||||||
describe('Wallet', function() {
|
describe('Wallet', function() {
|
||||||
var seed, wallet;
|
var seed, wallet;
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
|
@ -318,37 +320,38 @@ describe('Wallet', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('createTx', function(){
|
describe('createTx', function(){
|
||||||
var to, value, prevTx;
|
var to, value;
|
||||||
|
var address1, address2;
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
to = '15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3'
|
to = '15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3'
|
||||||
value = 500000
|
value = 500000
|
||||||
|
|
||||||
// generate 2 addresses
|
// generate 2 addresses
|
||||||
wallet.generateAddress()
|
address1 = wallet.generateAddress()
|
||||||
wallet.generateAddress()
|
address2 = wallet.generateAddress()
|
||||||
|
|
||||||
// set up 3 utxo
|
// set up 3 utxo
|
||||||
utxo = [
|
utxo = [
|
||||||
{
|
{
|
||||||
"hash": fakeTxHash(1),
|
"hash": fakeTxHash(1),
|
||||||
"outputIndex": 0,
|
"outputIndex": 0,
|
||||||
"scriptPubKey": scriptPubKeyFor(wallet.addresses[0], 300000),
|
"scriptPubKey": scriptPubKeyFor(address1, 300000),
|
||||||
"address" : wallet.addresses[0],
|
"address" : address1,
|
||||||
"value": 400000 // not enough for value
|
"value": 400000 // not enough for value
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"hash": fakeTxHash(2),
|
"hash": fakeTxHash(2),
|
||||||
"outputIndex": 1,
|
"outputIndex": 1,
|
||||||
"scriptPubKey": scriptPubKeyFor(wallet.addresses[0], 500000),
|
"scriptPubKey": scriptPubKeyFor(address1, 500000),
|
||||||
"address" : wallet.addresses[0],
|
"address" : address1,
|
||||||
"value": 500000 // enough for only value
|
"value": 500000 // enough for only value
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"hash": fakeTxHash(3),
|
"hash": fakeTxHash(3),
|
||||||
"outputIndex": 0,
|
"outputIndex": 0,
|
||||||
"scriptPubKey": scriptPubKeyFor(wallet.addresses[1], 520000),
|
"scriptPubKey": scriptPubKeyFor(address2, 520000),
|
||||||
"address" : wallet.addresses[1],
|
"address" : address2,
|
||||||
"value": 520000 // enough for value and fee
|
"value": 520000 // enough for value and fee
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -422,6 +425,22 @@ describe('Wallet', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('signing', function(){
|
||||||
|
afterEach(function(){
|
||||||
|
Transaction.prototype.sign.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('signes the inputs with respective keys', function(){
|
||||||
|
var fee = 30000
|
||||||
|
sinon.stub(Transaction.prototype, "sign")
|
||||||
|
|
||||||
|
var tx = wallet.createTx(to, value, fee)
|
||||||
|
|
||||||
|
assert(Transaction.prototype.sign.calledWith(0, wallet.getPrivateKeyForAddress(address2)))
|
||||||
|
assert(Transaction.prototype.sign.calledWith(1, wallet.getPrivateKeyForAddress(address1)))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function assertEqual(obj1, obj2){
|
function assertEqual(obj1, obj2){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue