Test old args as well
This commit is contained in:
parent
ee3150d7c7
commit
4bed585f6a
1 changed files with 558 additions and 549 deletions
|
@ -11,7 +11,7 @@ const NETWORKS = require('../src/networks')
|
||||||
|
|
||||||
const fixtures = require('./fixtures/transaction_builder')
|
const fixtures = require('./fixtures/transaction_builder')
|
||||||
|
|
||||||
function constructSign (f, txb) {
|
function constructSign (f, txb, useOldSignArgs) {
|
||||||
const network = NETWORKS[f.network]
|
const network = NETWORKS[f.network]
|
||||||
const stages = f.stages && f.stages.concat()
|
const stages = f.stages && f.stages.concat()
|
||||||
|
|
||||||
|
@ -35,6 +35,12 @@ function constructSign (f, txb) {
|
||||||
witnessScript = bscript.fromASM(sign.witnessScript)
|
witnessScript = bscript.fromASM(sign.witnessScript)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (useOldSignArgs) {
|
||||||
|
// DEPRECATED: v6 will remove this interface
|
||||||
|
txb.sign(index, keyPair, redeemScript, sign.hashType, witnessValue, witnessScript)
|
||||||
|
} else {
|
||||||
|
// prevOutScriptType is required, see /ts_src/transaction_builder.ts
|
||||||
|
// The PREVOUT_TYPES constant is a Set with all possible values.
|
||||||
txb.sign({
|
txb.sign({
|
||||||
prevOutScriptType: sign.prevOutScriptType,
|
prevOutScriptType: sign.prevOutScriptType,
|
||||||
vin: index,
|
vin: index,
|
||||||
|
@ -44,6 +50,7 @@ function constructSign (f, txb) {
|
||||||
witnessValue,
|
witnessValue,
|
||||||
witnessScript,
|
witnessScript,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (sign.stage) {
|
if (sign.stage) {
|
||||||
const tx = txb.buildIncomplete()
|
const tx = txb.buildIncomplete()
|
||||||
|
@ -56,7 +63,7 @@ function constructSign (f, txb) {
|
||||||
return txb
|
return txb
|
||||||
}
|
}
|
||||||
|
|
||||||
function construct (f, dontSign) {
|
function construct (f, dontSign, useOldSignArgs) {
|
||||||
const network = NETWORKS[f.network]
|
const network = NETWORKS[f.network]
|
||||||
const txb = new TransactionBuilder(network)
|
const txb = new TransactionBuilder(network)
|
||||||
|
|
||||||
|
@ -92,10 +99,11 @@ function construct (f, dontSign) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (dontSign) return txb
|
if (dontSign) return txb
|
||||||
return constructSign(f, txb)
|
return constructSign(f, txb, useOldSignArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('TransactionBuilder', () => {
|
for (const useOldSignArgs of [ false, true ]) {
|
||||||
|
describe(`TransactionBuilder: useOldSignArgs === ${useOldSignArgs}`, () => {
|
||||||
// constants
|
// constants
|
||||||
const keyPair = ECPair.fromPrivateKey(Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex'))
|
const keyPair = ECPair.fromPrivateKey(Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex'))
|
||||||
const scripts = [
|
const scripts = [
|
||||||
|
@ -157,7 +165,7 @@ describe('TransactionBuilder', () => {
|
||||||
assert.strictEqual(bscript.toASM(input.script), f.inputs[i].scriptSig)
|
assert.strictEqual(bscript.toASM(input.script), f.inputs[i].scriptSig)
|
||||||
})
|
})
|
||||||
|
|
||||||
constructSign(f, txb)
|
constructSign(f, txb, useOldSignArgs)
|
||||||
const txAfter = f.incomplete ? txb.buildIncomplete() : txb.build()
|
const txAfter = f.incomplete ? txb.buildIncomplete() : txb.build()
|
||||||
|
|
||||||
txAfter.ins.forEach((input, i) => {
|
txAfter.ins.forEach((input, i) => {
|
||||||
|
@ -464,7 +472,7 @@ describe('TransactionBuilder', () => {
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
fixtures.valid.build.forEach(f => {
|
fixtures.valid.build.forEach(f => {
|
||||||
it('builds "' + f.description + '"', () => {
|
it('builds "' + f.description + '"', () => {
|
||||||
const txb = construct(f)
|
const txb = construct(f, undefined, useOldSignArgs)
|
||||||
const tx = f.incomplete ? txb.buildIncomplete() : txb.build()
|
const tx = f.incomplete ? txb.buildIncomplete() : txb.build()
|
||||||
|
|
||||||
assert.strictEqual(tx.toHex(), f.txHex)
|
assert.strictEqual(tx.toHex(), f.txHex)
|
||||||
|
@ -480,7 +488,7 @@ describe('TransactionBuilder', () => {
|
||||||
if (f.txHex) {
|
if (f.txHex) {
|
||||||
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
||||||
} else {
|
} else {
|
||||||
txb = construct(f)
|
txb = construct(f, undefined, useOldSignArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
txb.build()
|
txb.build()
|
||||||
|
@ -495,7 +503,7 @@ describe('TransactionBuilder', () => {
|
||||||
if (f.txHex) {
|
if (f.txHex) {
|
||||||
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
||||||
} else {
|
} else {
|
||||||
txb = construct(f)
|
txb = construct(f, undefined, useOldSignArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
txb.buildIncomplete()
|
txb.buildIncomplete()
|
||||||
|
@ -507,7 +515,7 @@ describe('TransactionBuilder', () => {
|
||||||
if (f.txHex) {
|
if (f.txHex) {
|
||||||
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
|
||||||
} else {
|
} else {
|
||||||
txb = construct(f)
|
txb = construct(f, undefined, useOldSignArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
txb.buildIncomplete()
|
txb.buildIncomplete()
|
||||||
|
@ -720,3 +728,4 @@ describe('TransactionBuilder', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue