-
-
Notifications
You must be signed in to change notification settings - Fork 478
Add eth_getCode support to prover #5364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d5293d
Add eth_getCode support for the prover
nazarhussain 99462a6
Move some functions to a utility file
nazarhussain 254dc20
Add more unit tests
nazarhussain d6838be
Add unit test for getCode
nazarhussain 14df5f8
Cleanup fixture files
nazarhussain 7539f90
Update the tsconfig
nazarhussain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* eslint-disable no-console */ | ||
| import {writeFile, mkdir} from "node:fs/promises"; | ||
| import path from "node:path"; | ||
| import url from "node:url"; | ||
| // eslint-disable-next-line import/no-extraneous-dependencies | ||
| import axios from "axios"; | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| const __filename = url.fileURLToPath(import.meta.url); | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); | ||
|
|
||
| type NETWORK = "sepolia" | "mainnet"; | ||
| const networkURLs: Record<NETWORK, {beacon: string; rpc: string}> = { | ||
| sepolia: { | ||
| beacon: "https://lodestar-sepolia.chainsafe.io", | ||
| rpc: "https://lodestar-sepoliarpc.chainsafe.io", | ||
| }, | ||
| mainnet: { | ||
| beacon: "https://lodestar-mainnet.chainsafe.io", | ||
| rpc: "https://lodestar-mainnetrpc.chainsafe.io", | ||
| }, | ||
| }; | ||
|
|
||
| let idIndex = Math.floor(Math.random() * 1000000); | ||
|
|
||
| async function rawEth(network: NETWORK, payload: Record<string, unknown>): Promise<Record<string, unknown>> { | ||
| return (await axios({url: networkURLs[network].rpc, method: "post", data: payload, responseType: "json"})) | ||
| .data as Record<string, unknown>; | ||
| } | ||
|
|
||
| async function rawBeacon(network: NETWORK, path: string): Promise<Record<string, unknown>> { | ||
| return (await axios.get(`${networkURLs[network].beacon}/${path}`)).data as Record<string, unknown>; | ||
| } | ||
|
|
||
| async function generateFixture( | ||
| label: string, | ||
| {method, params}: {method: string; params: unknown[]}, | ||
| {slot}: {slot: number | string}, | ||
| network: NETWORK = "sepolia" | ||
| ): Promise<void> { | ||
| const request = {id: idIndex++, jsonrpc: "2.0", method, params}; | ||
| const response = await rawEth(network, request); | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any | ||
| const executionPayload: unknown = ((await rawBeacon(network, `eth/v2/beacon/blocks/${slot}`)) as any).data.message | ||
| .body.execution_payload; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any | ||
| const headers: unknown = ((await rawBeacon(network, `eth/v1/beacon/headers/${slot}`)) as any).data; | ||
|
|
||
| if (response.error || !response.result) { | ||
| throw new Error("Invalid response" + JSON.stringify(response)); | ||
| } | ||
|
|
||
| const fixture = { | ||
| label, | ||
| network, | ||
| request, | ||
| response, | ||
| executionPayload, | ||
| headers, | ||
| }; | ||
|
|
||
| const dir = path.join(__dirname, "..", "test/fixtures", network); | ||
| await mkdir(dir, {recursive: true}); | ||
| await writeFile(path.join(dir, `${label}.json`), JSON.stringify(fixture, null, 2)); | ||
|
|
||
| console.info("Generated fixture:", label); | ||
| } | ||
|
|
||
| await generateFixture( | ||
| "eth_getBlock_with_no_accessList", | ||
| { | ||
| method: "eth_getBlockByHash", | ||
| params: ["0x75b10426177f0f4bd8683999e2c7c597007c6e7c4551d6336c0f880b12c6f3bf", true], | ||
| }, | ||
| {slot: 2144468} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBlock_with_contractCreation", | ||
| { | ||
| method: "eth_getBlockByHash", | ||
| params: ["0x3a0225b38d5927a37cc95fd48254e83c4e9b70115918a103d9fd7e36464030d4", true], | ||
| }, | ||
| {slot: 625024} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBalance_eoa", | ||
| {method: "eth_getBalance", params: ["0xC4bFccB1668d6E464F33a76baDD8C8D7D341e04A", "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBalance_eoa", | ||
| {method: "eth_getBalance", params: ["0xC4bFccB1668d6E464F33a76baDD8C8D7D341e04A", "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBalance_eoa_proof", | ||
| {method: "eth_getProof", params: ["0xC4bFccB1668d6E464F33a76baDD8C8D7D341e04A", [], "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBalance_contract", | ||
| {method: "eth_getBalance", params: ["0xa54aeF0dAB669e8e1A164BCcB323549a818a0497", "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getBalance_contract_proof", | ||
| {method: "eth_getProof", params: ["0xa54aeF0dAB669e8e1A164BCcB323549a818a0497", [], "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
|
|
||
| await generateFixture( | ||
| "eth_getCode", | ||
| {method: "eth_getCode", params: ["0xa54aeF0dAB669e8e1A164BCcB323549a818a0497", "latest"]}, | ||
| {slot: "head"} | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this disable necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It requires to specify
axiosand few other packages asdependencies, while we just need it for development. So why had to disable this.