From 503c27887a34f0f4b529a8769f6038bbf4173607 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 13:47:11 +0100 Subject: [PATCH 1/2] Added `addTransactions` to aggregate transactions Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 ++++++++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..26ace13e3b 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -115,6 +115,17 @@ export class AggregateTransaction extends Transaction { ); } + /** + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction + * @returns {AggregateTransaction} + * @memberof AggregateTransaction + */ + public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { + const innerTransactions = this.innerTransactions.concat(transactions); + return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); + } + /** * @internal * @returns {AggregateTransaction} diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..5cf09cf275 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -454,6 +454,33 @@ describe('AggregateTransaction', () => { expect(standardCosignedTransaction.hash).to.be.equal(signedTransaction.hash); }); + it('Should be able to add innertransactions to current aggregate tx', () => { + const transferTx1 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('a to b'), + NetworkType.MIJIN_TEST); + const transferTx2 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('b to a'), + NetworkType.MIJIN_TEST); + let aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transferTx1.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(1); + + aggregateTransaction = aggregateTransaction.addTransactions([transferTx2.toAggregate(account.publicAccount)]); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(2); + }); + describe('size', () => { it('should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create( From 24a8909f457c2801fa374dbcc90273e83838c7fd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 13:47:11 +0100 Subject: [PATCH 2/2] Added `addTransactions` to aggregate transactions Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 ++++++++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..26ace13e3b 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -115,6 +115,17 @@ export class AggregateTransaction extends Transaction { ); } + /** + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction + * @returns {AggregateTransaction} + * @memberof AggregateTransaction + */ + public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { + const innerTransactions = this.innerTransactions.concat(transactions); + return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); + } + /** * @internal * @returns {AggregateTransaction} diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..5cf09cf275 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -454,6 +454,33 @@ describe('AggregateTransaction', () => { expect(standardCosignedTransaction.hash).to.be.equal(signedTransaction.hash); }); + it('Should be able to add innertransactions to current aggregate tx', () => { + const transferTx1 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('a to b'), + NetworkType.MIJIN_TEST); + const transferTx2 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('b to a'), + NetworkType.MIJIN_TEST); + let aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transferTx1.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(1); + + aggregateTransaction = aggregateTransaction.addTransactions([transferTx2.toAggregate(account.publicAccount)]); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(2); + }); + describe('size', () => { it('should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create(