Skip to content

Commit 8c284c6

Browse files
committed
chore: fix tests
Signed-off-by: nikolay <n.atanasow94@gmail.com>
1 parent 4fc87e5 commit 8c284c6

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

packages/relay/src/lib/decorators/cache.decorator.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,31 @@ import { RequestDetails } from '../types';
44
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
55
import { CacheService } from '../services/cacheService/cacheService';
66

7+
interface CacheSingleParam {
8+
index: string,
9+
value: string
10+
}
11+
12+
interface CacheNamedParam {
13+
name: string,
14+
value: string
15+
}
16+
17+
interface CacheNamedParams {
18+
index: string,
19+
fields: CacheNamedParam[]
20+
}
21+
22+
interface CacheOptions {
23+
skipParams?: CacheSingleParam[],
24+
skipNamedParams?: CacheNamedParams[],
25+
ttl?: number,
26+
}
27+
728
const shouldSkipCachingForSingleParams = (args: any, params: any = []) => {
829
for (const item of params) {
9-
if (args[item.index] == item.value) {
30+
const values = item.value.split('|');
31+
if (values.indexOf(args[item.index]) > -1) {
1032
return true;
1133
}
1234
}
@@ -22,7 +44,8 @@ const shouldSkipCachingForNamedParams = (args: any, params: any = []) => {
2244
}));
2345

2446
for (const [key, value] of Object.entries(skipList)) {
25-
if (input[key] == value) {
47+
const values = (value as string).split('|');
48+
if (values.indexOf(input[key]) > -1) {
2649
return true;
2750
}
2851
}
@@ -63,27 +86,6 @@ const extractRequestDetails = (args: any): RequestDetails => {
6386
return new RequestDetails({ requestId, ipAddress, connectionId });
6487
};
6588

66-
interface CacheSingleParam {
67-
index: string,
68-
value: string
69-
}
70-
71-
interface CacheNamedParam {
72-
name: string,
73-
value: string
74-
}
75-
76-
interface CacheNamedParams {
77-
index: string,
78-
fields: CacheNamedParam[]
79-
}
80-
81-
interface CacheOptions {
82-
skipParams?: CacheSingleParam[],
83-
skipNamedParams?: CacheNamedParams[],
84-
ttl?: number,
85-
}
86-
8789
export function cache(cacheService: CacheService, options: CacheOptions = {}) {
8890
return function(_target: any, _propertyKey: string, descriptor: PropertyDescriptor) {
8991
const method = descriptor.value;

packages/relay/src/lib/eth.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class EthImpl implements Eth {
174174
})
175175
@rpcParamLayoutConfig(RPC_LAYOUT.custom((params) => [Number(params[0]), params[1], params[2]]))
176176
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
177-
skipParams: [{ index: '2', value: 'latest' }],
177+
skipParams: [{ index: '2', value: 'latest|pending|finalized|safe' }],
178178
ttl: constants.CACHE_TTL.FIFTEEN_MINUTES,
179179
})
180180
async feeHistory(
@@ -679,7 +679,7 @@ export class EthImpl implements Eth {
679679
})
680680
@rpcParamLayoutConfig(RPC_LAYOUT.custom((params) => [params[0], params[1], params[2]]))
681681
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
682-
skipParams: [{ index: '2', value: 'latest' }],
682+
skipParams: [{ index: '2', value: 'latest|pending|finalized|safe' }],
683683
})
684684
async getStorageAt(
685685
address: string,
@@ -708,7 +708,7 @@ export class EthImpl implements Eth {
708708
1: { type: ParamType.BLOCK_NUMBER_OR_HASH, required: true },
709709
})
710710
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
711-
skipParams: [{ index: '1', value: 'latest' }],
711+
skipParams: [{ index: '1', value: 'latest|pending|finalized|safe' }],
712712
})
713713
async getBalance(
714714
account: string,
@@ -736,7 +736,7 @@ export class EthImpl implements Eth {
736736
1: { type: ParamType.BLOCK_NUMBER_OR_HASH, required: true },
737737
})
738738
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
739-
skipParams: [{ index: '1', value: 'latest' }],
739+
skipParams: [{ index: '1', value: 'latest|pending|finalized|safe' }],
740740
})
741741
public async getCode(
742742
address: string,
@@ -801,7 +801,7 @@ export class EthImpl implements Eth {
801801
0: { type: ParamType.BLOCK_NUMBER, required: true },
802802
})
803803
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
804-
skipParams: [{ index: '0', value: 'latest' }],
804+
skipParams: [{ index: '0', value: 'latest|pending|finalized|safe' }],
805805
})
806806
async getBlockTransactionCountByNumber(
807807
blockNumOrTag: string,
@@ -852,7 +852,7 @@ export class EthImpl implements Eth {
852852
1: { type: ParamType.HEX, required: true },
853853
})
854854
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
855-
skipParams: [{ index: '0', value: 'latest' }],
855+
skipParams: [{ index: '0', value: 'latest|pending|finalized|safe' }],
856856
})
857857
async getTransactionByBlockNumberAndIndex(
858858
blockNumOrTag: string,
@@ -883,7 +883,7 @@ export class EthImpl implements Eth {
883883
1: { type: ParamType.BOOLEAN, required: true },
884884
})
885885
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
886-
skipParams: [{ index: '0', value: 'latest' }],
886+
skipParams: [{ index: '0', value: 'latest|pending|finalized|safe' }],
887887
})
888888
async getBlockByNumber(
889889
blockNumOrTag: string,
@@ -1058,8 +1058,8 @@ export class EthImpl implements Eth {
10581058
{
10591059
index: '0',
10601060
fields: [
1061-
{ name: 'fromBlock', value: 'latest' },
1062-
{ name: 'toBlock', value: 'latest' },
1061+
{ name: 'fromBlock', value: 'latest|pending|finalized|safe' },
1062+
{ name: 'toBlock', value: 'latest|pending|finalized|safe' },
10631063
],
10641064
},
10651065
],
@@ -1102,7 +1102,7 @@ export class EthImpl implements Eth {
11021102
0: { type: ParamType.BLOCK_NUMBER_OR_HASH, required: true },
11031103
})
11041104
@cache(CacheService.getInstance(CACHE_LEVEL.L1), {
1105-
skipParams: [{ index: '0', value: 'latest' }],
1105+
skipParams: [{ index: '0', value: 'latest|pending|finalized|safe' }],
11061106
})
11071107
public async getBlockReceipts(blockHashOrBlockNumber: string, requestDetails: RequestDetails): Promise<Receipt[]> {
11081108
return await this.blockService.getBlockReceipts(blockHashOrBlockNumber, requestDetails);

0 commit comments

Comments
 (0)