From b68b1d5da4724bb0525e6138f2ed93e0ae0f011e Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 14 Jun 2014 00:30:01 +1000 Subject: [PATCH] Script: fixes pubKeyInput and adds a test --- src/scripts.js | 2 +- test/fixtures/script.json | 9 +++++++++ test/scripts.js | 22 +++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index fca4ba7..fc5d1e1 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -139,7 +139,7 @@ function multisigOutput(m, pubKeys) { function pubKeyInput(signature) { assert(Buffer.isBuffer(signature), 'Expected Buffer, got ' + signature) - return Script.fromChunks(signature) + return Script.fromChunks([signature]) } // {signature} {pubKey} diff --git a/test/fixtures/script.json b/test/fixtures/script.json index bb42dbe..edabed8 100644 --- a/test/fixtures/script.json +++ b/test/fixtures/script.json @@ -33,6 +33,15 @@ "asm": "72 304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f301 65 040cd2d2ce17a1e9b2b3b2cb294d40eecf305a25b7e7bfdafae6bb2639f4ee399b3637706c3d377ec4ab781355add443ae864b134c5e523001c442186ea60f0eb8", "scriptPubKey": false }, + { + "description": "pubKey scriptSig", + "hex": "48304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f301", + "type": "pubkey", + "hash": "44d9982c3e79452e02ef5816976a0e20a0ec1cba", + "signature": "304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f301", + "asm": "72 304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f301", + "scriptPubKey": false + }, { "description": "Valid multisig script", "hex": "5121032487c2a32f7c8d57d2a93906a6457afd00697925b0e6e145d89af6d3bca330162102308673d16987eaa010e540901cc6fe3695e758c19f46ce604e174dac315e685a52ae", diff --git a/test/scripts.js b/test/scripts.js index 36583c0..c100e76 100644 --- a/test/scripts.js +++ b/test/scripts.js @@ -52,12 +52,24 @@ describe('Scripts', function() { // FIXME: bad describe('pay-to-pubkey', function() { - it('matches the test data', function() { - var f = fixtures.valid[0] - var pubKey = ECPubKey.fromHex(f.pubKey) - var script = scripts.pubKeyOutput(pubKey) + describe('input', function() { + it('matches the test data', function() { + var f = fixtures.valid[4] + var signature = new Buffer(f.signature, 'hex') + var script = scripts.pubKeyInput(signature) - assert.equal(script.toHex(), f.hex) + assert.equal(script.toHex(), f.hex) + }) + }) + + describe('output', function() { + it('matches the test data', function() { + var f = fixtures.valid[0] + var pubKey = ECPubKey.fromHex(f.pubKey) + var script = scripts.pubKeyOutput(pubKey) + + assert.equal(script.toHex(), f.hex) + }) }) })