Skip to content

Commit bea6add

Browse files
exo-mvclaude
authored andcommitted
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 <noreply@anthropic.com> Co-authored-by: Claude Code (claude-opus-4-8[1m]) <noreply@anthropic.com>
1 parent d946729 commit bea6add

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/transaction/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ Transaction.prototype.fromObject = function fromObject(arg) {
472472
var self = this;
473473
var transaction;
474474
if (arg instanceof Transaction) {
475-
transaction = transaction.toObject();
475+
transaction = arg.toObject();
476476
} else {
477477
transaction = arg;
478478
}

test/transaction/fromObject.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
require('chai').should();
4+
5+
var bitcore = require('../../index-test');
6+
var Transaction = bitcore.Transaction;
7+
8+
describe('Transaction', function() {
9+
10+
describe('#fromObject', function() {
11+
12+
it('builds from a Transaction instance and preserves its data', function() {
13+
var source = new Transaction().lockUntilBlockHeight(123);
14+
15+
var target = new Transaction().fromObject(source);
16+
17+
target.nLockTime.should.equal(123);
18+
target.toObject().should.deep.equal(source.toObject());
19+
});
20+
21+
});
22+
23+
});

0 commit comments

Comments
 (0)