Skip to content

Commit

Permalink
fix getting old block issue (#931)
Browse files Browse the repository at this point in the history
* fix types bundle

* update

* add test

* test latest types bundle

* fix lint

* please work

* test

* fix

* fix

* update

* types 6.0.8

* use more descriptive name

* use latest types
  • Loading branch information
shunjizhan authored Jan 24, 2024
1 parent 513294f commit 93e8fc3
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/eth-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test:e2e": "vitest --run --config vitest.config.e2e.ts"
},
"peerDependencies": {
"@acala-network/api": "~6.0.5",
"@acala-network/api": "6.1.0",
"@polkadot/api": "^10.11.1"
},
"dependencies": {
Expand All @@ -23,7 +23,7 @@
"lru-cache": "~7.8.2"
},
"devDependencies": {
"@acala-network/api": "~6.0.5",
"@acala-network/api": "6.1.0",
"@types/bn.js": "~5.1.0",
"@types/lru-cache": "~7.6.1",
"dotenv": "~10.0.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/eth-providers/src/rpc-provider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { options } from '@acala-network/api';

import { ApiPromise, WsProvider } from '@polkadot/api';
import { withAcalaTypes } from '@acala-network/api';

import { BaseProvider, BaseProviderOptions } from './base-provider';

export class EvmRpcProvider extends BaseProvider {
constructor(endpoint: string | string[], opts?: BaseProviderOptions) {
super(opts);

const provider = new WsProvider(endpoint);
const api = new ApiPromise(options({ provider }));
const api = new ApiPromise(withAcalaTypes({
provider: new WsProvider(endpoint),
}));

this.setApi(api);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`endpoint > eth_getBlockByNumber > for very old runtime 1`] = `
{
"difficulty": "0x0",
"extraData": "0x",
"gasLimit": "0x1c99c80",
"gasUsed": "0x0",
"hash": "0x000643ffd6bbb04682ae1675e2e478e4c8ecd7c7b9d7e9d1eafe1b6095f751e3",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x8ce1cab8e0d55252720728bc495d05841ea3dc23",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0x5ae2c",
"parentHash": "0xe2ebe9eb139f9bc88862615f6a0c5095417595a0f80bd4f7f94c1c3753499973",
"receiptsRoot": "0xd3596ebbbb67ac571735047e856cecb63f3d8a519af4699ecc4505de59d570e5",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0xa80",
"stateRoot": "0xd440bfe07178304657083255758ec74358a3ed592720a8484015d1d89950e81e",
"timestamp": "0x611f2b1e",
"totalDifficulty": "0x0",
"transactions": [],
"transactionsRoot": "0xd3596ebbbb67ac571735047e856cecb63f3d8a519af4699ecc4505de59d570e5",
"uncles": [],
}
`;

exports[`endpoint > eth_getBlockByNumber > for very old runtime 2`] = `
{
"difficulty": "0x0",
"extraData": "0x",
"gasLimit": "0x1c99c80",
"gasUsed": "0x0",
"hash": "0x000643ffd6bbb04682ae1675e2e478e4c8ecd7c7b9d7e9d1eafe1b6095f751e3",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x8ce1cab8e0d55252720728bc495d05841ea3dc23",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0x5ae2c",
"parentHash": "0xe2ebe9eb139f9bc88862615f6a0c5095417595a0f80bd4f7f94c1c3753499973",
"receiptsRoot": "0xd3596ebbbb67ac571735047e856cecb63f3d8a519af4699ecc4505de59d570e5",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0xa80",
"stateRoot": "0xd440bfe07178304657083255758ec74358a3ed592720a8484015d1d89950e81e",
"timestamp": "0x611f2b1e",
"totalDifficulty": "0x0",
"transactions": [],
"transactionsRoot": "0xd3596ebbbb67ac571735047e856cecb63f3d8a519af4699ecc4505de59d570e5",
"uncles": [],
}
`;

exports[`endpoint > eth_getBlockByNumber > when there are >= 2 EVM transactions 1`] = `
{
"difficulty": "0x0",
Expand Down
8 changes: 8 additions & 0 deletions packages/eth-rpc-adapter/src/__tests__/e2e/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,14 @@ describe('endpoint', () => {
expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});

it('for very old runtime', async () => {
const resFull = (await eth_getBlockByNumber_karura([372268, true])).data.result;
const res = (await eth_getBlockByNumber_karura([372268, false])).data.result;

expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});
});

describe('eth_getBalance', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/eth-rpc-adapter/src/wrapped-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { BaseProvider, BaseProviderOptions } from '@acala-network/eth-providers/base-provider';
import { options } from '@acala-network/api';
import { withAcalaTypes } from '@acala-network/api';
import tracer from 'dd-trace';

const TRACE_METHODS = [
Expand Down Expand Up @@ -85,8 +85,9 @@ export class EvmRpcProviderWithTrace extends BaseProviderWithTrace {
constructor(endpoint: string | string[], opts?: BaseProviderOptions) {
super(opts);

const provider = new WsProvider(endpoint);
const api = new ApiPromise(options({ provider }));
const api = new ApiPromise(withAcalaTypes({
provider: new WsProvider(endpoint),
}));

this.setApi(api);
}
Expand Down
34 changes: 17 additions & 17 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93e8fc3

Please sign in to comment.