Skip to content
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

feat: Add loadAllocs cheatcode #6101

Closed
wants to merge 5 commits into from
Closed

feat: Add loadAllocs cheatcode #6101

wants to merge 5 commits into from

Conversation

clabby
Copy link
Contributor

@clabby clabby commented Oct 25, 2023

Overview

Introduces a new cheatcode, loadAllocs, which allows for directly inserting accounts into the in-memory revm state from an allocs section of a standard genesis.json file.

Motivation

Several Layer 2s, including Optimism, allocate many proxies etc. in the genesis file. For example, take Base Mainnet's 8.76MB genesis file.

While it is possible to deploy all of these contracts manually in a test file's setUp function, it is slow, cumbersome, and rather easy to accidentally break parity.

Solution

To allow for quicker and more ergonomic test setups in situations like the above, I've added a new loadAllocs cheatcode. This takes a path to a JSON file containing only the allocs object within a standard genesis.json, and directly inserts these accounts into revm's journal.

Alloc File Schema

The alloc file is simply the allocs section of a standard Genesis JSON file - that is, HashMap<Address, GenesisAccount>, where GenesisAccount is defined in ethers-rs as:

/// An account in the state of the genesis block.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct GenesisAccount {
    #[serde(
        skip_serializing_if = "Option::is_none",
        deserialize_with = "deserialize_stringified_u64_opt",
        default
    )]
    pub nonce: Option<u64>,
    #[serde(deserialize_with = "deserialize_stringified_numeric")]
    pub balance: U256,
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub code: Option<Bytes>,
    #[serde(
        skip_serializing_if = "Option::is_none",
        deserialize_with = "from_unformatted_hex_map",
        default
    )]
    pub storage: Option<HashMap<H256, H256>>,
}

Testing

Accompanying tests for the new cheatcode have been added in testdata.

Metadata
closes #6126

.load_allocs(&allocs, &mut ccx.data.journaled_state)
.map(|_| Vec::default())
.map_err(|e| fmt_err!("Failed to load allocs: {e}"))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please keep style consistent with the rest of the cheatcodes here? Self destructure at the top and lowercase error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This folder does not exist anymore

@Evalir
Copy link
Member

Evalir commented Nov 3, 2023

Closing in favor of #6207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Genesis Account Allocations cheatcode
3 participants