This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 682
fix: add support for mergeForkIdTransition
#4463
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
20167dc
upgrade @ethereumjs/common to 3.1.2
jeffsmale90 4ffc97f
WIP - resolve common from blocknumber+timestamp, where it's not avail…
jeffsmale90 4717d19
One less place that we fetch the block to resolve the common
jeffsmale90 bd80d60
Shuffle around transaction serialization logic so that we don't need …
jeffsmale90 ae13677
Revert those silly package-lock files
jeffsmale90 e99e7f0
Assume rpc transaction has gasPrice set, even for EIP-1559 Fee Market…
jeffsmale90 b29117a
Revert ethereumjs upgrade, because it does not support nodejs v14.0 :(
jeffsmale90 44405b7
Add tests for resolving Common by blocknumber and timestamp
jeffsmale90 8093a75
Only tidy ups
jeffsmale90 6bbc42b
Add tests for transaction serialization
jeffsmale90 668d1c3
Extend those transaction serialization tests
jeffsmale90 c6b824a
tidy up
jeffsmale90 2612412
Add mergeForkIdTransition hardfork
jeffsmale90 ca9509c
Merge branch 'develop' into fix/mergeForkIdTransition
jeffsmale90 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
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
130 changes: 130 additions & 0 deletions
130
src/chains/ethereum/ethereum/tests/forking/fork.test.ts
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,130 @@ | ||
| import { EthereumOptionsConfig } from "@ganache/ethereum-options"; | ||
| import { Fork } from "../../src/forking/fork"; | ||
| import { KNOWN_CHAINIDS, Quantity } from "@ganache/utils"; | ||
| import { Common } from "@ethereumjs/common/dist/common"; | ||
| import ganache from "../../../../../packages/core"; | ||
| import Server from "../../../../../packages/core/lib/src/server"; | ||
| import assert from "assert"; | ||
| import { logging } from "./helpers"; | ||
|
|
||
| describe("Fork", () => { | ||
| const port = 9999; | ||
| const networkId = 1; | ||
| const accounts = []; | ||
| const forkOptions = { | ||
| fork: { | ||
| url: `http://localhost:${port}` | ||
| }, | ||
| logging | ||
| }; | ||
|
|
||
| let remoteServer: Server; | ||
| let fork: Fork; | ||
|
|
||
| before(async () => { | ||
| remoteServer = ganache.server({ | ||
| wallet: { deterministic: true }, | ||
| chain: { networkId: networkId }, | ||
| logging | ||
| }); | ||
| await remoteServer.listen(port); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| const providerOptions = EthereumOptionsConfig.normalize(forkOptions); | ||
| fork = new Fork(providerOptions, accounts); | ||
| await fork.initialize(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await fork.close(); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await remoteServer.close(); | ||
| }); | ||
|
|
||
| describe("getCommonForBlock()", () => { | ||
| it("should return a Common for known chainIds", () => { | ||
| KNOWN_CHAINIDS.forEach(chainId => { | ||
| if (chainId === 42) { | ||
| // Skip kovan, because it is no longer supported by ethereumjs. To be | ||
| // removed in https://github.com/trufflesuite/ganache/issues/4461 | ||
| } else { | ||
| assert.doesNotThrow(() => { | ||
| const parentCommon = new Common({ chain: chainId }); | ||
|
|
||
| fork.getCommonForBlock(parentCommon, { | ||
| number: 0n, | ||
| timestamp: 0n | ||
| }); | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it("should resolve the correct hardfork based on block number for known chainId", () => { | ||
| const mainnet = 1; | ||
| const mergeBlocknumber = 15537394n; | ||
|
|
||
| // ensure that the fork blockNumber is after the merge blockNumber | ||
| fork.blockNumber = Quantity.from(mergeBlocknumber + 100n); | ||
| fork.chainId = mainnet; | ||
|
|
||
| const parentCommon = new Common({ chain: mainnet }); | ||
| const blocknumberToHardfork: [bigint, string][] = [ | ||
| [mergeBlocknumber - 1n, "grayGlacier"], | ||
| [mergeBlocknumber, "merge"], | ||
| [mergeBlocknumber + 1n, "merge"] | ||
| ]; | ||
|
|
||
| blocknumberToHardfork.forEach(([number, expectedHardfork]) => { | ||
| const common = fork.getCommonForBlock(parentCommon, { | ||
| number, // the block at which paris is scheduled | ||
| timestamp: 0n | ||
| }); | ||
|
|
||
| const hf = common.hardfork(); | ||
|
|
||
| assert.strictEqual( | ||
| hf, | ||
| expectedHardfork, | ||
| `Unexpected hardfork with blocknumber: ${number}` | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it("should resolve the correct hardfork based on timestamp for known chainId", () => { | ||
| // we use sepolia because it has shanghai hf scheduled | ||
| const sepolia = 11155111; | ||
| const shanghaiTimestamp = 1677557088n; | ||
| const mergeForkIdTransitionBlockNumber = 1735371n; | ||
|
|
||
| // ensure that the fork blockNumber is after the mergeForkIdTransition blockNumber | ||
| fork.blockNumber = Quantity.from(mergeForkIdTransitionBlockNumber + 100n); | ||
| fork.chainId = sepolia; | ||
|
|
||
| const timstampToHardfork: [bigint, string][] = [ | ||
| [shanghaiTimestamp - 1n, "mergeForkIdTransition"], | ||
| [shanghaiTimestamp, "shanghai"], | ||
| [shanghaiTimestamp + 1n, "shanghai"] | ||
| ]; | ||
|
|
||
| const parentCommon = new Common({ chain: sepolia }); | ||
| timstampToHardfork.forEach(([timestamp, expectedHardfork]) => { | ||
| const common = fork.getCommonForBlock(parentCommon, { | ||
| number: mergeForkIdTransitionBlockNumber, | ||
| timestamp | ||
| }); | ||
|
|
||
| const hf = common.hardfork(); | ||
|
|
||
| assert.strictEqual( | ||
| hf, | ||
| expectedHardfork, | ||
| `Unexpected hardfork with timestamp: ${timestamp}` | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,5 @@ export type Hardfork = | |
| | "arrowGlacier" | ||
| | "grayGlacier" | ||
| | "merge" | ||
| | "mergeForkIdTransition" | ||
| | "shanghai"; | ||
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.
Whats this about paris?
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.
apologies, the base branch was wrong here - as it depends on #4455 where I've fixed this, along with a minor change to the above comment https://github.com/trufflesuite/ganache/pull/4455/files/cb95798713916bda17494b7129aa8eb99220a786..163c987b7d9dbdf24eee0cc5569af085cf318989