use standardjs formatting
This commit is contained in:
parent
09d8e440de
commit
399803affa
41 changed files with 1252 additions and 1177 deletions
test/integration
|
@ -1,9 +1,11 @@
|
|||
/* global describe, it */
|
||||
|
||||
var assert = require('assert')
|
||||
var bitcoin = require('../../')
|
||||
var blockchain = new (require('cb-helloblock'))('testnet')
|
||||
|
||||
describe('bitcoinjs-lib (multisig)', function() {
|
||||
it('can create a 2-of-3 multisig P2SH address', function() {
|
||||
describe('bitcoinjs-lib (multisig)', function () {
|
||||
it('can create a 2-of-3 multisig P2SH address', function () {
|
||||
var pubKeys = [
|
||||
'026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
|
||||
'02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
|
||||
|
@ -17,29 +19,33 @@ describe('bitcoinjs-lib (multisig)', function() {
|
|||
assert.equal(address, '36NUkt6FWUi3LAWBqWRdDmdTWbt91Yvfu7')
|
||||
})
|
||||
|
||||
it('can spend from a 2-of-2 multsig P2SH address', function(done) {
|
||||
it('can spend from a 2-of-2 multsig P2SH address', function (done) {
|
||||
this.timeout(20000)
|
||||
|
||||
var privKeys = [
|
||||
'91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx',
|
||||
'91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgww7vXtT'
|
||||
].map(bitcoin.ECKey.fromWIF)
|
||||
var pubKeys = privKeys.map(function(x) { return x.pub })
|
||||
var pubKeys = privKeys.map(function (x) {
|
||||
return x.pub
|
||||
})
|
||||
|
||||
var redeemScript = bitcoin.scripts.multisigOutput(2, pubKeys) // 2 of 2
|
||||
var scriptPubKey = bitcoin.scripts.scriptHashOutput(redeemScript.getHash())
|
||||
var address = bitcoin.Address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet).toString()
|
||||
|
||||
// Attempt to send funds to the source address
|
||||
blockchain.addresses.__faucetWithdraw(address, 2e4, function(err) {
|
||||
blockchain.addresses.__faucetWithdraw(address, 2e4, function (err) {
|
||||
if (err) return done(err)
|
||||
|
||||
// get latest unspents from the address
|
||||
blockchain.addresses.unspents(address, function(err, unspents) {
|
||||
// get latest unspents from the address
|
||||
blockchain.addresses.unspents(address, function (err, unspents) {
|
||||
if (err) return done(err)
|
||||
|
||||
// filter small unspents
|
||||
unspents = unspents.filter(function(unspent) { return unspent.value > 1e4 })
|
||||
// filter small unspents
|
||||
unspents = unspents.filter(function (unspent) {
|
||||
return unspent.value > 1e4
|
||||
})
|
||||
|
||||
// use the oldest unspent
|
||||
var unspent = unspents.pop()
|
||||
|
@ -52,16 +58,16 @@ describe('bitcoinjs-lib (multisig)', function() {
|
|||
txb.addOutput(targetAddress, 1e4)
|
||||
|
||||
// sign w/ each private key
|
||||
privKeys.forEach(function(privKey) {
|
||||
privKeys.forEach(function (privKey) {
|
||||
txb.sign(0, privKey, redeemScript)
|
||||
})
|
||||
|
||||
// broadcast our transaction
|
||||
blockchain.transactions.propagate(txb.build().toHex(), function(err) {
|
||||
blockchain.transactions.propagate(txb.build().toHex(), function (err) {
|
||||
if (err) return done(err)
|
||||
|
||||
// check that the funds (1e4 Satoshis) indeed arrived at the intended address
|
||||
blockchain.addresses.summary(targetAddress, function(err, result) {
|
||||
// check that the funds (1e4 Satoshis) indeed arrived at the intended address
|
||||
blockchain.addresses.summary(targetAddress, function (err, result) {
|
||||
if (err) return done(err)
|
||||
|
||||
assert.equal(result.balance, 1e4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue