1616
1717import { expect } from 'chai' ;
1818import { ChronoUnit } from 'js-joda' ;
19+ import { TransactionMapping } from '../../../src/core/utils/TransactionMapping' ;
1920import { CreateTransactionFromDTO } from '../../../src/infrastructure/transaction/CreateTransactionFromDTO' ;
2021import { Account } from '../../../src/model/account/Account' ;
2122import { Address } from '../../../src/model/account/Address' ;
@@ -27,6 +28,8 @@ import {MosaicProperties} from '../../../src/model/mosaic/MosaicProperties';
2728import { MosaicSupplyType } from '../../../src/model/mosaic/MosaicSupplyType' ;
2829import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic' ;
2930import { AggregateTransaction } from '../../../src/model/transaction/AggregateTransaction' ;
31+ import { CosignatureSignedTransaction } from '../../../src/model/transaction/CosignatureSignedTransaction' ;
32+ import { CosignatureTransaction } from '../../../src/model/transaction/CosignatureTransaction' ;
3033import { Deadline } from '../../../src/model/transaction/Deadline' ;
3134import { ModifyMultisigAccountTransaction } from '../../../src/model/transaction/ModifyMultisigAccountTransaction' ;
3235import { MosaicDefinitionTransaction } from '../../../src/model/transaction/MosaicDefinitionTransaction' ;
@@ -35,6 +38,7 @@ import {MultisigCosignatoryModification} from '../../../src/model/transaction/Mu
3538import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType' ;
3639import { PlainMessage } from '../../../src/model/transaction/PlainMessage' ;
3740import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction' ;
41+ import { TransactionType } from '../../../src/model/transaction/TransactionType' ;
3842import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction' ;
3943import { UInt64 } from '../../../src/model/UInt64' ;
4044import { Cosignatory2Account , CosignatoryAccount , MultisigAccount , TestingAccount } from '../../conf/conf.spec' ;
@@ -80,7 +84,7 @@ describe('AggregateTransaction', () => {
8084 [ transferTransaction . toAggregate ( account . publicAccount ) ] ,
8185 NetworkType . MIJIN_TEST ,
8286 [ ] ,
83- new UInt64 ( [ 1 , 0 ] )
87+ new UInt64 ( [ 1 , 0 ] ) ,
8488 ) ;
8589
8690 expect ( aggregateTransaction . maxFee . higher ) . to . be . equal ( 0 ) ;
@@ -382,6 +386,65 @@ describe('AggregateTransaction', () => {
382386 } ) . to . throw ( Error , 'Inner transaction cannot be an aggregated transaction.' ) ;
383387 } ) ;
384388
389+ it ( 'Should create signed transaction with cosignatories - Aggregated Complete' , ( ) => {
390+ /**
391+ * https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112
392+ */
393+ const accountAlice = TestingAccount ;
394+ const accountBob = CosignatoryAccount ;
395+ const accountCarol = Cosignatory2Account ;
396+
397+ const AtoBTx = TransferTransaction . create ( Deadline . create ( ) ,
398+ accountBob . address ,
399+ [ ] ,
400+ PlainMessage . create ( 'a to b' ) ,
401+ NetworkType . MIJIN_TEST ) ;
402+ const BtoATx = TransferTransaction . create ( Deadline . create ( ) ,
403+ accountAlice . address ,
404+ [ ] ,
405+ PlainMessage . create ( 'b to a' ) ,
406+ NetworkType . MIJIN_TEST ) ;
407+ const CtoATx = TransferTransaction . create ( Deadline . create ( ) ,
408+ accountAlice . address ,
409+ [ ] ,
410+ PlainMessage . create ( 'c to a' ) ,
411+ NetworkType . MIJIN_TEST ) ;
412+
413+ // 01. Alice creates the aggregated tx and serialize it, Then payload send to Bob & Carol
414+ const aggregateTransactionPayload = AggregateTransaction . createComplete (
415+ Deadline . create ( ) ,
416+ [
417+ AtoBTx . toAggregate ( accountAlice . publicAccount ) ,
418+ BtoATx . toAggregate ( accountBob . publicAccount ) ,
419+ CtoATx . toAggregate ( accountCarol . publicAccount ) ] ,
420+ NetworkType . MIJIN_TEST ,
421+ [ ] ,
422+ ) . serialize ( ) ;
423+
424+ // 02.1 Bob cosigns the tx and sends it back to Alice
425+ const signedTxBob = CosignatureTransaction . signTransactionPayload ( accountBob , aggregateTransactionPayload , generationHash ) ;
426+
427+ // 02.2 Carol cosigns the tx and sends it back to Alice
428+ const signedTxCarol = CosignatureTransaction . signTransactionPayload ( accountCarol , aggregateTransactionPayload , generationHash ) ;
429+
430+ // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
431+
432+ // First Alice need to append cosignatories to current transaction.
433+ const cosignatureSignedTransactions = [
434+ new CosignatureSignedTransaction ( signedTxBob . parentHash , signedTxBob . signature , signedTxBob . signer ) ,
435+ new CosignatureSignedTransaction ( signedTxCarol . parentHash , signedTxCarol . signature , signedTxCarol . signer ) ,
436+ ] ;
437+
438+ const recreatedTx = TransactionMapping . createFromPayload ( aggregateTransactionPayload ) as AggregateTransaction ;
439+
440+ const signedTransaction = recreatedTx . signTransactionGivenSignatures ( accountAlice , cosignatureSignedTransactions , generationHash ) ;
441+
442+ expect ( signedTransaction . type ) . to . be . equal ( TransactionType . AGGREGATE_COMPLETE ) ;
443+ expect ( signedTransaction . signer ) . to . be . equal ( accountAlice . publicKey ) ;
444+ expect ( signedTransaction . payload . indexOf ( accountBob . publicKey ) > - 1 ) . to . be . true ;
445+ expect ( signedTransaction . payload . indexOf ( accountCarol . publicKey ) > - 1 ) . to . be . true ;
446+ } ) ;
447+
385448 describe ( 'size' , ( ) => {
386449 it ( 'should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM' , ( ) => {
387450 const transaction = TransferTransaction . create (
@@ -402,4 +465,4 @@ describe('AggregateTransaction', () => {
402465 expect ( aggregateTransaction . size ) . to . be . equal ( 120 + 4 + 158 ) ;
403466 } ) ;
404467 } ) ;
405- } ) ;
468+ } ) ;
0 commit comments