@@ -4,7 +4,7 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'
4
4
import { expect } from 'chai' ;
5
5
import sinon from 'sinon' ;
6
6
7
- import { cache , CacheHelper } from '../../../dist/lib/decorators' ;
7
+ import { __test__ , cache } from '../../../dist/lib/decorators' ;
8
8
import { CacheService } from '../../../dist/lib/services/cacheService/cacheService' ;
9
9
import { RequestDetails } from '../../../src/lib/types' ;
10
10
@@ -108,7 +108,7 @@ describe('cache decorator', () => {
108
108
describe ( 'shouldSkipCachingForSingleParams' , ( ) => {
109
109
it ( 'should return false if no skip rules are provided' , ( ) => {
110
110
const args = [ 'safe' , 'latest' ] as unknown as IArguments ;
111
- const result = CacheHelper [ ' shouldSkipCachingForSingleParams' ] ( args , [ ] ) ;
111
+ const result = __test__ . __private . shouldSkipCachingForSingleParams ( args , [ ] ) ;
112
112
expect ( result ) . to . be . false ;
113
113
} ) ;
114
114
@@ -118,36 +118,36 @@ describe('cache decorator', () => {
118
118
{ index : '0' , value : 'pending' } ,
119
119
{ index : '1' , value : 'safe|finalized' } ,
120
120
] ;
121
- const result = CacheHelper [ ' shouldSkipCachingForSingleParams' ] ( args , params ) ;
121
+ const result = __test__ . __private . shouldSkipCachingForSingleParams ( args , params ) ;
122
122
expect ( result ) . to . be . false ;
123
123
} ) ;
124
124
125
125
it ( 'should return true if a param at index matches any value in the pipe-separated list' , ( ) => {
126
126
const args = [ 'earliest' , 'safe' ] as unknown as IArguments ;
127
127
const params = [ { index : '1' , value : 'pending|safe' } ] ;
128
- const result = CacheHelper [ ' shouldSkipCachingForSingleParams' ] ( args , params ) ;
128
+ const result = __test__ . __private . shouldSkipCachingForSingleParams ( args , params ) ;
129
129
expect ( result ) . to . be . true ;
130
130
} ) ;
131
131
132
132
it ( 'should return true if the argument at index is missing (do not cache optional parameters)' , ( ) => {
133
133
const args = [ 'latest' ] as unknown as IArguments ;
134
134
const params = [ { index : '1' , value : 'pending|safe' } ] ;
135
- const result = CacheHelper [ ' shouldSkipCachingForSingleParams' ] ( args , params ) ;
135
+ const result = __test__ . __private . shouldSkipCachingForSingleParams ( args , params ) ;
136
136
expect ( result ) . to . be . true ;
137
137
} ) ;
138
138
139
139
it ( 'should return true if the argument at index is explicitly undefined' , ( ) => {
140
140
const args = [ 'finalized' , undefined ] as unknown as IArguments ;
141
141
const params = [ { index : '1' , value : 'pending|safe' } ] ;
142
- const result = CacheHelper [ ' shouldSkipCachingForSingleParams' ] ( args , params ) ;
142
+ const result = __test__ . __private . shouldSkipCachingForSingleParams ( args , params ) ;
143
143
expect ( result ) . to . be . true ;
144
144
} ) ;
145
145
} ) ;
146
146
147
147
describe ( 'shouldSkipCachingForNamedParams' , ( ) => {
148
148
it ( 'should return false when no rules are provided' , ( ) => {
149
149
const args = [ { fromBlock : 'safe' } ] as unknown as IArguments ;
150
- const result = CacheHelper [ ' shouldSkipCachingForNamedParams' ] ( args , [ ] ) ;
150
+ const result = __test__ . __private . shouldSkipCachingForNamedParams ( args , [ ] ) ;
151
151
expect ( result ) . to . be . false ;
152
152
} ) ;
153
153
@@ -159,7 +159,7 @@ describe('cache decorator', () => {
159
159
fields : [ { name : 'fromBlock' , value : 'pending|safe' } ] ,
160
160
} ,
161
161
] ;
162
- const result = CacheHelper [ ' shouldSkipCachingForNamedParams' ] ( args , params ) ;
162
+ const result = __test__ . __private . shouldSkipCachingForNamedParams ( args , params ) ;
163
163
expect ( result ) . to . be . false ;
164
164
} ) ;
165
165
@@ -174,7 +174,7 @@ describe('cache decorator', () => {
174
174
] ,
175
175
} ,
176
176
] ;
177
- const result = CacheHelper [ ' shouldSkipCachingForNamedParams' ] ( args , params ) ;
177
+ const result = __test__ . __private . shouldSkipCachingForNamedParams ( args , params ) ;
178
178
expect ( result ) . to . be . false ;
179
179
} ) ;
180
180
@@ -186,7 +186,7 @@ describe('cache decorator', () => {
186
186
fields : [ { name : 'fromBlock' , value : 'pending|safe' } ] ,
187
187
} ,
188
188
] ;
189
- const result = CacheHelper [ ' shouldSkipCachingForNamedParams' ] ( args , params ) ;
189
+ const result = __test__ . __private . shouldSkipCachingForNamedParams ( args , params ) ;
190
190
expect ( result ) . to . be . true ;
191
191
} ) ;
192
192
@@ -201,7 +201,7 @@ describe('cache decorator', () => {
201
201
] ,
202
202
} ,
203
203
] ;
204
- const result = CacheHelper [ ' shouldSkipCachingForNamedParams' ] ( args , params ) ;
204
+ const result = __test__ . __private . shouldSkipCachingForNamedParams ( args , params ) ;
205
205
expect ( result ) . to . be . true ;
206
206
} ) ;
207
207
} ) ;
@@ -210,21 +210,21 @@ describe('cache decorator', () => {
210
210
it ( 'should return only the method name when args are empty' , ( ) => {
211
211
const args = [ ] as unknown as IArguments ;
212
212
213
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_getBalance' , args ) ;
213
+ const result = __test__ . __private . generateCacheKey ( 'eth_getBalance' , args ) ;
214
214
expect ( result ) . to . equal ( 'eth_getBalance' ) ;
215
215
} ) ;
216
216
217
217
it ( 'should append primitive arguments to the cache key' , ( ) => {
218
218
const args = [ '0xabc' , 'latest' ] as unknown as IArguments ;
219
219
220
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_getBalance' , args ) ;
220
+ const result = __test__ . __private . generateCacheKey ( 'eth_getBalance' , args ) ;
221
221
expect ( result ) . to . equal ( 'eth_getBalance_0xabc_latest' ) ;
222
222
} ) ;
223
223
224
224
it ( 'should append object key-value pairs to the cache key' , ( ) => {
225
225
const args = [ { fromBlock : 'earliest' , toBlock : 5644 } ] as unknown as IArguments ;
226
226
227
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_getLogs' , args ) ;
227
+ const result = __test__ . __private . generateCacheKey ( 'eth_getLogs' , args ) ;
228
228
expect ( result ) . to . equal ( 'eth_getLogs_fromBlock_earliest_toBlock_5644' ) ;
229
229
} ) ;
230
230
@@ -235,28 +235,28 @@ describe('cache decorator', () => {
235
235
} ;
236
236
const args = [ mockRequestDetails , 'earliest' ] as unknown as IArguments ;
237
237
238
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_call' , args ) ;
238
+ const result = __test__ . __private . generateCacheKey ( 'eth_call' , args ) ;
239
239
expect ( result ) . to . equal ( 'eth_call_earliest' ) ;
240
240
} ) ;
241
241
242
242
it ( 'should not skip null or undefined args' , ( ) => {
243
243
const args = [ undefined , null , 'pending' ] as unknown as IArguments ;
244
244
245
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_call' , args ) ;
245
+ const result = __test__ . __private . generateCacheKey ( 'eth_call' , args ) ;
246
246
expect ( result ) . to . equal ( 'eth_call_undefined_null_pending' ) ;
247
247
} ) ;
248
248
249
249
it ( 'should process multiple arguments correctly' , ( ) => {
250
250
const args = [ { fromBlock : '0xabc' } , 5644 , 'safe' ] as unknown as IArguments ;
251
251
252
- const result = CacheHelper [ ' generateCacheKey' ] ( 'eth_getLogs' , args ) ;
252
+ const result = __test__ . __private . generateCacheKey ( 'eth_getLogs' , args ) ;
253
253
expect ( result ) . to . equal ( 'eth_getLogs_fromBlock_0xabc_5644_safe' ) ;
254
254
} ) ;
255
255
256
256
it ( 'should work with mixed types including booleans and numbers' , ( ) => {
257
257
const args = [ true , 42 , { fromBlock : 'safe' } ] as unknown as IArguments ;
258
258
259
- const result = CacheHelper [ ' generateCacheKey' ] ( 'custom_method' , args ) ;
259
+ const result = __test__ . __private . generateCacheKey ( 'custom_method' , args ) ;
260
260
expect ( result ) . to . equal ( 'custom_method_true_42_fromBlock_safe' ) ;
261
261
} ) ;
262
262
} ) ;
@@ -266,23 +266,23 @@ describe('cache decorator', () => {
266
266
const requestDetails = new RequestDetails ( { requestId : 'abc123' , ipAddress : '127.0.0.1' } ) ;
267
267
const args = [ 5644 , requestDetails , 'other' ] as unknown as IArguments ;
268
268
269
- const result = CacheHelper [ ' extractRequestDetails' ] ( args ) ;
269
+ const result = __test__ . __private . extractRequestDetails ( args ) ;
270
270
expect ( result . requestId ) . to . equal ( 'abc123' ) ;
271
271
expect ( result . ipAddress ) . to . equal ( '127.0.0.1' ) ;
272
272
} ) ;
273
273
274
274
it ( 'should return a new default RequestDetails if not found' , ( ) => {
275
275
const args = [ 5644 , { fromBlock : 'pending' } , 'value' ] as unknown as IArguments ;
276
276
277
- const result = CacheHelper [ ' extractRequestDetails' ] ( args ) ;
277
+ const result = __test__ . __private . extractRequestDetails ( args ) ;
278
278
expect ( result . requestId ) . to . equal ( '' ) ;
279
279
expect ( result . ipAddress ) . to . equal ( '' ) ;
280
280
} ) ;
281
281
282
282
it ( 'should return new RequestDetails when args is empty' , ( ) => {
283
283
const args = [ ] as unknown as IArguments ;
284
284
285
- const result = CacheHelper [ ' extractRequestDetails' ] ( args ) ;
285
+ const result = __test__ . __private . extractRequestDetails ( args ) ;
286
286
expect ( result . requestId ) . to . equal ( '' ) ;
287
287
expect ( result . ipAddress ) . to . equal ( '' ) ;
288
288
} ) ;
@@ -292,14 +292,14 @@ describe('cache decorator', () => {
292
292
const rd2 = new RequestDetails ( { requestId : 'second' , ipAddress : '2.2.2.2' } ) ;
293
293
const args = [ rd1 , rd2 ] as unknown as IArguments ;
294
294
295
- const result = CacheHelper [ ' extractRequestDetails' ] ( args ) ;
295
+ const result = __test__ . __private . extractRequestDetails ( args ) ;
296
296
expect ( result ) . to . equal ( rd1 ) ;
297
297
} ) ;
298
298
299
299
it ( 'should handle null or undefined values in args' , ( ) => {
300
300
const args = [ undefined , null , 5644 ] as unknown as IArguments ;
301
301
302
- const result = CacheHelper [ ' extractRequestDetails' ] ( args ) ;
302
+ const result = __test__ . __private . extractRequestDetails ( args ) ;
303
303
expect ( result . requestId ) . to . equal ( '' ) ;
304
304
expect ( result . ipAddress ) . to . equal ( '' ) ;
305
305
} ) ;
0 commit comments