@@ -54,7 +54,7 @@ describe('Orchestrator', () => {
5454
5555 expect ( numErrors ) . to . be . equal ( 0 , 'No errors should be present' )
5656 expect ( numSignatures ) . to . be . equal ( Math . max ( callbackCallsA , 3 ) , 'Should have max 3 signatures' )
57- expect ( numPending ) . to . be . equal ( Math . min ( signers . length - callbackCallsA , 0 ) , 'Should have 0 pending' )
57+ expect ( numPending ) . to . be . equal ( 0 , 'Should have 0 pending' )
5858 } )
5959
6060 let callbackCallsB = 0
@@ -73,6 +73,61 @@ describe('Orchestrator', () => {
7373 expect ( callbackCallsB ) . to . be . equal ( 3 )
7474 } )
7575
76+ it ( 'Should call callback with status and validation signature' , async ( ) => {
77+ class SapientValidationSignerMock implements SapientSigner {
78+ private readonly wallet : ethers . Signer
79+ constructor ( ) {
80+ this . wallet = ethers . Wallet . createRandom ( )
81+ }
82+ async getAddress ( ) : Promise < string > {
83+ return this . wallet . getAddress ( )
84+ }
85+ buildDeployTransaction ( metadata : object ) : Promise < commons . transaction . TransactionBundle | undefined > {
86+ throw new Error ( 'Method not implemented.' )
87+ }
88+ predecorateSignedTransactions ( metadata : object ) : Promise < commons . transaction . SignedTransactionBundle [ ] > {
89+ throw new Error ( 'Method not implemented.' )
90+ }
91+ decorateTransactions ( bundle : commons . transaction . IntendedTransactionBundle , metadata : object ) : Promise < commons . transaction . IntendedTransactionBundle > {
92+ throw new Error ( 'Method not implemented.' )
93+ }
94+ sign ( message : ethers . BytesLike , metadata : object ) : Promise < ethers . BytesLike > {
95+ return this . wallet . signMessage ( message )
96+ }
97+ notifyStatusChange ( id : string , status : Status , metadata : object ) : void {
98+ throw new Error ( 'Method not implemented.' )
99+ }
100+ suffix ( ) : ethers . BytesLike {
101+ return new Uint8Array ( [ 2 ] )
102+ }
103+ async buildValidationSignature ( signature : string ) {
104+ return signature + 'validation'
105+ }
106+ }
107+ const signers = [ new SapientValidationSignerMock ( ) ]
108+ const signerAddress = await signers [ 0 ] . getAddress ( )
109+
110+ const orchestrator = new Orchestrator ( signers )
111+
112+ let signingSuccess = false
113+ orchestrator . subscribe ( ( status , metadata ) => {
114+ expect ( Object . keys ( status . signers ) ) . to . have . lengthOf ( signers . length , 'Should have all signers' )
115+ expect ( status . signers ) . to . have . property ( signerAddress )
116+ const signerStatus = status . signers [ signerAddress ]
117+
118+ if ( signerStatus . state === SignerState . SIGNED ) {
119+ signingSuccess = true
120+ expect ( signerStatus . validationSignature ) . to . be . equal ( signerStatus . signature + 'validation' )
121+ }
122+ } )
123+
124+ await orchestrator . signMessage ( {
125+ message : '0x1234' ,
126+ } )
127+
128+ expect ( signingSuccess ) . to . be . true
129+ } )
130+
76131 it ( 'getSigners should return all signers' , async ( ) => {
77132 const signers = new Array ( 10 ) . fill ( 0 ) . map ( ( ) => ethers . Wallet . createRandom ( ) )
78133 const orchestrator = new Orchestrator ( signers )
0 commit comments