Skip to content

Commit e2435dd

Browse files
authored
eth rpc adapter tests (#1032)
* subscription tests * errors test * utils refactor and eth_estimate gas tests * add retry * eth_sendTx tests * misc corner endpoints * blocktag tests * eth_call tests * fix and switch endpoint * eth_getCode tests * eth_getStorageAt tests * use retry 2 times * use dwellir node url * moved karura getblockbynumber tests to parseblock test * eth_getBlockByNumber tests * get tx and receipt tests * eth_newFilter tests * all filter family * eth_getlogs test * clean up * add retry to start test infra * cleanup * decrease test timeout
1 parent 29e56bb commit e2435dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2854
-3430
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ jobs:
3636
run: yarn install --immutable
3737

3838
- name: start test infra
39-
run: docker compose up -d
39+
uses: nick-fields/retry@v2
40+
with:
41+
timeout_minutes: 5
42+
max_attempts: 3
43+
command: docker compose up -d
4044

4145
- name: start rpc adapter for eth-providers
4246
if: matrix.project == 'eth-providers'
4347
run: yarn workspace @acala-network/eth-rpc-adapter run start:coverage
4448

49+
- name: generate typechain for eth-rpc-adapter tests
50+
if: matrix.project == 'eth-rpc-adapter'
51+
run: yarn workspace @acala-network/eth-rpc-adapter run typegen
52+
4553
- name: run tests
46-
run: yarn workspace @acala-network/${{ matrix.project }} run test:coverage
54+
uses: nick-fields/retry@v2
55+
with:
56+
timeout_minutes: 15
57+
max_attempts: 2
58+
command: yarn workspace @acala-network/${{ matrix.project }} run test:coverage
4759

4860
- name: save coverage reports
4961
uses: actions/upload-artifact@v4
@@ -85,7 +97,11 @@ jobs:
8597
run: yarn install --immutable
8698

8799
- name: start test infra
88-
run: docker compose up -d
100+
uses: nick-fields/retry@v2
101+
with:
102+
timeout_minutes: 5
103+
max_attempts: 3
104+
command: docker compose up -d
89105

90106
- name: start coverage server
91107
env:
@@ -96,7 +112,11 @@ jobs:
96112
run: cd e2e-tests/${{ matrix.project }} && yarn install --immutable
97113

98114
- name: run e2e tests
99-
run: cd e2e-tests/${{ matrix.project }} && yarn test:acalaFork
115+
uses: nick-fields/retry@v2
116+
with:
117+
timeout_minutes: 15
118+
max_attempts: 2
119+
command: cd e2e-tests/${{ matrix.project }} && yarn test:acalaFork
100120

101121
- name: stop coverage server and generate coverage report
102122
run: yarn workspace @acala-network/eth-rpc-adapter run stop:coverage

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ lib
7676
**/.yarn/install-state.gz
7777

7878
## openzeppelin cache
79-
**/.openzeppelin/
79+
**/.openzeppelin/
80+
81+
## typechain files
82+
**/types

chopsticks/configs/acala.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
endpoint: wss://acala-rpc.aca-api.network
1+
endpoint: wss://acala-rpc.dwellir.com
22
mock-signature-host: true
33
runtime-log-level: 5
44
block: 7000000

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ coverage:
1313

1414
comment:
1515
layout: "reach, diff, flags, files"
16-
behavior: default
16+
behavior: new
1717
require_changes: false
1818
require_base: false
1919
require_head: false

packages/eth-providers/src/__tests__/__snapshots__/parseBlock.test.ts.snap

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,111 @@ exports[`getAllReceiptsAtBlock > contract creation > with logs + legacy gas 1`]
363363
]
364364
`;
365365

366+
exports[`getAllReceiptsAtBlock > different evm tx count > when there are 0 EVM transactions 1`] = `[]`;
367+
368+
exports[`getAllReceiptsAtBlock > different evm tx count > when there are 1 EVM transactions 1`] = `
369+
[
370+
{
371+
"blockHash": "0xab9f0519e9f9885861da35765dad61161c5f939c66b4c4b7091f7e9555e9f92f",
372+
"blockNumber": "0x1bbf96",
373+
"contractAddress": "0x0000000000000000000000000000000000000801",
374+
"cumulativeGasUsed": "0x0",
375+
"effectiveGasPrice": "0x4ced5668c50",
376+
"from": "0x0000000000000000000000000000000000000000",
377+
"gasUsed": "0x3181f",
378+
"logs": [],
379+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
380+
"status": "0x1",
381+
"to": null,
382+
"transactionHash": "0x79090e3e64da12012839fb40f95ad03703a6d3c999c262b4196796f9753861ca",
383+
"transactionIndex": "0x0",
384+
"type": "0x0",
385+
},
386+
]
387+
`;
388+
389+
exports[`getAllReceiptsAtBlock > different evm tx count > when there are 2 EVM transactions 1`] = `
390+
[
391+
{
392+
"blockHash": "0xbdae06c67294bca57bffd390c997d6730a837e1c11252d9bba00cac7384c1f16",
393+
"blockNumber": "0x25623f",
394+
"contractAddress": null,
395+
"cumulativeGasUsed": "0x0",
396+
"effectiveGasPrice": "0x15fde28667",
397+
"from": "0x9cb3b68e0c48c53b70f465bda3ba6481a9cb7720",
398+
"gasUsed": "0x2a9f7",
399+
"logs": [
400+
{
401+
"address": "0x0000000000000000000100000000000000000084",
402+
"blockHash": "0xbdae06c67294bca57bffd390c997d6730a837e1c11252d9bba00cac7384c1f16",
403+
"blockNumber": "0x25623f",
404+
"data": "0x0000000000000000000000000000000000000000000000000001550f7dca7000",
405+
"logIndex": "0x0",
406+
"topics": [
407+
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
408+
"0x00000000000000000000000030385059196602a1498f5f8ef91f3450e3a7b27a",
409+
"0x0000000000000000000000009cb3b68e0c48c53b70f465bda3ba6481a9cb7720",
410+
],
411+
"transactionHash": "0x7b0361f47dc0be798cb9f7d115d74d68960e685714c515df81dd1a17e3db0cff",
412+
"transactionIndex": "0x0",
413+
},
414+
{
415+
"address": "0x30385059196602a1498f5f8ef91f3450e3a7b27a",
416+
"blockHash": "0xbdae06c67294bca57bffd390c997d6730a837e1c11252d9bba00cac7384c1f16",
417+
"blockNumber": "0x25623f",
418+
"data": "0x0000000000000000000000009cb3b68e0c48c53b70f465bda3ba6481a9cb77200000000000000000000000000000000000000000000000000001550f7dca70000000000000000000000000000000000000000000000000000000000062f8bc54000000000000000000000000000000000000000000000000000000000025623f0000000000000000000000009cb3b68e0c48c53b70f465bda3ba6481a9cb7720",
419+
"logIndex": "0x1",
420+
"topics": [
421+
"0xcb3fe4174668d512bcb57104a92bc21df0b8fdeb1cacc3575aa50b74a3e5ad5a",
422+
"0xeac06b4f60edb2a940a2170eea5cef018dc569f5d98b8176f5da7ea640c9bd27",
423+
"0x0000000000000000000000000000000000000000000100000000000000000084",
424+
"0x0000000000000000000000000000000000000000000000000000000000000004",
425+
],
426+
"transactionHash": "0x7b0361f47dc0be798cb9f7d115d74d68960e685714c515df81dd1a17e3db0cff",
427+
"transactionIndex": "0x0",
428+
},
429+
],
430+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
431+
"status": "0x1",
432+
"to": "0x30385059196602a1498f5f8ef91f3450e3a7b27a",
433+
"transactionHash": "0x7b0361f47dc0be798cb9f7d115d74d68960e685714c515df81dd1a17e3db0cff",
434+
"transactionIndex": "0x0",
435+
"type": "0x0",
436+
},
437+
{
438+
"blockHash": "0xbdae06c67294bca57bffd390c997d6730a837e1c11252d9bba00cac7384c1f16",
439+
"blockNumber": "0x25623f",
440+
"contractAddress": null,
441+
"cumulativeGasUsed": "0x0",
442+
"effectiveGasPrice": "0xb460f6718",
443+
"from": "0xc760da3c525c8511938c35613684c3f6175c01a5",
444+
"gasUsed": "0xc26d",
445+
"logs": [
446+
{
447+
"address": "0x1f3a10587a20114ea25ba1b388ee2dd4a337ce27",
448+
"blockHash": "0xbdae06c67294bca57bffd390c997d6730a837e1c11252d9bba00cac7384c1f16",
449+
"blockNumber": "0x25623f",
450+
"data": "0x0000000000000000000000000000000000000000000000000000000025342e5d",
451+
"logIndex": "0x0",
452+
"topics": [
453+
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
454+
"0x000000000000000000000000c760da3c525c8511938c35613684c3f6175c01a5",
455+
"0x000000000000000000000000f7abcfa42bf7e7d43d3d53c665ded80fdafb5244",
456+
],
457+
"transactionHash": "0x9824e1111ba926db7df3091ec45344f224a3086daf5580eaf7ab3e6bf5a6dde6",
458+
"transactionIndex": "0x1",
459+
},
460+
],
461+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
462+
"status": "0x1",
463+
"to": "0x1f3a10587a20114ea25ba1b388ee2dd4a337ce27",
464+
"transactionHash": "0x9824e1111ba926db7df3091ec45344f224a3086daf5580eaf7ab3e6bf5a6dde6",
465+
"transactionIndex": "0x1",
466+
"type": "0x0",
467+
},
468+
]
469+
`;
470+
366471
exports[`getAllReceiptsAtBlock > erc20 XCM > basic xcm 1`] = `
367472
[
368473
{

packages/eth-providers/src/__tests__/evm-rpc-provider.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { EvmRpcProvider } from '../rpc-provider';
2-
import { afterAll, describe, expect, it } from 'vitest';
2+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
33
import { runWithTiming, sleep } from '../utils';
44
import dotenv from 'dotenv';
55

66
dotenv.config();
77

8-
const ACALA_NODE_URL = 'wss://acala-rpc.aca-api.network';
8+
const ACALA_NODE_URL = 'wss://acala-rpc.dwellir.com';
99
const ACALA_SUBQL = 'https://subql-query-acala.aca-api.network';
1010
const endpoint = process.env.ENDPOINT_URL || 'ws://127.0.0.1:9944';
1111

@@ -98,10 +98,12 @@ describe.skip('all cache', async () => {
9898

9999
describe.concurrent('rpc test', async () => {
100100
const provider = EvmRpcProvider.from(endpoint);
101-
await provider.isReady();
101+
102+
beforeAll(async () => {
103+
await provider.isReady();
104+
});
102105

103106
afterAll(async () => {
104-
await sleep(5000);
105107
await provider.disconnect();
106108
});
107109

packages/eth-providers/src/__tests__/parseBlock.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe.concurrent('getAllReceiptsAtBlock', () => {
4949
beforeAll(async () => {
5050
console.log('connecting to node...');
5151
const KARURA_NODE_URL = 'wss://karura-rpc.aca-api.network';
52-
const ACALA_NODE_URL = 'wss://acala-rpc.aca-api.network';
52+
const ACALA_NODE_URL = 'wss://acala-rpc.dwellir.com';
5353

5454
apiK = new ApiPromise(
5555
options({
@@ -72,7 +72,6 @@ describe.concurrent('getAllReceiptsAtBlock', () => {
7272
});
7373

7474
afterAll(async () => {
75-
await sleep(10_000);
7675
await apiK.disconnect();
7776
await apiA.disconnect();
7877
});
@@ -199,6 +198,32 @@ describe.concurrent('getAllReceiptsAtBlock', () => {
199198
});
200199
});
201200

201+
describe.concurrent('different evm tx count', () => {
202+
it('when there are 0 EVM transactions', async ({ expect }) => {
203+
const blockNumber = 1818188;
204+
const receipts = await getAllReceiptsAtBlockNumber(apiK, blockNumber);
205+
206+
expect(receipts.length).to.equal(0);
207+
expect(receipts).toMatchSnapshot();
208+
});
209+
210+
it('when there are 1 EVM transactions', async ({ expect }) => {
211+
const blockNumber = 1818518;
212+
const receipts = await getAllReceiptsAtBlockNumber(apiK, blockNumber);
213+
214+
expect(receipts.length).to.equal(1);
215+
expect(receipts).toMatchSnapshot();
216+
});
217+
218+
it('when there are 2 EVM transactions', async ({ expect }) => {
219+
const blockNumber = 2449983;
220+
const receipts = await getAllReceiptsAtBlockNumber(apiK, blockNumber);
221+
222+
expect(receipts.length).to.equal(2);
223+
expect(receipts).toMatchSnapshot();
224+
});
225+
});
226+
202227
describe.concurrent.skip('other types', () => {
203228
// it('failed EVM extrinsic - 0 gasLimit', async ({ expect }) => {
204229
// // TODO: construct a similar one on karura

packages/eth-providers/src/base-provider.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,6 @@ export abstract class BaseProvider extends AbstractProvider {
17011701
return sortedReceipts?.[receiptIdx] ? subqlReceiptAdapter(sortedReceipts[receiptIdx]) : null;
17021702
};
17031703

1704-
// TODO: test pending
17051704
_getPendingTX = async (txHash: string): Promise<TX | null> => {
17061705
const pendingExtrinsics = await this.api.rpc.author.pendingExtrinsics();
17071706
const targetExtrinsic = pendingExtrinsics.find(ex => ex.hash.toHex() === txHash);
@@ -1827,7 +1826,8 @@ export abstract class BaseProvider extends AbstractProvider {
18271826
.map(this.blockCache.getLogsAtBlock.bind(this))
18281827
.flat()
18291828
.filter(log => filterLogByBlockNumber(log, filter.fromBlock, filter.toBlock))
1830-
.filter(log => filterLogByAddress(log, filter.address));
1829+
.filter(log => filterLogByAddress(log, filter.address))
1830+
.filter(log => filterLogByTopics(log, filter.topics));
18311831
};
18321832

18331833
// Bloom-filter Queries
@@ -2071,19 +2071,13 @@ export abstract class BaseProvider extends AbstractProvider {
20712071
toBlock: effectiveTo,
20722072
};
20732073

2074-
if (!this.subql) {
2075-
return logger.throwError(
2076-
'missing subql url to fetch logs, to initialize base provider with subql, please provide a subqlUrl param.'
2077-
);
2078-
}
2079-
20802074
filterInfo.lastPollBlockNumber = curBlockNumber;
20812075
filterInfo.lastPollTimestamp = Date.now();
20822076

2083-
const subqlLogs = await this.subql.getFilteredLogs(effectiveFilter); // FIXME: this misses unfinalized logs
2084-
const filteredLogs = subqlLogs.filter(log => filterLogByTopics(log, sanitizedFilter.topics));
2077+
const logs = await this.getLogs(effectiveFilter);
2078+
const formattedLogs = logs.map(log => this.formatter.filterLog(log));
20852079

2086-
return hexlifyRpcResult(filteredLogs.map(log => this.formatter.filterLog(log)));
2080+
return hexlifyRpcResult(formattedLogs);
20872081
};
20882082

20892083
_pollBlocks = async (filterInfo: BlockPollFilter): Promise<string[]> => {
@@ -2110,7 +2104,9 @@ export abstract class BaseProvider extends AbstractProvider {
21102104
}
21112105

21122106
// TODO: TS bug?? why filterInfo type is not BlockPollFilter | LogPollFilter
2113-
return filterInfo['logFilter'] ? this._pollLogs(filterInfo as LogPollFilter) : this._pollBlocks(filterInfo);
2107+
return filterInfo['logFilter']
2108+
? this._pollLogs(filterInfo as LogPollFilter)
2109+
: this._pollBlocks(filterInfo as BlockPollFilter);
21142110
};
21152111

21162112
removePollFilter = (id: string): boolean => {

packages/eth-rpc-adapter/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
"scripts": {
88
"build": "tsc",
99
"ncc:pack": "ncc build src/index.ts -t --target es2020",
10-
"dev": "ts-node-dev -T -r tsconfig-paths/register src/index.ts -l | pino-pretty --singleLine --colorize --ignore time,hostname,jsonrpc,dd",
10+
"typegen": "typechain --target=ethers-v5 --out-dir=./src/__tests__/types src/__tests__/abis/*.json",
11+
"dev": "ts-node-dev -T -r tsconfig-paths/register src/index.ts | pino-pretty --singleLine --colorize --ignore time,hostname,jsonrpc,dd",
1112
"clean": "rm -rf tsconfig.tsbuildinfo .nyc_output coverage/ lib/",
1213
"health-check": "./scripts/health-check.sh",
1314
"start": "ts-node -r tsconfig-paths/register src/index.ts",
1415
"start:coverage": "COVERAGE_DIR=${COVERAGE_DIR:-eth-rpc-adapter/coverage} pm2 start --name eth-rpc 'nyc --report-dir=$COVERAGE_DIR node -r ts-node/register -r tsconfig-paths/register src/index.ts' && yarn health-check",
1516
"stop:coverage": "pm2 stop eth-rpc && pm2 delete eth-rpc",
16-
"test": "vitest",
17+
"test": "vitest --no-file-parallelism",
1718
"test:coverage": "COVERAGE_DIR=${COVERAGE_DIR:-eth-rpc-adapter/coverage} yarn start:coverage && COVERAGE_DIR=${COVERAGE_DIR:-eth-rpc-adapter/coverage} yarn test --run && yarn stop:coverage"
1819
},
1920
"peerDependencies": {
@@ -47,6 +48,7 @@
4748
"pm2": "^5.4.2",
4849
"ts-node": "^10.9.1",
4950
"ts-node-dev": "^2.0.0",
51+
"typechain": "^8.3.2",
5052
"vitest": "^2.1.1"
5153
},
5254
"files": [

0 commit comments

Comments
 (0)