Browse Source

Use fromASM instead. Much cleaner.

addComplexScript
junderw 7 years ago
parent
commit
e6ac7c16ce
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 78
      test/integration/csv.js

78
test/integration/csv.js

@ -21,20 +21,18 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
// IF MTP (from when confirmed) > seconds, aQ can redeem // IF MTP (from when confirmed) > seconds, aQ can redeem
function csvCheckSigOutput (aQ, bQ, sequence) { function csvCheckSigOutput (aQ, bQ, sequence) {
return bitcoin.script.compile([ return bitcoin.script.fromASM(`
/* eslint-disable indent */ OP_IF
bitcoin.opcodes.OP_IF, ${bitcoin.script.number.encode(sequence).toString('hex')}
bitcoin.script.number.encode(sequence), OP_CHECKSEQUENCEVERIFY
bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, OP_DROP
bitcoin.opcodes.OP_DROP, OP_ELSE
bitcoin.opcodes.OP_ELSE, ${bQ.publicKey.toString('hex')}
bQ.publicKey, OP_CHECKSIGVERIFY
bitcoin.opcodes.OP_CHECKSIGVERIFY, OP_ENDIF
bitcoin.opcodes.OP_ENDIF, ${aQ.publicKey.toString('hex')}
aQ.publicKey, OP_CHECKSIG
bitcoin.opcodes.OP_CHECKSIG `.trim().replace(/\s+/g, ' '))
/* eslint-enable indent */
])
} }
// 2 of 3 multisig of bQ, cQ, dQ, // 2 of 3 multisig of bQ, cQ, dQ,
@ -44,33 +42,31 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
// Note: bitcoinjs-lib will not offer specific support for problems with // Note: bitcoinjs-lib will not offer specific support for problems with
// advanced script usages such as below. Use at your own risk. // advanced script usages such as below. Use at your own risk.
function complexCsvOutput (aQ, bQ, cQ, dQ, sequence1, sequence2) { function complexCsvOutput (aQ, bQ, cQ, dQ, sequence1, sequence2) {
return bitcoin.script.compile([ return bitcoin.script.fromASM(`
/* eslint-disable indent */ OP_IF
bitcoin.opcodes.OP_IF, OP_IF
bitcoin.opcodes.OP_IF, OP_2
bitcoin.opcodes.OP_2, OP_ELSE
bitcoin.opcodes.OP_ELSE, ${bitcoin.script.number.encode(sequence1).toString('hex')}
bitcoin.script.number.encode(sequence1), OP_CHECKSEQUENCEVERIFY
bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, OP_DROP
bitcoin.opcodes.OP_DROP, ${aQ.publicKey.toString('hex')}
aQ.publicKey, OP_CHECKSIGVERIFY
bitcoin.opcodes.OP_CHECKSIGVERIFY, OP_1
bitcoin.opcodes.OP_1, OP_ENDIF
bitcoin.opcodes.OP_ENDIF, ${bQ.publicKey.toString('hex')}
bQ.publicKey, ${cQ.publicKey.toString('hex')}
cQ.publicKey, ${dQ.publicKey.toString('hex')}
dQ.publicKey, OP_3
bitcoin.opcodes.OP_3, OP_CHECKMULTISIG
bitcoin.opcodes.OP_CHECKMULTISIG, OP_ELSE
bitcoin.opcodes.OP_ELSE, ${bitcoin.script.number.encode(sequence2).toString('hex')}
bitcoin.script.number.encode(sequence2), OP_CHECKSEQUENCEVERIFY
bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, OP_DROP
bitcoin.opcodes.OP_DROP, ${aQ.publicKey.toString('hex')}
aQ.publicKey, OP_CHECKSIG
bitcoin.opcodes.OP_CHECKSIG, OP_ENDIF
bitcoin.opcodes.OP_ENDIF `.trim().replace(/\s+/g, ' '))
/* eslint-enable indent */
])
} }
// expiry will pass, {Alice's signature} OP_TRUE // expiry will pass, {Alice's signature} OP_TRUE

Loading…
Cancel
Save