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: configurable e2e setup #87

Merged
merged 30 commits into from
Jul 18, 2024
Merged

Conversation

segfault-magnet
Copy link
Contributor

related to: #84
closes: #86

To run e2e tests from now on you have to have fuel-core and foundry in your PATH.

The e2e test rn:

    async fn submitted_correct_block_and_was_finalized() -> Result<()> {
        // given
        let show_logs = true;
        let stack = WholeStack::deploy_default(show_logs).await?;

        // when
        stack
            .fuel_node
            .client()
            .produce_blocks(stack.deployed_contract.blocks_per_commit_interval())
            .await?;

        // then
        stack
            .committer
            .wait_for_committed_block(stack.deployed_contract.blocks_per_commit_interval() as u64)
            .await?;
        let committed_at = tokio::time::Instant::now();

        sleep_until(committed_at + stack.deployed_contract.duration_to_finalize()).await;

        let latest_block = stack.fuel_node.client().latest_block().await?;

        let validated_block =
            BlockValidator::new(stack.fuel_node.consensus_pub_key()).validate(&latest_block)?;

        assert!(stack.deployed_contract.finalized(validated_block).await?);

        Ok(())
    }

How it works

Build phase

In the build phase of e2e we're downloading a zip of fuel-bridge and extracting the FuelChainState.sol.

We then initialize a foundry project, add the required deps and compile the contract.

The artifacts are stored in the target directory. If you change the revision of fuel-bridge used or do a cargo clean this process is repeated.

Usage in tests

Each service is now a structure. Running an eth node (currently anvil from foundry) and deploying the contract looks like this:

        let eth_node = EthNode::default().with_show_logs(logs).start().await?;
        let deployed_contract = eth_node
            .deploy_contract(
                finalize_duration.as_secs(),
                blocks_per_interval,
                commit_cooldown_seconds,
            )
            .await?;

If you drop eth_node the node will shut down.

The remaining services are done similarly.

Contract deployment had to be done via a solidity script using forge script because the smart contract needs to be accessed via a proxy contract (because of how the contract is written you cannot get the role needed for committing if you deploy only the contract).

Wallet keys, contract addresses and the fuel-core consensus keys are generated on each run and no longer hard coded.

Copy link

@Br1ght0ne Br1ght0ne left a comment

Choose a reason for hiding this comment

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

Solid work!

.produce_blocks(fuel_contract.commit_interval().into())
// given
let show_logs = false;
// blob support disabled because this test doesn't generate blocks with transactions in it
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -12,9 +12,22 @@ use crate::error::Error;
fn kzg_settings() -> &'static c_kzg::KzgSettings {
static KZG_SETTINGS: OnceLock<c_kzg::KzgSettings> = OnceLock::new();
KZG_SETTINGS.get_or_init(|| {
// TODO: Load the trusted setup from static bytes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

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

Beautiful work. Can't thank you enough for dropping the need for docker and docker compose to run these tests. Massive win, IMO.

Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

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

Awesome work!

@segfault-magnet segfault-magnet merged commit bfd8e71 into master Jul 18, 2024
7 checks passed
@segfault-magnet segfault-magnet deleted the feature/configurable_e2e_setup branch July 18, 2024 11:19
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.

owning the e2e setup
4 participants