@@ -18,6 +18,7 @@ import {expect} from 'chai';
1818import { ChronoUnit } from 'js-joda' ;
1919import { TransactionMapping } from '../../../src/core/utils/TransactionMapping' ;
2020import { CreateTransactionFromDTO } from '../../../src/infrastructure/transaction/CreateTransactionFromDTO' ;
21+ import { CreateTransactionFromPayload } from '../../../src/infrastructure/transaction/CreateTransactionFromPayload' ;
2122import { Account } from '../../../src/model/account/Account' ;
2223import { Address } from '../../../src/model/account/Address' ;
2324import { PublicAccount } from '../../../src/model/account/PublicAccount' ;
@@ -116,6 +117,55 @@ describe('AggregateTransaction', () => {
116117 ) ) . to . be . equal ( '019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765' ) ;
117118 } ) ;
118119
120+ it ( 'should createComplete an AggregateTransaction object with delegated signer' , ( ) => {
121+ const transferTransaction = TransferTransaction . create (
122+ Deadline . create ( 1 , ChronoUnit . HOURS ) ,
123+ Address . createFromRawAddress ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ,
124+ [ ] ,
125+ PlainMessage . create ( 'test-message' ) ,
126+ NetworkType . MIJIN_TEST ,
127+ ) ;
128+
129+ const aggregateTransaction = AggregateTransaction . createComplete (
130+ Deadline . create ( ) ,
131+ [ transferTransaction . toAggregate ( ) ] ,
132+ NetworkType . MIJIN_TEST ,
133+ [ ] ) ;
134+ expect ( aggregateTransaction . innerTransactions [ 0 ] . signer ) . to . be . undefined ;
135+
136+ const signedTransaction = aggregateTransaction . signWith ( account , generationHash ) ;
137+
138+ expect ( signedTransaction . payload . substring ( 0 , 8 ) ) . to . be . equal ( 'CD000000' ) ;
139+ expect ( signedTransaction . payload . substring ( 240 , 256 ) ) . to . be . equal ( '5100000051000000' ) ;
140+ expect ( signedTransaction . payload . substring (
141+ 320 ,
142+ signedTransaction . payload . length ,
143+ ) ) . to . be . equal ( '019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765' ) ;
144+
145+ const createdFromPayload = CreateTransactionFromPayload ( signedTransaction . payload ) ;
146+ expect ( ( createdFromPayload as AggregateTransaction ) . innerTransactions [ 0 ] . signer ! . publicKey )
147+ . to . be . equal ( account . publicKey ) ;
148+ } ) ;
149+
150+ it ( 'should throw exception with delegated signer' , ( ) => {
151+ expect ( ( ) => {
152+ const transferTransaction = TransferTransaction . create (
153+ Deadline . create ( 1 , ChronoUnit . HOURS ) ,
154+ Address . createFromRawAddress ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ,
155+ [ ] ,
156+ PlainMessage . create ( 'test-message' ) ,
157+ NetworkType . MIJIN_TEST ,
158+ ) ;
159+ const aggregateTransaction = AggregateTransaction . createBonded (
160+ Deadline . create ( ) ,
161+ [ transferTransaction . toAggregate ( ) ] ,
162+ NetworkType . MIJIN_TEST ,
163+ [ ] ) ;
164+
165+ aggregateTransaction . signWith ( account , generationHash ) ;
166+ } ) . to . throw ( Error , 'InnerTransaction signer must be provide. Only AggregateComplete transaction can use delegated signer.' ) ;
167+ } ) ;
168+
119169 it ( 'should createComplete an AggregateTransaction object with NamespaceRegistrationTransaction' , ( ) => {
120170 const registerNamespaceTransaction = NamespaceRegistrationTransaction . createRootNamespace (
121171 Deadline . create ( ) ,
0 commit comments