16
16
17
17
import { expect } from 'chai' ;
18
18
import { ChronoUnit } from 'js-joda' ;
19
+ import { TransactionMapping } from '../../../src/core/utils/TransactionMapping' ;
19
20
import { CreateTransactionFromDTO } from '../../../src/infrastructure/transaction/CreateTransactionFromDTO' ;
20
21
import { Account } from '../../../src/model/account/Account' ;
21
22
import { Address } from '../../../src/model/account/Address' ;
@@ -27,6 +28,8 @@ import {MosaicProperties} from '../../../src/model/mosaic/MosaicProperties';
27
28
import { MosaicSupplyType } from '../../../src/model/mosaic/MosaicSupplyType' ;
28
29
import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic' ;
29
30
import { AggregateTransaction } from '../../../src/model/transaction/AggregateTransaction' ;
31
+ import { CosignatureSignedTransaction } from '../../../src/model/transaction/CosignatureSignedTransaction' ;
32
+ import { CosignatureTransaction } from '../../../src/model/transaction/CosignatureTransaction' ;
30
33
import { Deadline } from '../../../src/model/transaction/Deadline' ;
31
34
import { ModifyMultisigAccountTransaction } from '../../../src/model/transaction/ModifyMultisigAccountTransaction' ;
32
35
import { MosaicDefinitionTransaction } from '../../../src/model/transaction/MosaicDefinitionTransaction' ;
@@ -35,6 +38,7 @@ import {MultisigCosignatoryModification} from '../../../src/model/transaction/Mu
35
38
import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType' ;
36
39
import { PlainMessage } from '../../../src/model/transaction/PlainMessage' ;
37
40
import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction' ;
41
+ import { TransactionType } from '../../../src/model/transaction/TransactionType' ;
38
42
import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction' ;
39
43
import { UInt64 } from '../../../src/model/UInt64' ;
40
44
import { Cosignatory2Account , CosignatoryAccount , MultisigAccount , TestingAccount } from '../../conf/conf.spec' ;
@@ -80,7 +84,7 @@ describe('AggregateTransaction', () => {
80
84
[ transferTransaction . toAggregate ( account . publicAccount ) ] ,
81
85
NetworkType . MIJIN_TEST ,
82
86
[ ] ,
83
- new UInt64 ( [ 1 , 0 ] )
87
+ new UInt64 ( [ 1 , 0 ] ) ,
84
88
) ;
85
89
86
90
expect ( aggregateTransaction . maxFee . higher ) . to . be . equal ( 0 ) ;
@@ -382,6 +386,65 @@ describe('AggregateTransaction', () => {
382
386
} ) . to . throw ( Error , 'Inner transaction cannot be an aggregated transaction.' ) ;
383
387
} ) ;
384
388
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
+
385
448
describe ( 'size' , ( ) => {
386
449
it ( 'should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM' , ( ) => {
387
450
const transaction = TransferTransaction . create (
@@ -402,4 +465,4 @@ describe('AggregateTransaction', () => {
402
465
expect ( aggregateTransaction . size ) . to . be . equal ( 120 + 4 + 158 ) ;
403
466
} ) ;
404
467
} ) ;
405
- } ) ;
468
+ } ) ;
0 commit comments