From bea6add0d7a5c6ba8c774d431a3a78fb90d6730e Mon Sep 17 00:00:00 2001 From: exo-mv Date: Thu, 4 Jun 2026 13:44:14 +0000 Subject: [PATCH] fix(transaction): use arg.toObject() in fromObject for Transaction instances fromObject called transaction.toObject() while the transaction variable was still undefined, so passing a Transaction instance threw "TypeError: Cannot read properties of undefined (reading 'toObject')". Read from the arg parameter, which holds the Transaction instance. Add a regression test for this previously uncovered path. Co-Authored-By: Claude Opus 4.7 Co-authored-by: Claude Code (claude-opus-4-8[1m]) --- lib/transaction/transaction.js | 2 +- test/transaction/fromObject.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/transaction/fromObject.js diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index f15043c..ee8499b 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -472,7 +472,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/fromObject.js b/test/transaction/fromObject.js new file mode 100644 index 0000000..61c488e --- /dev/null +++ b/test/transaction/fromObject.js @@ -0,0 +1,23 @@ +'use strict'; + +require('chai').should(); + +var bitcore = require('../../index-test'); +var Transaction = bitcore.Transaction; + +describe('Transaction', function() { + + describe('#fromObject', function() { + + it('builds from a Transaction instance and preserves its data', function() { + var source = new Transaction().lockUntilBlockHeight(123); + + var target = new Transaction().fromObject(source); + + target.nLockTime.should.equal(123); + target.toObject().should.deep.equal(source.toObject()); + }); + + }); + +});