From 39d042d05875df35f214d61355b4f3b60b91ed0e Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 8 May 2014 13:23:31 +1000 Subject: [PATCH 1/6] syncscript: general cleanup --- test/fixtures/syncscript.js | 80 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/test/fixtures/syncscript.js b/test/fixtures/syncscript.js index 5cdf1e6..02c1f6f 100644 --- a/test/fixtures/syncscript.js +++ b/test/fixtures/syncscript.js @@ -8,16 +8,13 @@ var secureRandom = require('secure-random') function b2h(b) { return new Buffer(b).toString('hex') } function h2b(h) { return new Buffer(h, 'hex') } -function randomBuf(s) { - return new Buffer(secureRandom(s)) -} +function randomBuf(s) { return new Buffer(secureRandom(s)) } request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_encode_decode.json', function (error, response, body) { assert.ifError(error) assert.equal(response.statusCode, 200) - var data = JSON.parse(body) - var valid = data.map(function(x) { + var valid = JSON.parse(body).map(function(x) { return { hex: x[0], string: x[1] @@ -31,7 +28,7 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/ // string: ' \t\n\v\f\r skip \r\f\v\n\t ' // }) - var fixtureJSON = JSON.stringify({ + var fixture = JSON.stringify({ valid: valid, invalid: [ { @@ -58,48 +55,43 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/ ] }, null, ' ') - fs.writeFileSync('./test/fixtures/base58.js', 'module.exports = ' + fixtureJSON) + fs.writeFileSync('./test/fixtures/base58.js', 'module.exports = ' + fixture) }) request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_valid.json', function (error, response, body) { - request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_invalid.json', function (error2, response2, body2) { - assert.ifError(error) - assert.ifError(error2) - assert.equal(response.statusCode, 200) - assert.equal(response2.statusCode, 200) - - var validData = JSON.parse(body) - var invalidData = JSON.parse(body2) +request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_invalid.json', function (error2, response2, body2) { + assert.ifError(error) + assert.ifError(error2) + assert.equal(response.statusCode, 200) + assert.equal(response2.statusCode, 200) - var valid = validData.map(function(x) { - var string = x[0] - var hex = x[1] - var params = x[2] + var valid = JSON.parse(body).map(function(x) { + var string = x[0] + var hex = x[1] + var params = x[2] - if (params.isCompressed) { - hex += '01' - } - assert.equal(b2h(base58check.decode(string).payload), hex) + if (params.isCompressed) hex += '01' + assert.equal(b2h(base58check.decode(string).payload), hex) - return { - string: string, - decode: { - version: base58check.decode(string).version, - payload: hex, - checksum: b2h(base58check.decode(string).checksum), - } + return { + string: string, + decode: { + version: base58check.decode(string).version, + payload: hex, + checksum: b2h(base58check.decode(string).checksum), } - }) - var invalid2 = invalidData.map(function(x) { return x[0] }) + } + }) + var invalid2 = JSON.parse(body2).map(function(x) { return x[0] }) - // Our own tests - var hash = crypto.hash160(randomBuf(65)) - var checksum = base58check.decode(base58check.encode(hash)).checksum + // Our own tests + var hash = crypto.hash160(randomBuf(65)) + var checksum = base58check.decode(base58check.encode(hash)).checksum - var fixtureJSON = JSON.stringify({ - valid: valid, - invalid: [ - { + var fixture = JSON.stringify({ + valid: valid, + invalid: [ + { base58check: base58check.encode(hash.slice(0, 18), 0x05), description: 'hash too short' }, @@ -119,10 +111,10 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/ base58check: base58.encode(Buffer.concat([new Buffer([0x05]), hash, randomBuf(4)])), description: 'bad SHA256 checksum', } - ], - invalid2: invalid2 - }, null, ' ') + ], + invalid2: invalid2 + }, null, ' ') - fs.writeFileSync('./test/fixtures/base58check.js', 'module.exports = ' + fixtureJSON) - }) + fs.writeFileSync('./test/fixtures/base58check.js', 'module.exports = ' + fixture) +}) }) From 842b075e75eccd27627bfd127144e00cae1db496 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 14 May 2014 14:38:55 +1000 Subject: [PATCH 2/6] Address: consistent json formatting --- test/fixtures/address.js | 62 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/fixtures/address.js b/test/fixtures/address.js index 7a6becc..d9e351e 100644 --- a/test/fixtures/address.js +++ b/test/fixtures/address.js @@ -1,45 +1,45 @@ module.exports = { - valid: [ + "valid": [ { - description: 'pubKeyHash', - network: 'bitcoin', - version: 0, - hex: '751e76e8199196d454941c45d1b3a323f1433bd6', - base58check: '1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', - script: '76a914751e76e8199196d454941c45d1b3a323f1433bd688ac' + "description": "pubKeyHash", + "network": "bitcoin", + "version": 0, + "hex": "751e76e8199196d454941c45d1b3a323f1433bd6", + "base58check": "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH", + "script": "76a914751e76e8199196d454941c45d1b3a323f1433bd688ac" }, { - description: 'pubKeyHash', - network: 'testnet', - version: 111, - hex: '751e76e8199196d454941c45d1b3a323f1433bd6', - base58check: 'mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r', - script: '76a914751e76e8199196d454941c45d1b3a323f1433bd688ac' + "description": "scriptHash", + "network": "bitcoin", + "version": 5, + "hex": "cd7b44d0b03f2d026d1e586d7ae18903b0d385f6", + "base58check": "3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr", + "script": "a914cd7b44d0b03f2d026d1e586d7ae18903b0d385f687" }, { - description: 'scriptHash', - network: 'bitcoin', - version: 5, - hex: 'cd7b44d0b03f2d026d1e586d7ae18903b0d385f6', - base58check: '3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr', - script: 'a914cd7b44d0b03f2d026d1e586d7ae18903b0d385f687' + "description": "pubKeyHash", + "network": "testnet", + "version": 111, + "hex": "751e76e8199196d454941c45d1b3a323f1433bd6", + "base58check": "mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r", + "script": "76a914751e76e8199196d454941c45d1b3a323f1433bd688ac" }, { - description: 'scriptHash', - network: 'testnet', - version: 196, - hex: 'cd7b44d0b03f2d026d1e586d7ae18903b0d385f6', - base58check: '2NByiBUaEXrhmqAsg7BbLpcQSAQs1EDwt5w', - script: 'a914cd7b44d0b03f2d026d1e586d7ae18903b0d385f687' + "description": "scriptHash", + "network": "testnet", + "version": 196, + "hex": "cd7b44d0b03f2d026d1e586d7ae18903b0d385f6", + "base58check": "2NByiBUaEXrhmqAsg7BbLpcQSAQs1EDwt5w", + "script": "a914cd7b44d0b03f2d026d1e586d7ae18903b0d385f687" } ], - invalid: { - toScriptPubKey: [ + "invalid": { + "toScriptPubKey": [ { - description: 'Unknown Address version', - version: 0x99, - hex: 'cd7b44d0b03f2d026d1e586d7ae18903b0d385f6' + "description": "Unknown Address version", + "version": 153, + "hex": "751e76e8199196d454941c45d1b3a323f1433bd6" } ] } -} +} \ No newline at end of file From 54cc123d319a42c78200675bd7ecc74236a170e1 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 8 May 2014 13:28:20 +1000 Subject: [PATCH 3/6] Address/Script: consistent function ordering --- src/script.js | 14 +++++++------- test/address.js | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/script.js b/src/script.js index e349d48..ae59fc2 100644 --- a/src/script.js +++ b/src/script.js @@ -314,6 +314,13 @@ Script.createPubKeyHashScriptSig = function(signature, pubKey) { return script } +// {serialized scriptPubKey script} +Script.createP2SHScriptSig = function(scriptSig, scriptPubKey) { + var inScript = new Script(scriptSig.buffer) + inScript.writeBytes(scriptPubKey.buffer) + return inScript +} + // OP_0 [signatures ...] Script.createMultisigScriptSig = function(signatures, scriptPubKey) { if (scriptPubKey) { @@ -334,13 +341,6 @@ Script.createMultisigScriptSig = function(signatures, scriptPubKey) { return inScript } -// {serialized scriptPubKey script} -Script.createP2SHScriptSig = function(scriptSig, scriptPubKey) { - var inScript = new Script(scriptSig.buffer) - inScript.writeBytes(scriptPubKey.buffer) - return inScript -} - Script.prototype.clone = function() { return new Script(this.buffer) } diff --git a/test/address.js b/test/address.js index 0ec736f..6475ebb 100644 --- a/test/address.js +++ b/test/address.js @@ -22,14 +22,6 @@ describe('Address', function() { }) describe('fromBase58Check', function() { - it('throws on invalid base58check', function() { - b58fixtures.invalid.forEach(function(f) { - assert.throws(function() { - Address.fromBase58Check(f) - }) - }) - }) - fixtures.valid.forEach(function(f) { it('imports ' + f.description + '(' + f.network + ') correctly', function() { var addr = Address.fromBase58Check(f.base58check) @@ -38,6 +30,14 @@ describe('Address', function() { assert.equal(addr.hash.toString('hex'), f.hex) }) }) + + it('throws on invalid base58check', function() { + b58fixtures.invalid.forEach(function(f) { + assert.throws(function() { + Address.fromBase58Check(f) + }) + }) + }) }) describe('fromScriptPubKey', function() { From 55681e7e5d94ca435a9663d7fb59d6b5efbae0a2 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 8 May 2014 13:55:57 +1000 Subject: [PATCH 4/6] Script: use PubKey objects not prebuilt Buffers --- src/script.js | 13 ++++++++----- test/integration/p2sh.js | 5 +---- test/script.js | 5 +++-- test/transaction.js | 3 +-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/script.js b/src/script.js index ae59fc2..2e47f7c 100644 --- a/src/script.js +++ b/src/script.js @@ -295,12 +295,15 @@ Script.createP2SHScriptPubKey = function(hash) { // m [pubKeys ...] n OP_CHECKMULTISIG Script.createMultisigScriptPubKey = function(m, pubKeys) { var script = new Script() + var n = pubKeys.length - script.writeOp(opcodes.OP_1 + m - 1) - for (var i = 0; i < pubKeys.length; ++i) { - script.writeBytes(pubKeys[i]) - } - script.writeOp(opcodes.OP_1 + pubKeys.length - 1) + script.writeOp((opcodes.OP_1 - 1) + m) + + pubKeys.forEach(function(pubKey) { + script.writeBytes(pubKey.toBuffer()) + }) + + script.writeOp((opcodes.OP_1 - 1) + n) script.writeOp(opcodes.OP_CHECKMULTISIG) return script diff --git a/test/integration/p2sh.js b/test/integration/p2sh.js index 72c3f75..0fef5f8 100644 --- a/test/integration/p2sh.js +++ b/test/integration/p2sh.js @@ -27,10 +27,7 @@ describe('p2sh', function() { var pubKeys = privKeys.map(function(eck) { return eck.pub }) - var pubKeyBuffers = pubKeys.map(function(q) { - return q.toBuffer() - }) - var redeemScript = Script.createMultisigScriptPubKey(2, pubKeyBuffers) + var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys) var hash160 = crypto.hash160(redeemScript.buffer) var multisigAddress = new Address(hash160, networks.testnet.scriptHash) diff --git a/test/script.js b/test/script.js index 36f0e6c..595a130 100644 --- a/test/script.js +++ b/test/script.js @@ -3,6 +3,7 @@ var crypto = require('../src/crypto') var networks = require('../src/networks') var Address = require('../src/address') +var ECPubKey = require('../src/ecpubkey') var Script = require('../src/script') var fixtures = require('./fixtures/script') @@ -95,7 +96,7 @@ describe('Script', function() { '02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f', '02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f', '036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19' - ].map(h2b) + ].map(ECPubKey.fromHex) }) it('should create valid redeemScript', function() { @@ -112,7 +113,7 @@ describe('Script', function() { var pubKeys = [ '02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1', '0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a' - ].map(h2b) + ].map(ECPubKey.fromHex) var signatures = [ '304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801', '3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501' diff --git a/test/transaction.js b/test/transaction.js index 5c2fcbd..0b3b0db 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -255,8 +255,7 @@ describe('Transaction', function() { return ECKey.fromWIF(wif) }) var pubKeys = privKeys.map(function(eck) { return eck.pub }) - var pubKeyBuffers = pubKeys.map(function(q) { return q.toBuffer() }) - var redeemScript = Script.createMultisigScriptPubKey(2, pubKeyBuffers) + var redeemScript = Script.createMultisigScriptPubKey(2, pubKeys) var signatures = privKeys.map(function(privKey) { return tx.signScriptSig(0, redeemScript, privKey) From e033a872c9c6f99113466440ebc3fb793a29ce5e Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sun, 4 May 2014 15:03:24 +1000 Subject: [PATCH 5/6] Transaction: rename hashTransactionForSignature to hashForSignature --- src/transaction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index b21f851..0b336cf 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -204,7 +204,7 @@ var SIGHASH_ANYONECANPAY = 80 * hashType, serializes and finally hashes the result. This hash can then be * used to sign the transaction input in question. */ -Transaction.prototype.hashTransactionForSignature = +Transaction.prototype.hashForSignature = function (connectedScript, inIndex, hashType) { var txTmp = this.clone() @@ -377,7 +377,7 @@ Transaction.prototype.signScriptSig = function(index, script, key, type) { assert(key instanceof ECKey, 'Invalid private key') // assert.equal(type & 0x7F, type, 'Invalid type') // TODO - var hash = this.hashTransactionForSignature(script, index, type) + var hash = this.hashForSignature(script, index, type) return key.sign(hash).concat([type]) } @@ -387,7 +387,7 @@ Transaction.prototype.setScriptSig = function(index, script) { Transaction.prototype.validateSig = function(index, script, pub, sig, type) { type = type || SIGHASH_ALL - var hash = this.hashTransactionForSignature(script, index, type) + var hash = this.hashForSignature(script, index, type) return pub.verify(hash, sig) } From 0468c4710cfadb65681448b9ad993b1b72e3a5e4 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 8 May 2014 10:44:35 +1000 Subject: [PATCH 6/6] Transaction: rename (de)serialize to [to/from]Buffer --- src/transaction.js | 27 +++++++++++---------------- test/integration/p2sh.js | 2 +- test/transaction.js | 24 ++++++++++++------------ test/wallet.js | 4 ++-- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 0b336cf..2b50940 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -20,7 +20,7 @@ function Transaction(doc) { if (doc) { if (typeof doc == "string" || Array.isArray(doc)) { - doc = Transaction.deserialize(doc) + doc = Transaction.fromBuffer(doc) } if (doc.hash) this.hash = doc.hash; @@ -114,13 +114,7 @@ Transaction.prototype.addOutput = function (address, value) { })) } -/** - * Serialize this transaction. - * - * Returns the transaction as a binary buffer in - * accordance with the Bitcoin protocol. - */ -Transaction.prototype.serialize = function () { +Transaction.prototype.toBuffer = function () { var txInSize = this.ins.reduce(function(a, x) { return a + (40 + bufferutils.varIntSize(x.script.buffer.length) + x.script.buffer.length) }, 0) @@ -185,8 +179,8 @@ Transaction.prototype.serialize = function () { return buffer } -Transaction.prototype.serializeHex = function() { - return this.serialize().toString('hex') +Transaction.prototype.toHex = function() { + return this.toBuffer().toString('hex') } //var OP_CODESEPARATOR = 171 @@ -246,12 +240,12 @@ Transaction.prototype.hashForSignature = var htB = new Buffer(4) htB.writeUInt32LE(hashType, 0) - var buffer = Buffer.concat([txTmp.serialize(), htB]) + var buffer = Buffer.concat([txTmp.toBuffer(), htB]) return crypto.hash256(buffer) } Transaction.prototype.getHash = function () { - var buffer = crypto.hash256(this.serialize()) + var buffer = crypto.hash256(this.toBuffer()) // Big-endian is used for TxHash Array.prototype.reverse.call(buffer) @@ -276,10 +270,7 @@ Transaction.prototype.clone = function () return newTx } -Transaction.deserialize = function(buffer) { - if (typeof buffer == "string") buffer = new Buffer(buffer, 'hex') - else if (Array.isArray(buffer)) buffer = new Buffer(buffer) - +Transaction.fromBuffer = function(buffer) { // Copy because we mutate (reverse TxOutHashs) buffer = new Buffer(buffer) @@ -355,6 +346,10 @@ Transaction.deserialize = function(buffer) { }) } +Transaction.fromHex = function(hex) { + return Transaction.fromBuffer(new Buffer(hex, 'hex')) +} + /** * Signs a standard output at some index with the given key */ diff --git a/test/integration/p2sh.js b/test/integration/p2sh.js index 0fef5f8..474dd9a 100644 --- a/test/integration/p2sh.js +++ b/test/integration/p2sh.js @@ -59,7 +59,7 @@ describe('p2sh', function() { tx.setScriptSig(0, scriptSig) // Send from mutlsigAddress to targetAddress - helloblock.transactions.propagate(tx.serializeHex(), function(err, resp, resource) { + helloblock.transactions.propagate(tx.toHex(), function(err, resp, resource) { // no err means that transaction has been successfully propagated if (err) done(err); diff --git a/test/transaction.js b/test/transaction.js index 0b3b0db..9f33cc4 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -26,11 +26,11 @@ describe('Transaction', function() { '3901ffffffff0100f2052a010000001976a914dd40dedd8f7e3746662', '4c4dacc6362d8e7be23dd88ac00000000' ].join('') - tx = Transaction.deserialize(serializedTx) + tx = Transaction.fromHex(serializedTx) }) it('returns the original after serialized again', function() { - var actual = tx.serialize() + var actual = tx.toBuffer() var expected = serializedTx assert.equal(b2h(actual), expected) @@ -38,7 +38,7 @@ describe('Transaction', function() { it('does not mutate the input buffer', function() { var buffer = new Buffer(serializedTx, 'hex') - Transaction.deserialize(buffer) + Transaction.fromBuffer(buffer) assert.equal(buffer.toString('hex'), serializedTx) }) @@ -84,7 +84,7 @@ describe('Transaction', function() { tx.addInput("0cb859105100ebc3344f749c835c7af7d7103ec0d8cbc3d8ccbd5d28c3c36b57", 0) tx.addOutput("15mMHKL96tWAUtqF3tbVf99Z8arcmnJrr3", 100) - var buffer = tx.serialize() + var buffer = tx.toBuffer() // we're going to replace the 8bit VarInt for tx.ins.length with a stretched 32bit equivalent var mutated = Buffer.concat([ @@ -94,7 +94,7 @@ describe('Transaction', function() { ]) // the deserialized-serialized transaction should return to its non-mutated state (== tx) - var buffer2 = Transaction.deserialize(mutated).serialize() + var buffer2 = Transaction.fromBuffer(mutated).toBuffer() assert.deepEqual(buffer, buffer2) }) }) @@ -102,7 +102,7 @@ describe('Transaction', function() { describe('creating a transaction', function() { var tx, prevTx beforeEach(function() { - prevTx = Transaction.deserialize(fixtureTx1Hex) + prevTx = Transaction.fromHex(fixtureTx1Hex) tx = new Transaction() }) @@ -207,7 +207,7 @@ describe('Transaction', function() { var validTx beforeEach(function() { - validTx = Transaction.deserialize(fixtureTx2Hex) + validTx = Transaction.fromHex(fixtureTx2Hex) }) it('returns true for valid signature', function(){ @@ -221,22 +221,22 @@ describe('Transaction', function() { describe('estimateFee', function(){ it('works for fixture tx 1', function(){ - var tx = Transaction.deserialize(fixtureTx1Hex) + var tx = Transaction.fromHex(fixtureTx1Hex) assert.equal(tx.estimateFee(), 20000) }) it('works for fixture big tx', function(){ - var tx = Transaction.deserialize(fixtureTxBigHex) + var tx = Transaction.fromHex(fixtureTxBigHex) assert.equal(tx.estimateFee(), 60000) }) it('allow feePerKb to be passed in as an argument', function(){ - var tx = Transaction.deserialize(fixtureTx2Hex) + var tx = Transaction.fromHex(fixtureTx2Hex) assert.equal(tx.estimateFee(10000), 10000) }) it('allow feePerKb to be set to 0', function(){ - var tx = Transaction.deserialize(fixtureTx2Hex) + var tx = Transaction.fromHex(fixtureTx2Hex) assert.equal(tx.estimateFee(0), 0) }) }) @@ -270,7 +270,7 @@ describe('Transaction', function() { }) var expected = '010000000189632848f99722915727c5c75da8db2dbf194342a0429828f66ff88fab2af7d600000000fd1b0100483045022100e5be20d440b2bbbc886161f9095fa6d0bca749a4e41d30064f30eb97adc7a1f5022061af132890d8e4e90fedff5e9365aeeb77021afd8ef1d5c114d575512e9a130a0147304402205054e38e9d7b5c10481b6b4991fde5704cd94d49e344406e3c2ce4d18a43bf8e022051d7ba8479865b53a48bee0cce86e89a25633af5b2918aa276859489e232f51c014c8752410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a52aeffffffff0101000000000000001976a914751e76e8199196d454941c45d1b3a323f1433bd688ac00000000' - assert.equal(tx.serializeHex(), expected) + assert.equal(tx.toHex(), expected) }) }) }) diff --git a/test/wallet.js b/test/wallet.js index 276ef0f..d1afdd3 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -318,7 +318,7 @@ describe('Wallet', function() { '1BBjuhF2jHxu7tPinyQGCuaNhEs6f5u59u' ] - tx = Transaction.deserialize(fixtureTx1Hex) + tx = Transaction.fromHex(fixtureTx1Hex) }) describe("when tx outs contains an address owned by the wallet, an 'output' gets added to wallet.outputs", function(){ @@ -363,7 +363,7 @@ describe('Wallet', function() { wallet.addresses = [addresses[0]] // the address fixtureTx2 used as input wallet.processTx(tx) - tx = Transaction.deserialize(fixtureTx2Hex) + tx = Transaction.fromHex(fixtureTx2Hex) }) it("does not add to wallet.outputs", function(){