From c0e0b5eb303a1c8f78fc4405ccdec839fc607fa5 Mon Sep 17 00:00:00 2001 From: aizaiz Date: Thu, 29 Nov 2018 14:40:22 +0800 Subject: [PATCH] feat(ApostillePublicAccount): signAggregate receive array of innertransaction instead of transaction --- src/model/apostille/ApostillePublicAccount.ts | 20 ++++++------ .../apostille/ApostillePublicAccount.spec.ts | 32 +++++++++++++++---- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/model/apostille/ApostillePublicAccount.ts b/src/model/apostille/ApostillePublicAccount.ts index e85503c..1ffcdd1 100644 --- a/src/model/apostille/ApostillePublicAccount.ts +++ b/src/model/apostille/ApostillePublicAccount.ts @@ -1,4 +1,4 @@ -import { Account, AggregateTransaction, Deadline, LockFundsTransaction, ModifyMultisigAccountTransaction, Mosaic, MultisigCosignatoryModification, MultisigCosignatoryModificationType, PlainMessage, PublicAccount, SignedTransaction, Transaction, TransferTransaction, UInt64, XEM } from 'nem2-sdk'; +import { Account, AggregateTransaction, Deadline, InnerTransaction, LockFundsTransaction, ModifyMultisigAccountTransaction, Mosaic, MultisigCosignatoryModification, MultisigCosignatoryModificationType, PlainMessage, PublicAccount, SignedTransaction, Transaction, TransferTransaction, UInt64, XEM } from 'nem2-sdk'; import { HashFunction } from '../../hash/HashFunction'; import { Errors } from '../../types/Errors'; @@ -140,21 +140,21 @@ export class ApostillePublicAccount { * @returns * @memberof ApostillePublicAccount */ - public signAggregate(transaction: Transaction, signers: Account[], isCompleteCosignatories: boolean) { + public signAggregate(innerTransactions: InnerTransaction[], signers: Account[], isCompleteCosignatories: boolean) { if (isCompleteCosignatories) { - return this._signTransferTransactionAgregateComplete(transaction, signers); + return this._signAgregateCompleteTransaction(innerTransactions, signers); } else { - return this._signTransferTransactionAggregateBonded(transaction, signers); + return this._signAgregateBondedTransaction(innerTransactions, signers); } } - private _signTransferTransactionAgregateComplete( - transaction: Transaction, + private _signAgregateCompleteTransaction( + innerTransactions: InnerTransaction[], signers: Account[], ): SignedTransaction { const aggregateTransaction = AggregateTransaction.createComplete( Deadline.create(), - [transaction.toAggregate(this.publicAccount)], + innerTransactions, this.publicAccount.address.networkType, []); @@ -163,13 +163,13 @@ export class ApostillePublicAccount { return signedAggregateTransaction; } - private _signTransferTransactionAggregateBonded( - transaction: Transaction, + private _signAgregateBondedTransaction( + innerTransactions: InnerTransaction[], signers: Account[], ): SignedTransaction { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), - [transaction.toAggregate(this.publicAccount)], + innerTransactions, this.publicAccount.address.networkType); const signedAggregateTransaction = this._signAggregate(aggregateTransaction, signers); diff --git a/tests/unit/model/apostille/ApostillePublicAccount.spec.ts b/tests/unit/model/apostille/ApostillePublicAccount.spec.ts index c0fd48a..04b3122 100644 --- a/tests/unit/model/apostille/ApostillePublicAccount.spec.ts +++ b/tests/unit/model/apostille/ApostillePublicAccount.spec.ts @@ -107,9 +107,12 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount); + expect(() => { apostillePublicAccount.signAggregate( - transferTransaction, + [innerTransaction], [], true); }).toThrowError(Errors[Errors.UNABLE_TO_SIGN_AGGREGATE_TRANSACTION]); @@ -121,8 +124,10 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount); const signedTransferTransaction = apostillePublicAccount.signAggregate( - transferTransaction, + [innerTransaction], [signer], true); expect(signedTransferTransaction.signer).toMatch(signer.publicAccount.publicKey); @@ -134,8 +139,11 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount); + const signedTransferTransaction = apostillePublicAccount.signAggregate( - transferTransaction, + [innerTransaction], [signer, secondSigner], true); expect(signedTransferTransaction.signer).toMatch(signer.publicAccount.publicKey); @@ -147,8 +155,10 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount); const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate( - aggregateBondedTransaction, + [innerTransaction], [signer], false); expect(signedAggregateBondedTransaction.signer).toMatch(signer.publicAccount.publicKey); @@ -160,8 +170,10 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount); + const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate( - aggregateBondedTransaction, + [innerTransaction], [signer, secondSigner], false); expect(signedAggregateBondedTransaction.signer).toMatch(signer.publicAccount.publicKey); @@ -173,8 +185,11 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount); + const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate( - aggregateBondedTransaction, + [innerTransaction], [signer], false); const lockFundsTransaction = apostillePublicAccount.lockFundsTransaction( @@ -188,8 +203,11 @@ describe('apostille public account transaction methods should work properly', () [signer.publicAccount], 0, 0); + + const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount); + const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate( - aggregateBondedTransaction, + [innerTransaction], [signer], false); const lockFundsTransaction = apostillePublicAccount.lockFundsTransaction(