@@ -529,3 +529,60 @@ test('can add and remove accounts', async () => {
529
529
530
530
return true
531
531
} )
532
+
533
+ test ( 'errors if dbEncryptionKey is lost' , async ( ) => {
534
+ const keyBytes = new Uint8Array ( [
535
+ 233 , 120 , 198 , 96 , 154 , 65 , 132 , 17 , 132 , 96 , 250 , 40 , 103 , 35 , 125 , 64 ,
536
+ 166 , 83 , 208 , 224 , 254 , 44 , 205 , 227 , 175 , 49 , 234 , 129 , 74 , 252 , 135 , 145 ,
537
+ ] )
538
+ const badKeyBytes = new Uint8Array ( [
539
+ 0 , 0 , 0 , 0 , 154 , 65 , 132 , 17 , 132 , 96 , 250 , 40 , 103 , 35 , 125 , 64 , 166 , 83 ,
540
+ 208 , 224 , 254 , 44 , 205 , 227 , 175 , 49 , 234 , 129 , 0 , 0 , 0 , 0 ,
541
+ ] )
542
+ const alixWallet = Wallet . createRandom ( )
543
+
544
+ const alix = await Client . create ( adaptEthersWalletToSigner ( alixWallet ) , {
545
+ env : 'local' ,
546
+ appVersion : 'Testing/0.0.0' ,
547
+ dbEncryptionKey : keyBytes ,
548
+ } )
549
+
550
+ let errorThrown = false
551
+
552
+ try {
553
+ await Client . build ( alix . address , {
554
+ env : 'local' ,
555
+ appVersion : 'Testing/0.0.0' ,
556
+ dbEncryptionKey : badKeyBytes ,
557
+ } )
558
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
559
+ } catch ( error ) {
560
+ errorThrown = true
561
+ }
562
+
563
+ if ( ! errorThrown ) {
564
+ throw new Error (
565
+ 'Expected build to throw an error with a bad encryption key but it did not'
566
+ )
567
+ }
568
+
569
+ errorThrown = false
570
+ try {
571
+ await Client . create ( adaptEthersWalletToSigner ( alixWallet ) , {
572
+ env : 'local' ,
573
+ appVersion : 'Testing/0.0.0' ,
574
+ dbEncryptionKey : badKeyBytes ,
575
+ } )
576
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
577
+ } catch ( error ) {
578
+ errorThrown = true
579
+ }
580
+
581
+ if ( ! errorThrown ) {
582
+ throw new Error (
583
+ 'Expected create to throw an error with a bad encryption key but it did not'
584
+ )
585
+ }
586
+
587
+ return true
588
+ } )
0 commit comments