payments: prepare tests for null data
This commit is contained in:
parent
7104bb412e
commit
8aa4c8fdd4
2 changed files with 14 additions and 9 deletions
|
@ -9,14 +9,15 @@ const u = require('./payments.utils')
|
|||
const fixtures = require('./fixtures/' + p)
|
||||
|
||||
fixtures.valid.forEach(function (f, i) {
|
||||
const args = u.preform(f.arguments)
|
||||
|
||||
it(f.description + ' as expected', function () {
|
||||
const args = u.preform(f.arguments)
|
||||
const actual = fn(args, f.options)
|
||||
|
||||
u.equate(actual, f.expected, f.arguments)
|
||||
})
|
||||
|
||||
it(f.description + ' as expected (no validation)', function () {
|
||||
const args = u.preform(f.arguments)
|
||||
const actual = fn(args, Object.assign({}, f.options, {
|
||||
validate: false
|
||||
}))
|
||||
|
|
|
@ -7,6 +7,12 @@ function tryHex (x) {
|
|||
if (Array.isArray(x)) return x.map(tryHex)
|
||||
return x
|
||||
}
|
||||
|
||||
function fromHex (x) {
|
||||
if (typeof x === 'string') return Buffer.from(x, 'hex')
|
||||
if (Array.isArray(x)) return x.map(fromHex)
|
||||
return x
|
||||
}
|
||||
function tryASM (x) {
|
||||
if (Buffer.isBuffer(x)) return bscript.toASM(x)
|
||||
return x
|
||||
|
@ -64,6 +70,7 @@ function equate (a, b, args) {
|
|||
if ('n' in b) t.strictEqual(a.n, b.n, 'Inequal *.n')
|
||||
if ('pubkeys' in b) t.deepEqual(tryHex(a.pubkeys), tryHex(b.pubkeys), 'Inequal *.pubkeys')
|
||||
if ('signatures' in b) t.deepEqual(tryHex(a.signatures), tryHex(b.signatures), 'Inequal *.signatures')
|
||||
if ('data' in b) t.deepEqual(tryHex(a.data), tryHex(b.data), 'Inequal *.data')
|
||||
}
|
||||
|
||||
function preform (x) {
|
||||
|
@ -80,21 +87,18 @@ function preform (x) {
|
|||
}
|
||||
if (typeof x.output === 'string') x.output = asmToBuffer(x.output)
|
||||
if (typeof x.input === 'string') x.input = asmToBuffer(x.input)
|
||||
if (Array.isArray(x.witness)) {
|
||||
x.witness = x.witness.map(function (y) {
|
||||
return Buffer.from(y, 'hex')
|
||||
})
|
||||
}
|
||||
if (Array.isArray(x.witness)) x.witness = x.witness.map(fromHex)
|
||||
|
||||
if (x.data) x.data = x.data.map(fromHex)
|
||||
if (x.hash) x.hash = Buffer.from(x.hash, 'hex')
|
||||
if (x.pubkey) x.pubkey = Buffer.from(x.pubkey, 'hex')
|
||||
if (x.signature) x.signature = Buffer.from(x.signature, 'hex')
|
||||
if (x.pubkeys) x.pubkeys = x.pubkeys.map(function (y) { return Buffer.from(y, 'hex') })
|
||||
if (x.pubkeys) x.pubkeys = x.pubkeys.map(fromHex)
|
||||
if (x.signatures) x.signatures = x.signatures.map(function (y) { return Number.isFinite(y) ? y : Buffer.from(y, 'hex') })
|
||||
if (x.redeem) {
|
||||
if (typeof x.redeem.input === 'string') x.redeem.input = asmToBuffer(x.redeem.input)
|
||||
if (typeof x.redeem.output === 'string') x.redeem.output = asmToBuffer(x.redeem.output)
|
||||
if (Array.isArray(x.redeem.witness)) x.redeem.witness = x.redeem.witness.map(function (y) { return Buffer.from(y, 'hex') })
|
||||
if (Array.isArray(x.redeem.witness)) x.redeem.witness = x.redeem.witness.map(fromHex)
|
||||
x.redeem.network = bnetworks[x.redeem.network] || x.network || bnetworks.bitcoin
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue