tests/integration: simplify the bare witness examples
This commit is contained in:
parent
b7e7d879b3
commit
732df83346
2 changed files with 68 additions and 69 deletions
test/integration
|
@ -4,6 +4,7 @@ const dhttp = require('dhttp/200')
|
|||
|
||||
const APIPASS = process.env.APIPASS || 'satoshi'
|
||||
const APIURL = 'https://api.dcousens.cloud/1'
|
||||
const NETWORK = bitcoin.networks.testnet
|
||||
|
||||
function broadcast (txHex, callback) {
|
||||
dhttp({
|
||||
|
@ -42,6 +43,31 @@ function faucet (address, value, callback) {
|
|||
})
|
||||
}
|
||||
|
||||
function faucetComplex (output, value, callback) {
|
||||
const keyPair = bitcoin.ECPair.makeRandom({ network: NETWORK })
|
||||
const p2pkh = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: NETWORK })
|
||||
|
||||
faucet(p2pkh.address, value * 2, (err, unspent) => {
|
||||
if (err) return callback(err)
|
||||
|
||||
const txvb = new bitcoin.TransactionBuilder(NETWORK)
|
||||
txvb.addInput(unspent.txId, unspent.vout, null, p2pkh.output)
|
||||
txvb.addOutput(output, value)
|
||||
txvb.sign(0, keyPair)
|
||||
const txv = txvb.build()
|
||||
|
||||
broadcast(txv.toHex(), function (err) {
|
||||
if (err) return callback(err)
|
||||
|
||||
return callback(null, {
|
||||
txId: txv.getId(),
|
||||
vout: 0,
|
||||
value
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fetch (txId, callback) {
|
||||
dhttp({
|
||||
method: 'GET',
|
||||
|
@ -78,14 +104,15 @@ function randomAddress () {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
broadcast: broadcast,
|
||||
faucet: faucet,
|
||||
fetch: fetch,
|
||||
height: height,
|
||||
mine: mine,
|
||||
network: bitcoin.networks.testnet,
|
||||
unspents: unspents,
|
||||
verify: verify,
|
||||
randomAddress: randomAddress,
|
||||
broadcast,
|
||||
faucet,
|
||||
faucetComplex,
|
||||
fetch,
|
||||
height,
|
||||
mine,
|
||||
network: NETWORK,
|
||||
unspents,
|
||||
verify,
|
||||
randomAddress,
|
||||
RANDOM_ADDRESS: randomAddress()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue