Skip to content

Commit 24a8909

Browse files
committed
Added addTransactions to aggregate transactions
Added unit tests
1 parent c14b20e commit 24a8909

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/model/transaction/AggregateTransaction.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ export class AggregateTransaction extends Transaction {
115115
);
116116
}
117117

118+
/**
119+
* @description add inner transactions to current list
120+
* @param {InnerTransaction[]} transaction
121+
* @returns {AggregateTransaction}
122+
* @memberof AggregateTransaction
123+
*/
124+
public addTransactions(transactions: InnerTransaction[]): AggregateTransaction {
125+
const innerTransactions = this.innerTransactions.concat(transactions);
126+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions});
127+
}
128+
118129
/**
119130
* @internal
120131
* @returns {AggregateTransaction}

test/model/transaction/AggregateTransaction.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,33 @@ describe('AggregateTransaction', () => {
454454
expect(standardCosignedTransaction.hash).to.be.equal(signedTransaction.hash);
455455
});
456456

457+
it('Should be able to add innertransactions to current aggregate tx', () => {
458+
const transferTx1 = TransferTransaction.create(Deadline.create(),
459+
account.address,
460+
[],
461+
PlainMessage.create('a to b'),
462+
NetworkType.MIJIN_TEST);
463+
const transferTx2 = TransferTransaction.create(Deadline.create(),
464+
account.address,
465+
[],
466+
PlainMessage.create('b to a'),
467+
NetworkType.MIJIN_TEST);
468+
let aggregateTransaction = AggregateTransaction.createComplete(
469+
Deadline.create(),
470+
[transferTx1.toAggregate(account.publicAccount)],
471+
NetworkType.MIJIN_TEST,
472+
[],
473+
);
474+
475+
expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE);
476+
expect(aggregateTransaction.innerTransactions.length).to.be.equal(1);
477+
478+
aggregateTransaction = aggregateTransaction.addTransactions([transferTx2.toAggregate(account.publicAccount)]);
479+
480+
expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE);
481+
expect(aggregateTransaction.innerTransactions.length).to.be.equal(2);
482+
});
483+
457484
describe('size', () => {
458485
it('should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => {
459486
const transaction = TransferTransaction.create(

0 commit comments

Comments
 (0)