From 2392ce0a4905512e019f8334b2ad296aeca66cd8 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 28 Apr 2015 11:49:01 +1000 Subject: [PATCH 1/3] tests: verify bitcoin core ASM --- test/bitcoin.core.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/bitcoin.core.js b/test/bitcoin.core.js index 6511368..f09072a 100644 --- a/test/bitcoin.core.js +++ b/test/bitcoin.core.js @@ -166,7 +166,6 @@ describe('Bitcoin-core', function () { // reverse because test data is big-endian var prevOutHash = bufferutils.reverse(new Buffer(input[0], 'hex')) var prevOutIndex = input[1] - // var prevOutScriptPubKey = input[2] // TODO: we don't have a ASM parser assert.deepEqual(txIn.hash, prevOutHash) @@ -177,6 +176,37 @@ describe('Bitcoin-core', function () { }) }) + describe('Script', function () { + tx_valid.forEach(function (f) { + // Objects that are only a single string are ignored + if (f.length === 1) return + + var inputs = f[0] + + inputs.forEach(function (input) { + var prevOutScriptPubKey = input[2] + .replace(/(^| )1( |$)/g, 'OP_1 ').replace(/(^| )2( |$)/g, 'OP_2 ').replace(/(^| )3( |$)/g, 'OP_3 ') + .replace(/(^| )4( |$)/g, 'OP_4 ').replace(/(^| )5( |$)/g, 'OP_5 ').replace(/(^| )6( |$)/g, 'OP_6 ') + .replace(/(^| )7( |$)/g, 'OP_7 ').replace(/(^| )8( |$)/g, 'OP_8 ').replace(/(^| )9( |$)/g, 'OP_9 ') + .replace(/0x[a-f0-9]+ 0x([a-f0-9]+)/, '$1') + .replace(/DUP/g, 'OP_DUP') + .replace(/NOT/g, 'OP_NOT') + .replace(/HASH160/g, 'OP_HASH160') + .replace(/EQUALVERIFY/g, 'OP_EQUALVERIFY') + .replace(/EQUAL( |$)/g, 'OP_EQUAL ') + .replace(/CHECKSIG/g, 'OP_CHECKSIG') + .replace(/ CHECKMULTISIG/g, ' OP_CHECKMULTISIG') + .replace(/CODESEPARATOR/g, 'OP_CODESEPARATOR') + .replace(/CHECKSIGVERIFY/g, 'OP_CHECKSIGVERIFY') + + it('can decode ' + prevOutScriptPubKey, function () { + // TODO: we can probably do better validation than this + Script.fromASM(prevOutScriptPubKey) + }) + }) + }) + }) + // sighash describe('Transaction', function () { sighash.forEach(function (f) { From df2bd1903325cf3c4f9e2f92e2cd16b94f30427f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 8 Jul 2015 12:33:36 +1000 Subject: [PATCH 2/3] tests: simplify OP_* regex --- test/bitcoin.core.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/bitcoin.core.js b/test/bitcoin.core.js index f09072a..5c3da90 100644 --- a/test/bitcoin.core.js +++ b/test/bitcoin.core.js @@ -185,9 +185,7 @@ describe('Bitcoin-core', function () { inputs.forEach(function (input) { var prevOutScriptPubKey = input[2] - .replace(/(^| )1( |$)/g, 'OP_1 ').replace(/(^| )2( |$)/g, 'OP_2 ').replace(/(^| )3( |$)/g, 'OP_3 ') - .replace(/(^| )4( |$)/g, 'OP_4 ').replace(/(^| )5( |$)/g, 'OP_5 ').replace(/(^| )6( |$)/g, 'OP_6 ') - .replace(/(^| )7( |$)/g, 'OP_7 ').replace(/(^| )8( |$)/g, 'OP_8 ').replace(/(^| )9( |$)/g, 'OP_9 ') + .replace(/(^| )([0-9])( |$)/g, 'OP_$2 ') .replace(/0x[a-f0-9]+ 0x([a-f0-9]+)/, '$1') .replace(/DUP/g, 'OP_DUP') .replace(/NOT/g, 'OP_NOT') From 1209d5960a7254cb4b00cf250bc0183e34f4ff2c Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 8 Jul 2015 12:33:48 +1000 Subject: [PATCH 3/3] tests: better test descriptions --- test/bitcoin.core.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/bitcoin.core.js b/test/bitcoin.core.js index 5c3da90..a2d5b52 100644 --- a/test/bitcoin.core.js +++ b/test/bitcoin.core.js @@ -47,7 +47,7 @@ describe('Bitcoin-core', function () { }) // base58_keys_valid - describe('Address', function () { + describe('Address.formBase58Check', function () { var typeMap = { 'pubkey': 'pubKeyHash', 'script': 'scriptHash' @@ -74,7 +74,7 @@ describe('Bitcoin-core', function () { }) // base58_keys_invalid - describe('Address', function () { + describe('Address.fromBase58Check', function () { var allowedNetworks = [ networks.bitcoin.pubkeyhash, networks.bitcoin.scripthash, @@ -105,19 +105,19 @@ describe('Bitcoin-core', function () { if (!params.isPrivkey) return var keyPair = ECPair.fromWIF(string) - it('imports ' + string, function () { + it('fromWIF imports ' + string, function () { assert.strictEqual(keyPair.d.toHex(), hex) assert.strictEqual(keyPair.compressed, params.isCompressed) }) - it('exports ' + hex + ' to ' + string, function () { + it('toWIF exports ' + hex + ' to ' + string, function () { assert.strictEqual(keyPair.toWIF(), string) }) }) }) // base58_keys_invalid - describe('ECPair', function () { + describe('ECPair.fromWIF', function () { var allowedNetworks = [ networks.bitcoin, networks.testnet @@ -136,9 +136,9 @@ describe('Bitcoin-core', function () { }) }) - describe('Block', function () { + describe('Block.fromHex', function () { blocks_valid.forEach(function (f) { - it('fromHex can parse ' + f.id, function () { + it('can parse ' + f.id, function () { var block = Block.fromHex(f.hex) assert.strictEqual(block.getId(), f.id) @@ -148,7 +148,7 @@ describe('Bitcoin-core', function () { }) // tx_valid - describe('Transaction', function () { + describe('Transaction.fromHex', function () { tx_valid.forEach(function (f) { // Objects that are only a single string are ignored if (f.length === 1) return @@ -176,7 +176,7 @@ describe('Bitcoin-core', function () { }) }) - describe('Script', function () { + describe('Script.fromASM', function () { tx_valid.forEach(function (f) { // Objects that are only a single string are ignored if (f.length === 1) return @@ -197,7 +197,7 @@ describe('Bitcoin-core', function () { .replace(/CODESEPARATOR/g, 'OP_CODESEPARATOR') .replace(/CHECKSIGVERIFY/g, 'OP_CHECKSIGVERIFY') - it('can decode ' + prevOutScriptPubKey, function () { + it('can parse ' + prevOutScriptPubKey, function () { // TODO: we can probably do better validation than this Script.fromASM(prevOutScriptPubKey) }) @@ -240,7 +240,7 @@ describe('Bitcoin-core', function () { }) }) - describe('ECSignature', function () { + describe('ECSignature.parseScriptSignature', function () { sig_canonical.forEach(function (hex) { var buffer = new Buffer(hex, 'hex')