Test old args as well

This commit is contained in:
junderw 2019-06-14 11:55:34 +09:00
parent ee3150d7c7
commit 4bed585f6a
No known key found for this signature in database
GPG key ID: B256185D3A971908

View file

@ -11,7 +11,7 @@ const NETWORKS = require('../src/networks')
const fixtures = require('./fixtures/transaction_builder')
function constructSign (f, txb) {
function constructSign (f, txb, useOldSignArgs) {
const network = NETWORKS[f.network]
const stages = f.stages && f.stages.concat()
@ -35,6 +35,12 @@ function constructSign (f, txb) {
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({
prevOutScriptType: sign.prevOutScriptType,
vin: index,
@ -44,6 +50,7 @@ function constructSign (f, txb) {
witnessValue,
witnessScript,
})
}
if (sign.stage) {
const tx = txb.buildIncomplete()
@ -56,7 +63,7 @@ function constructSign (f, txb) {
return txb
}
function construct (f, dontSign) {
function construct (f, dontSign, useOldSignArgs) {
const network = NETWORKS[f.network]
const txb = new TransactionBuilder(network)
@ -92,10 +99,11 @@ function construct (f, dontSign) {
})
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
const keyPair = ECPair.fromPrivateKey(Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex'))
const scripts = [
@ -157,7 +165,7 @@ describe('TransactionBuilder', () => {
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()
txAfter.ins.forEach((input, i) => {
@ -464,7 +472,7 @@ describe('TransactionBuilder', () => {
describe('build', () => {
fixtures.valid.build.forEach(f => {
it('builds "' + f.description + '"', () => {
const txb = construct(f)
const txb = construct(f, undefined, useOldSignArgs)
const tx = f.incomplete ? txb.buildIncomplete() : txb.build()
assert.strictEqual(tx.toHex(), f.txHex)
@ -480,7 +488,7 @@ describe('TransactionBuilder', () => {
if (f.txHex) {
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
} else {
txb = construct(f)
txb = construct(f, undefined, useOldSignArgs)
}
txb.build()
@ -495,7 +503,7 @@ describe('TransactionBuilder', () => {
if (f.txHex) {
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
} else {
txb = construct(f)
txb = construct(f, undefined, useOldSignArgs)
}
txb.buildIncomplete()
@ -507,7 +515,7 @@ describe('TransactionBuilder', () => {
if (f.txHex) {
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
} else {
txb = construct(f)
txb = construct(f, undefined, useOldSignArgs)
}
txb.buildIncomplete()
@ -720,3 +728,4 @@ describe('TransactionBuilder', () => {
})
})
})
}