Skip to content

Commit

Permalink
Merge branch 'dev' into elfedy-bh-default
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy authored Aug 1, 2024
2 parents aabcf4b + 199f026 commit d781527
Show file tree
Hide file tree
Showing 21 changed files with 668 additions and 138 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,21 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-04-28

- name: Run era-test-node
uses: dutterbutter/era-test-node-action@v1
with:
mode: fork
network: mainnet
log: info
logFilePath: era_test_node.log
target: x86_64-unknown-linux-gnu
releaseTag: v0.1.0-alpha.25

- name: Run zk tests
env:
RUST_BACKTRACE: full
TEST_MAINNET_URL: http://localhost:8011
run: cargo test zk

zk-smoke-test:
Expand Down
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ impl Cheatcodes {
}
}

impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
#[inline]
fn initialize_interp(&mut self, _: &mut Interpreter, ecx: &mut EvmContext<DB>) {
// When the first interpreter is initialized we've circumvented the balance and gas checks,
Expand Down Expand Up @@ -2083,7 +2083,7 @@ impl<DB: DatabaseExt + Send> Inspector<DB> for Cheatcodes {
}
}

impl<DB: DatabaseExt + Send> InspectorExt<DB> for Cheatcodes {
impl<DB: DatabaseExt> InspectorExt<DB> for Cheatcodes {
fn should_use_create2_factory(
&mut self,
ecx: &mut EvmContext<DB>,
Expand Down
11 changes: 4 additions & 7 deletions crates/evm/core/src/backend/fork_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ impl CachedForkType {

let is_zk_url = foundry_common::provider::try_get_http_provider(fork_url)
.map(|provider| {
let is_zk_url = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(provider.raw_request("zks_L1ChainId".into(), ()))
.map(|_: String| true)
.unwrap_or_default();
let is_zk_url =
futures::executor::block_on(provider.raw_request("zks_L1ChainId".into(), ()))
.map(|_: String| true)
.unwrap_or_default();

is_zk_url
})
Expand Down
31 changes: 28 additions & 3 deletions crates/forge/tests/it/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl ForgeTestProfile {
zk_config.zksync.fallback_oz = true;
zk_config.zksync.optimizer_mode = '3';
zk_config.zksync.zksolc = Some(foundry_config::SolcReq::Version(Version::new(1, 5, 1)));
zk_config.fuzz.no_zksync_reserved_addresses = true;

zk_config
}
Expand Down Expand Up @@ -335,7 +336,7 @@ impl ForgeTestData {
/// Builds a non-tracing runner with zksync
/// TODO: This needs to be added as currently it is a copy of the original function
pub fn runner_with_zksync_config(&self, mut zk_config: Config) -> MultiContractRunner {
zk_config.rpc_endpoints = rpc_endpoints();
zk_config.rpc_endpoints = rpc_endpoints_zk();
zk_config.allow_paths.push(manifest_root().to_path_buf());

// no prompt testing
Expand All @@ -352,15 +353,16 @@ impl ForgeTestData {
let output = self.zk_test_data.output.clone();
let zk_output = self.zk_test_data.zk_output.clone();
let dual_compiled_contracts = self.zk_test_data.dual_compiled_contracts.clone();

let mut test_opts = self.test_opts.clone();
test_opts.fuzz.no_zksync_reserved_addresses = zk_config.fuzz.no_zksync_reserved_addresses;
let sender = zk_config.sender;

let mut builder = self.base_runner();
builder.config = Arc::new(zk_config);
builder
.enable_isolation(opts.isolate)
.sender(sender)
.with_test_options(self.test_opts.clone())
.with_test_options(test_opts)
.build(root, output, Some(zk_output), env, opts.clone(), dual_compiled_contracts)
.unwrap()
}
Expand Down Expand Up @@ -511,3 +513,26 @@ pub fn rpc_endpoints() -> RpcEndpoints {
("rpcEnvAlias", RpcEndpoint::Env("${RPC_ENV_ALIAS}".to_string())),
])
}

/// the RPC endpoints used during tests
pub fn rpc_endpoints_zk() -> RpcEndpoints {
// use mainnet url from env to avoid rate limiting in CI
let mainnet_url =
std::env::var("TEST_MAINNET_URL").unwrap_or("https://mainnet.era.zksync.io".to_string()); // trufflehog:ignore
RpcEndpoints::new([
("mainnet", RpcEndpoint::Url(mainnet_url)),
(
"rpcAlias",
RpcEndpoint::Url(
"https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf".to_string(), /* trufflehog:ignore */
),
),
(
"rpcAliasSepolia",
RpcEndpoint::Url(
"https://eth-sepolia.g.alchemy.com/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf".to_string(), /* trufflehog:ignore */
),
),
("rpcEnvAlias", RpcEndpoint::Env("${RPC_ENV_ALIAS}".to_string())),
])
}
68 changes: 0 additions & 68 deletions crates/forge/tests/it/zk.rs

This file was deleted.

34 changes: 34 additions & 0 deletions crates/forge/tests/it/zk/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Forge tests for basic zkysnc functionality.
use crate::{config::*, test_helpers::TEST_DATA_DEFAULT};
use forge::revm::primitives::SpecId;
use foundry_test_utils::Filter;

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_block_information_is_consistent() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter =
Filter::new("testZkBasicBlockNumber|testZkBasicBlockTimestamp", "ZkBasicTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_address_balance_is_consistent() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkBasicAddressBalance", "ZkBasicTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_propagated_block_env_is_consistent() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new(
"testZkPropagatedBlockEnv|testZkBasicBlockBaseFee|testZkBlockHashWithNewerBlocks",
"ZkBasicTest",
".*",
);

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}
92 changes: 92 additions & 0 deletions crates/forge/tests/it/zk/cheats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//! Forge tests for cheatcodes.
use crate::{config::*, test_helpers::TEST_DATA_DEFAULT};
use forge::revm::primitives::SpecId;
use foundry_config::fs_permissions::PathPermission;
use foundry_test_utils::Filter;

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_roll_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesRoll", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_warp_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesWarp", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_deal_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesDeal", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_set_nonce_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesSetNonce", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_etch_works() {
let mut zk_config = TEST_DATA_DEFAULT.zk_test_data.zk_config.clone();
zk_config.fs_permissions.add(PathPermission::read_write("./zk/zkout/ConstantNumber.sol"));
let runner = TEST_DATA_DEFAULT.runner_with_zksync_config(zk_config);
let filter = Filter::new("testZkCheatcodesEtch", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_record_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testRecord", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_expect_emit_works() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testExpectEmit|testExpectEmitOnCreate", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_mock_with_value_function() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesValueFunctionMockReturn", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_mock_calls() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new(
"testZkCheatcodesCanMockCallTestContract|testZkCheatcodesCanMockCall",
"ZkCheatcodesTest",
".*",
);

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_cheat_works_after_fork() {
let runner = TEST_DATA_DEFAULT.runner_zksync();
let filter = Filter::new("testZkCheatcodesCanBeUsedAfterFork", "ZkCheatcodesTest", ".*");

TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await;
}
Loading

0 comments on commit d781527

Please sign in to comment.