From 919bed87307e00ed52d4d8656befecfae308d7b6 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Fri, 8 Dec 2017 19:24:17 +0300 Subject: [PATCH 1/2] Fix Transaction().fromObject() --- lib/transaction/transaction.js | 2 +- test/transaction/transaction.js | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 947af4336..39463eedd 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -349,7 +349,7 @@ Transaction.prototype.fromObject = function fromObject(arg) { var self = this; var transaction; if (arg instanceof Transaction) { - transaction = transaction.toObject(); + transaction = arg.toObject(); } else { transaction = arg; } diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index 82a6eb27f..d44fb1be8 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -1235,6 +1235,40 @@ describe('Transaction', function() { }); }); }); + describe('fromObject', function () { + it('Should copy transaction when passing instance of Transaction as arg', function() { + var tx = bitcore.Transaction({ + hash: '132856bf03d6415562a556437d22ac63c37a4595fd986c796eb8e02dc031aa25', + version: 1, + inputs: [ + { + prevTxId: 'e30ac3db24ef28500f023775d8eb06ad8a26241690080260308208a4020012a4', + outputIndex: 0, + sequenceNumber: 4294967294, + script: '473044022024dbcf41ccd4f3fe325bebb7a87d0bf359eefa03826482008e0fe7795586ad440220676f5f211ebbc311cfa631f14a8223a343cbadc6fa97d6d17f8d2531308b533201', + scriptString: '71 0x3044022024dbcf41ccd4f3fe325bebb7a87d0bf359eefa03826482008e0fe7795586ad440220676f5f211ebbc311cfa631f14a8223a343cbadc6fa97d6d17f8d2531308b533201', + output: { + satoshis: 5000000000, + script: '2103b1c65d65f1ff3fe145a4ede692460ae0606671d04e8449e99dd11c66ab55a7feac' + } + } + ], + outputs: [ + { + satoshis: 3999999040, + script: '76a914fa1e0abfb8d26e494375f47e04b4883c44dd44d988ac' + }, + { + satoshis: 1000000000, + script: '76a9140b2f0a0c31bfe0406b0ccc1381fdbe311946dadc88ac' + } + ], + nLockTime: 139 + }); + const copiedTransaction = bitcore.Transaction().fromObject(tx); + expect(copiedTransaction).to.be.an.instanceof(bitcore.Transaction); + }); + }); }); From ccd85649dff2928b32fe17fd04a69c06257f5752 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Thu, 8 Feb 2018 20:34:07 +0300 Subject: [PATCH 2/2] Fixed accidental const in test --- test/transaction/transaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index d44fb1be8..c31cb4178 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -1265,7 +1265,7 @@ describe('Transaction', function() { ], nLockTime: 139 }); - const copiedTransaction = bitcore.Transaction().fromObject(tx); + var copiedTransaction = bitcore.Transaction().fromObject(tx); expect(copiedTransaction).to.be.an.instanceof(bitcore.Transaction); }); });