@@ -8,7 +8,8 @@ describe('LitCore', () => {
8
8
describe ( 'getLatestBlockhash' , ( ) => {
9
9
let originalFetch : typeof fetch ;
10
10
let originalDateNow : typeof Date . now ;
11
- const mockBlockhashUrl = 'https://block-indexer-url.com/get_most_recent_valid_block' ;
11
+ const mockBlockhashUrl =
12
+ 'https://block-indexer-url.com/get_most_recent_valid_block' ;
12
13
13
14
beforeEach ( ( ) => {
14
15
core = new LitCore ( {
@@ -51,7 +52,12 @@ describe('LitCore', () => {
51
52
const blockNumber = 12345 ;
52
53
global . fetch = jest . fn ( ) . mockResolvedValue ( {
53
54
ok : true ,
54
- json : ( ) => Promise . resolve ( { blockhash : mockBlockhash , timestamp : currentTime , blockNumber } ) ,
55
+ json : ( ) =>
56
+ Promise . resolve ( {
57
+ blockhash : mockBlockhash ,
58
+ timestamp : currentTime ,
59
+ blockNumber,
60
+ } ) ,
55
61
} ) ;
56
62
Date . now = jest . fn ( ) . mockReturnValue ( currentTime ) ;
57
63
@@ -73,7 +79,9 @@ describe('LitCore', () => {
73
79
core [ '_getProviderWithFallback' ] = jest . fn ( ( ) => Promise . resolve ( null ) ) ;
74
80
75
81
// Execute & Assert
76
- await expect ( core . getLatestBlockhash ( ) ) . rejects . toThrow ( InvalidEthBlockhash ) ;
82
+ await expect ( core . getLatestBlockhash ( ) ) . rejects . toThrow (
83
+ InvalidEthBlockhash
84
+ ) ;
77
85
} ) ;
78
86
79
87
it ( 'should handle fetch failure and use fallback RPC' , async ( ) => {
@@ -87,7 +95,7 @@ describe('LitCore', () => {
87
95
getBlock : jest . fn ( ) . mockResolvedValue ( {
88
96
hash : mockBlockhash ,
89
97
number : 12345 ,
90
- timestamp : currentTime
98
+ timestamp : currentTime ,
91
99
} ) ,
92
100
} ;
93
101
jest . spyOn ( core as any , '_getProviderWithFallback' ) . mockResolvedValue ( {
@@ -110,17 +118,18 @@ describe('LitCore', () => {
110
118
Date . now = jest . fn ( ) . mockReturnValue ( currentTime ) ;
111
119
global . fetch = jest . fn ( ) . mockResolvedValue ( {
112
120
ok : true ,
113
- json : ( ) => Promise . resolve ( {
114
- blockhash : null ,
115
- blockNumber : null
116
- } ) ,
121
+ json : ( ) =>
122
+ Promise . resolve ( {
123
+ blockhash : null ,
124
+ blockNumber : null ,
125
+ } ) ,
117
126
} ) ;
118
127
const mockProvider = {
119
128
getBlockNumber : jest . fn ( ) . mockResolvedValue ( 12345 ) ,
120
129
getBlock : jest . fn ( ) . mockResolvedValue ( {
121
130
hash : mockBlockhash ,
122
131
number : 12345 ,
123
- timestamp : currentTime
132
+ timestamp : currentTime ,
124
133
} ) ,
125
134
} ;
126
135
jest . spyOn ( core as any , '_getProviderWithFallback' ) . mockResolvedValue ( {
@@ -141,11 +150,14 @@ describe('LitCore', () => {
141
150
const currentTime = 1000000 ;
142
151
Date . now = jest . fn ( ) . mockReturnValue ( currentTime ) ;
143
152
144
- global . fetch = jest . fn ( ) . mockImplementation ( ( ) =>
145
- new Promise ( ( _ , reject ) =>
146
- setTimeout ( ( ) => reject ( new Error ( 'Network timeout' ) ) , 1000 )
147
- )
148
- ) ;
153
+ global . fetch = jest
154
+ . fn ( )
155
+ . mockImplementation (
156
+ ( ) =>
157
+ new Promise ( ( _ , reject ) =>
158
+ setTimeout ( ( ) => reject ( new Error ( 'Network timeout' ) ) , 1000 )
159
+ )
160
+ ) ;
149
161
150
162
const mockProvider = {
151
163
getBlockNumber : jest . fn ( ) . mockResolvedValue ( 12345 ) ,
@@ -162,5 +174,4 @@ describe('LitCore', () => {
162
174
) ;
163
175
} ) ;
164
176
} ) ;
165
-
166
177
} ) ;
0 commit comments