use standardjs formatting
This commit is contained in:
parent
09d8e440de
commit
399803affa
41 changed files with 1252 additions and 1177 deletions
test
120
test/scripts.js
120
test/scripts.js
|
@ -1,3 +1,5 @@
|
|||
/* global describe, it */
|
||||
|
||||
var assert = require('assert')
|
||||
var ops = require('../src/opcodes')
|
||||
var scripts = require('../src/scripts')
|
||||
|
@ -7,16 +9,16 @@ var Script = require('../src/script')
|
|||
|
||||
var fixtures = require('./fixtures/scripts.json')
|
||||
|
||||
describe('Scripts', function() {
|
||||
describe('Scripts', function () {
|
||||
// TODO
|
||||
describe.skip('isCanonicalPubKey', function() {})
|
||||
describe.skip('isCanonicalSignature', function() {})
|
||||
describe.skip('isCanonicalPubKey', function () {})
|
||||
describe.skip('isCanonicalSignature', function () {})
|
||||
|
||||
describe('classifyInput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('classifyInput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (!f.scriptSig) return
|
||||
|
||||
it('classifies ' + f.scriptSig + ' as ' + f.type, function() {
|
||||
it('classifies ' + f.scriptSig + ' as ' + f.type, function () {
|
||||
var script = Script.fromASM(f.scriptSig)
|
||||
var type = scripts.classifyInput(script)
|
||||
|
||||
|
@ -24,11 +26,11 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
fixtures.valid.forEach(function(f) {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (!f.scriptSig) return
|
||||
if (!f.typeIncomplete) return
|
||||
|
||||
it('classifies incomplete ' + f.scriptSig + ' as ' + f.typeIncomplete, function() {
|
||||
it('classifies incomplete ' + f.scriptSig + ' as ' + f.typeIncomplete, function () {
|
||||
var script = Script.fromASM(f.scriptSig)
|
||||
var type = scripts.classifyInput(script, true)
|
||||
|
||||
|
@ -37,11 +39,11 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('classifyOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('classifyOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (!f.scriptPubKey) return
|
||||
|
||||
it('classifies ' + f.scriptPubKey + ' as ' + f.type, function() {
|
||||
it('classifies ' + f.scriptPubKey + ' as ' + f.type, function () {
|
||||
var script = Script.fromASM(f.scriptPubKey)
|
||||
var type = scripts.classifyOutput(script)
|
||||
|
||||
|
@ -50,19 +52,19 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
;['PubKey', 'PubKeyHash', 'ScriptHash', 'Multisig', 'NullData'].forEach(function(type) {
|
||||
;['PubKey', 'PubKeyHash', 'ScriptHash', 'Multisig', 'NullData'].forEach(function (type) {
|
||||
var inputFnName = 'is' + type + 'Input'
|
||||
var outputFnName = 'is' + type + 'Output'
|
||||
|
||||
var inputFn = scripts[inputFnName]
|
||||
var outputFn= scripts[outputFnName]
|
||||
var outputFn = scripts[outputFnName]
|
||||
|
||||
describe('is' + type + 'Input', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('is' + type + 'Input', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
var expected = type.toLowerCase() === f.type
|
||||
|
||||
if (inputFn && f.scriptSig) {
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function() {
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function () {
|
||||
var script = Script.fromASM(f.scriptSig)
|
||||
|
||||
assert.equal(inputFn(script), expected)
|
||||
|
@ -71,7 +73,7 @@ describe('Scripts', function() {
|
|||
if (f.typeIncomplete) {
|
||||
var expectedIncomplete = type.toLowerCase() === f.typeIncomplete
|
||||
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function() {
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function () {
|
||||
var script = Script.fromASM(f.scriptSig)
|
||||
|
||||
assert.equal(inputFn(script, true), expectedIncomplete)
|
||||
|
@ -82,9 +84,9 @@ describe('Scripts', function() {
|
|||
|
||||
if (!(inputFnName in fixtures.invalid)) return
|
||||
|
||||
fixtures.invalid[inputFnName].forEach(function(f) {
|
||||
fixtures.invalid[inputFnName].forEach(function (f) {
|
||||
if (inputFn && f.scriptSig) {
|
||||
it('returns false for ' + f.scriptSig, function() {
|
||||
it('returns false for ' + f.scriptSig, function () {
|
||||
var script = Script.fromASM(f.scriptSig)
|
||||
|
||||
assert.equal(inputFn(script), false)
|
||||
|
@ -93,12 +95,12 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('is' + type + 'Output', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('is' + type + 'Output', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
var expected = type.toLowerCase() === f.type
|
||||
|
||||
if (outputFn && f.scriptPubKey) {
|
||||
it('returns ' + expected + ' for ' + f.scriptPubKey, function() {
|
||||
it('returns ' + expected + ' for ' + f.scriptPubKey, function () {
|
||||
var script = Script.fromASM(f.scriptPubKey)
|
||||
|
||||
assert.equal(outputFn(script), expected)
|
||||
|
@ -108,9 +110,9 @@ describe('Scripts', function() {
|
|||
|
||||
if (!(outputFnName in fixtures.invalid)) return
|
||||
|
||||
fixtures.invalid[outputFnName].forEach(function(f) {
|
||||
fixtures.invalid[outputFnName].forEach(function (f) {
|
||||
if (outputFn && f.scriptPubKey) {
|
||||
it('returns false for ' + f.scriptPubKey, function() {
|
||||
it('returns false for ' + f.scriptPubKey, function () {
|
||||
var script = Script.fromASM(f.scriptPubKey)
|
||||
|
||||
assert.equal(outputFn(script), false)
|
||||
|
@ -120,11 +122,11 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('pubKeyInput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('pubKeyInput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
it('returns ' + f.scriptSig, function() {
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
|
||||
var scriptSig = scripts.pubKeyInput(signature)
|
||||
|
@ -133,11 +135,11 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('pubKeyOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('pubKeyOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
it('returns ' + f.scriptPubKey, function() {
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var pubKey = ECPubKey.fromHex(f.pubKey)
|
||||
|
||||
var scriptPubKey = scripts.pubKeyOutput(pubKey)
|
||||
|
@ -146,13 +148,13 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('pubKeyHashInput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('pubKeyHashInput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
var pubKey = ECPubKey.fromHex(f.pubKey)
|
||||
|
||||
it('returns ' + f.scriptSig, function() {
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
|
||||
var scriptSig = scripts.pubKeyHashInput(signature, pubKey)
|
||||
|
@ -161,26 +163,26 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('pubKeyHashOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('pubKeyHashOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
var pubKey = ECPubKey.fromHex(f.pubKey)
|
||||
var address = pubKey.getAddress()
|
||||
|
||||
it('returns ' + f.scriptPubKey, function() {
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var scriptPubKey = scripts.pubKeyHashOutput(address.hash)
|
||||
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('multisigInput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('multisigInput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'multisig') return
|
||||
|
||||
it('returns ' + f.scriptSig, function() {
|
||||
var signatures = f.signatures.map(function(signature) {
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var signatures = f.signatures.map(function (signature) {
|
||||
return signature ? new Buffer(signature, 'hex') : ops.OP_0
|
||||
})
|
||||
|
||||
|
@ -189,53 +191,53 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.multisigInput.forEach(function(f) {
|
||||
fixtures.invalid.multisigInput.forEach(function (f) {
|
||||
var pubKeys = f.pubKeys.map(ECPubKey.fromHex)
|
||||
var scriptPubKey = scripts.multisigOutput(pubKeys.length, pubKeys)
|
||||
|
||||
it('throws on ' + f.exception, function() {
|
||||
var signatures = f.signatures.map(function(signature) {
|
||||
it('throws on ' + f.exception, function () {
|
||||
var signatures = f.signatures.map(function (signature) {
|
||||
return signature ? new Buffer(signature, 'hex') : ops.OP_0
|
||||
})
|
||||
|
||||
assert.throws(function() {
|
||||
assert.throws(function () {
|
||||
scripts.multisigInput(signatures, scriptPubKey)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('multisigOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('multisigOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'multisig') return
|
||||
|
||||
var pubKeys = f.pubKeys.map(ECPubKey.fromHex)
|
||||
var scriptPubKey = scripts.multisigOutput(pubKeys.length, pubKeys)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function() {
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.multisigOutput.forEach(function(f) {
|
||||
fixtures.invalid.multisigOutput.forEach(function (f) {
|
||||
var pubKeys = f.pubKeys.map(ECPubKey.fromHex)
|
||||
|
||||
it('throws on ' + f.exception, function() {
|
||||
assert.throws(function() {
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
scripts.multisigOutput(f.m, pubKeys)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('scriptHashInput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('scriptHashInput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'scripthash') return
|
||||
|
||||
var redeemScript = Script.fromASM(f.redeemScript)
|
||||
var redeemScriptSig = Script.fromASM(f.redeemScriptSig)
|
||||
|
||||
it('returns ' + f.scriptSig, function() {
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var scriptSig = scripts.scriptHashInput(redeemScriptSig, redeemScript)
|
||||
|
||||
assert.equal(scriptSig.toASM(), f.scriptSig)
|
||||
|
@ -243,13 +245,13 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('scriptHashOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('scriptHashOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'scripthash') return
|
||||
|
||||
var redeemScript = Script.fromASM(f.redeemScript)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function() {
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var scriptPubKey = scripts.scriptHashOutput(redeemScript.getHash())
|
||||
|
||||
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
|
||||
|
@ -257,14 +259,14 @@ describe('Scripts', function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe('nullDataOutput', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
describe('nullDataOutput', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'nulldata') return
|
||||
|
||||
var data = new Buffer(f.data, 'hex')
|
||||
var scriptPubKey = scripts.nullDataOutput(data)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function() {
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
assert.equal(scriptPubKey.toASM(), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue