1616
1717import { expect } from 'chai' ;
1818import { ChronoUnit } from 'js-joda' ;
19+ import { VerifiableTransaction } from 'nem2-library' ;
20+ import { TransactionMapping } from '../../../src/core/utils/TransactionMapping' ;
1921import { CreateTransactionFromDTO } from '../../../src/infrastructure/transaction/CreateTransactionFromDTO' ;
2022import { Account } from '../../../src/model/account/Account' ;
2123import { Address } from '../../../src/model/account/Address' ;
@@ -27,6 +29,8 @@ import {MosaicProperties} from '../../../src/model/mosaic/MosaicProperties';
2729import { MosaicSupplyType } from '../../../src/model/mosaic/MosaicSupplyType' ;
2830import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic' ;
2931import { AggregateTransaction } from '../../../src/model/transaction/AggregateTransaction' ;
32+ import { CosignatureSignedTransaction } from '../../../src/model/transaction/CosignatureSignedTransaction' ;
33+ import { CosignatureTransaction } from '../../../src/model/transaction/CosignatureTransaction' ;
3034import { Deadline } from '../../../src/model/transaction/Deadline' ;
3135import { ModifyMultisigAccountTransaction } from '../../../src/model/transaction/ModifyMultisigAccountTransaction' ;
3236import { MosaicDefinitionTransaction } from '../../../src/model/transaction/MosaicDefinitionTransaction' ;
@@ -35,6 +39,7 @@ import {MultisigCosignatoryModification} from '../../../src/model/transaction/Mu
3539import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType' ;
3640import { PlainMessage } from '../../../src/model/transaction/PlainMessage' ;
3741import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction' ;
42+ import { TransactionType } from '../../../src/model/transaction/TransactionType' ;
3843import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction' ;
3944import { UInt64 } from '../../../src/model/UInt64' ;
4045import { Cosignatory2Account , CosignatoryAccount , MultisigAccount , TestingAccount } from '../../conf/conf.spec' ;
@@ -80,7 +85,7 @@ describe('AggregateTransaction', () => {
8085 [ transferTransaction . toAggregate ( account . publicAccount ) ] ,
8186 NetworkType . MIJIN_TEST ,
8287 [ ] ,
83- new UInt64 ( [ 1 , 0 ] )
88+ new UInt64 ( [ 1 , 0 ] ) ,
8489 ) ;
8590
8691 expect ( aggregateTransaction . maxFee . higher ) . to . be . equal ( 0 ) ;
@@ -382,6 +387,67 @@ describe('AggregateTransaction', () => {
382387 } ) . to . throw ( Error , 'Inner transaction cannot be an aggregated transaction.' ) ;
383388 } ) ;
384389
390+ it ( 'Should create signed transaction with cosignatories - Aggregated Complete' , ( ) => {
391+ /**
392+ * https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112
393+ */
394+ const accountAlice = TestingAccount ;
395+ const accountBob = CosignatoryAccount ;
396+ const accountCarol = Cosignatory2Account ;
397+
398+ const AtoBTx = TransferTransaction . create ( Deadline . create ( ) ,
399+ accountBob . address ,
400+ [ ] ,
401+ PlainMessage . create ( 'a to b' ) ,
402+ NetworkType . MIJIN_TEST ) ;
403+ const BtoATx = TransferTransaction . create ( Deadline . create ( ) ,
404+ accountAlice . address ,
405+ [ ] ,
406+ PlainMessage . create ( 'b to a' ) ,
407+ NetworkType . MIJIN_TEST ) ;
408+ const CtoATx = TransferTransaction . create ( Deadline . create ( ) ,
409+ accountAlice . address ,
410+ [ ] ,
411+ PlainMessage . create ( 'c to a' ) ,
412+ NetworkType . MIJIN_TEST ) ;
413+
414+ // 01. Alice creates the aggregated tx and serialize it, and generate the hash. Then send to Bob & Carol
415+ const aggregateTransactionPayload = AggregateTransaction . createComplete (
416+ Deadline . create ( ) ,
417+ [
418+ AtoBTx . toAggregate ( accountAlice . publicAccount ) ,
419+ BtoATx . toAggregate ( accountBob . publicAccount ) ,
420+ CtoATx . toAggregate ( accountCarol . publicAccount ) ] ,
421+ NetworkType . MIJIN_TEST ,
422+ [ ] ,
423+ ) . serialize ( ) ;
424+
425+ const txHash = VerifiableTransaction . createTransactionHash ( aggregateTransactionPayload ) ;
426+
427+ // 02.1 Bob cosigns the tx and sends it back to Alice
428+ const signedTxBob = CosignatureTransaction . signTransactionHashWith ( accountBob , txHash ) ;
429+
430+ // 02.2 Carol cosigns the tx and sends it back to Alice
431+ const signedTxCarol = CosignatureTransaction . signTransactionHashWith ( accountCarol , txHash ) ;
432+
433+ // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
434+
435+ // First Alice need to append cosignatories to current transaction.
436+ const cosignatureSignedTransactions = [
437+ new CosignatureSignedTransaction ( signedTxBob . parentHash , signedTxBob . signature , signedTxBob . signer ) ,
438+ new CosignatureSignedTransaction ( signedTxCarol . parentHash , signedTxCarol . signature , signedTxCarol . signer ) ,
439+ ] ;
440+
441+ const recreatedTx = TransactionMapping . createFromPayload ( aggregateTransactionPayload ) as AggregateTransaction ;
442+
443+ const signedTransaction = recreatedTx . signTransactionWithCosignedTransactions ( accountAlice , cosignatureSignedTransactions ) ;
444+
445+ expect ( signedTransaction . type ) . to . be . equal ( TransactionType . AGGREGATE_COMPLETE ) ;
446+ expect ( signedTransaction . signer ) . to . be . equal ( accountAlice . publicKey ) ;
447+ expect ( signedTransaction . payload . indexOf ( accountBob . publicKey ) > - 1 ) . to . be . true ;
448+ expect ( signedTransaction . payload . indexOf ( accountCarol . publicKey ) > - 1 ) . to . be . true ;
449+ } ) ;
450+
385451 describe ( 'size' , ( ) => {
386452 it ( 'should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM' , ( ) => {
387453 const transaction = TransferTransaction . create (
0 commit comments