2018-07-23 09:45:01 +02:00
|
|
|
const { describe, it } = require('mocha')
|
2018-06-05 09:24:47 +02:00
|
|
|
const assert = require('assert')
|
|
|
|
const u = require('./payments.utils')
|
|
|
|
|
2018-07-11 09:27:44 +02:00
|
|
|
;['embed', 'p2ms', 'p2pk', 'p2pkh', 'p2sh', 'p2wpkh', 'p2wsh'].forEach(function (p) {
|
2018-06-05 09:24:47 +02:00
|
|
|
describe(p, function () {
|
|
|
|
const fn = require('../src/payments/' + p)
|
|
|
|
const fixtures = require('./fixtures/' + p)
|
|
|
|
|
|
|
|
fixtures.valid.forEach(function (f, i) {
|
|
|
|
it(f.description + ' as expected', function () {
|
2018-07-03 14:33:04 +02:00
|
|
|
const args = u.preform(f.arguments)
|
2018-06-05 09:24:47 +02:00
|
|
|
const actual = fn(args, f.options)
|
2018-07-03 14:33:04 +02:00
|
|
|
|
2018-06-05 09:24:47 +02:00
|
|
|
u.equate(actual, f.expected, f.arguments)
|
|
|
|
})
|
|
|
|
|
|
|
|
it(f.description + ' as expected (no validation)', function () {
|
2018-07-03 14:33:04 +02:00
|
|
|
const args = u.preform(f.arguments)
|
2018-06-05 09:24:47 +02:00
|
|
|
const actual = fn(args, Object.assign({}, f.options, {
|
|
|
|
validate: false
|
|
|
|
}))
|
|
|
|
|
|
|
|
u.equate(actual, f.expected, f.arguments)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
fixtures.invalid.forEach(function (f) {
|
2018-06-05 16:09:55 +02:00
|
|
|
it('throws ' + f.exception + (f.description ? ('for ' + f.description) : ''), function () {
|
2018-06-05 09:24:47 +02:00
|
|
|
const args = u.preform(f.arguments)
|
|
|
|
|
|
|
|
assert.throws(function () {
|
|
|
|
fn(args, f.options)
|
|
|
|
}, new RegExp(f.exception))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// cross-verify dynamically too
|
|
|
|
if (!fixtures.dynamic) return
|
|
|
|
const { depends, details } = fixtures.dynamic
|
|
|
|
|
|
|
|
details.forEach(function (f) {
|
|
|
|
const detail = u.preform(f)
|
|
|
|
const disabled = {}
|
|
|
|
if (f.disabled) f.disabled.forEach(function (k) { disabled[k] = true })
|
|
|
|
|
|
|
|
for (let key in depends) {
|
|
|
|
if (key in disabled) continue
|
|
|
|
const dependencies = depends[key]
|
|
|
|
|
|
|
|
dependencies.forEach(function (dependency) {
|
|
|
|
if (!Array.isArray(dependency)) dependency = [dependency]
|
|
|
|
|
|
|
|
const args = {}
|
|
|
|
dependency.forEach(function (d) { u.from(d, detail, args) })
|
|
|
|
const expected = u.from(key, detail)
|
|
|
|
|
|
|
|
it(f.description + ', ' + key + ' derives from ' + JSON.stringify(dependency), function () {
|
|
|
|
u.equate(fn(args), expected)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|