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

chore: update fork url #707

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions crates/edr_solidity_tests/tests/it/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use edr_solidity_tests::{
multi_runner::{TestContract, TestContracts},
MultiContractRunner, SolidityTestRunnerConfig,
};
use edr_test_utils::new_fd_lock;
use edr_test_utils::{
env::{get_alchemy_url_for_network, NetworkType},
new_fd_lock,
};
use foundry_cheatcodes::{ExecutionContextConfig, FsPermissions, RpcEndpoint, RpcEndpoints};
use foundry_compilers::{
artifacts::{CompactContractBytecode, Libraries},
Expand Down Expand Up @@ -509,25 +512,35 @@ pub static TEST_DATA_CANCUN: Lazy<ForgeTestData> =
pub static TEST_DATA_MULTI_VERSION: Lazy<ForgeTestData> =
Lazy::new(|| ForgeTestData::new(ForgeTestProfile::MultiVersion));

// TODO use alchemy from env
// https://github.com/NomicFoundation/edr/issues/643
fn rpc_endpoints() -> RpcEndpoints {
RpcEndpoints::new([
(
"rpcAlias",
RpcEndpoint::Url(
"https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf".to_string(),
),
"rpcAliasFake",
RpcEndpoint::Url("https://example.com".to_string()),
),
(
"rpcAliasMainnet",
RpcEndpoint::Url(get_alchemy_url_for_network(NetworkType::Ethereum)),
),
(
"rpcAliasSepolia",
RpcEndpoint::Url(
"https://eth-sepolia.g.alchemy.com/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf".to_string(),
),
RpcEndpoint::Url(get_alchemy_url_for_network(NetworkType::Sepolia)),
),
(
"rpcEnvAlias",
RpcEndpoint::Env("${RPC_ENV_ALIAS}".to_string()),
),
(
"rpcAliasOptimism",
RpcEndpoint::Url(get_alchemy_url_for_network(NetworkType::Optimism)),
),
(
"rpcAliasPolygon",
RpcEndpoint::Url(get_alchemy_url_for_network(NetworkType::Polygon)),
),
(
"rpcAliasArbitrum",
RpcEndpoint::Url(get_alchemy_url_for_network(NetworkType::Arbitrum)),
),
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract ForkTest is DSTest {

// this will create two _different_ forks during setup
function setUp() public {
forkA = vm.createFork("https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf", mainblock);
forkB = vm.createFork("https://eth-mainnet.alchemyapi.io/v2/9VWGraLx0tMiSWx05WH-ywgSVmMxs66W", mainblock - 1);
forkA = vm.createFork("rpcAliasMainnet", mainblock);
forkB = vm.createFork("rpcAliasMainnet", mainblock - 1);
testValue = 999;
}

Expand All @@ -35,7 +35,7 @@ contract ForkTest is DSTest {

// ensures we can create and select in one step
function testCreateSelect() public {
uint256 fork = vm.createSelectFork("https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf");
uint256 fork = vm.createSelectFork("rpcAliasMainnet");
assertEq(fork, vm.activeFork());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract ForkTest is DSTest {

// this will create two _different_ forks during setup
function setUp() public {
mainnetFork = vm.createFork("rpcAlias");
optimismFork = vm.createFork("https://opt-mainnet.g.alchemy.com/v2/UVatYU2Ax0rX6bDiqddeTRDdcCxzdpoE");
mainnetFork = vm.createFork("rpcAliasMainnet");
optimismFork = vm.createFork("rpcAliasOptimism");
}

// ensures forks use different ids
Expand All @@ -57,7 +57,7 @@ contract ForkTest is DSTest {
}

function testCanCreateSelect() public {
uint256 anotherFork = vm.createSelectFork("rpcAlias");
uint256 anotherFork = vm.createSelectFork("rpcAliasMainnet");
assertEq(anotherFork, vm.activeFork());
}

Expand All @@ -75,12 +75,12 @@ contract ForkTest is DSTest {
// test that we can switch between forks, and "roll" blocks
function testCanRollFork() public {
vm.selectFork(mainnetFork);
uint256 otherMain = vm.createFork("rpcAlias", block.number - 1);
uint256 otherMain = vm.createFork("rpcAliasMainnet", block.number - 1);
vm.selectFork(otherMain);
uint256 mainBlock = block.number;

uint256 forkedBlock = 14608400;
uint256 otherFork = vm.createFork("rpcAlias", forkedBlock);
uint256 otherFork = vm.createFork("rpcAliasMainnet", forkedBlock);
vm.selectFork(otherFork);
assertEq(block.number, forkedBlock);

Expand All @@ -101,7 +101,7 @@ contract ForkTest is DSTest {
uint256 block = 16261704;

// fork until previous block
uint256 fork = vm.createSelectFork("rpcAlias", block - 1);
uint256 fork = vm.createSelectFork("rpcAliasMainnet", block - 1);

// block transactions in order: https://beaconcha.in/block/16261704#transactions
// run transactions from current block until tx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ contract RpcUrlTest is DSTest {

// returns the correct url
function testCanGetRpcUrl() public {
string memory url = vm.rpcUrl("rpcAlias"); // note: this alias is pre-configured in the test runner
assertEq(url, "https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf");
string memory url = vm.rpcUrl("rpcAliasFake"); // note: this alias is pre-configured in the test runner
assertEq(url, "https://example.com");
}

// returns an error if env alias does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ForkTest is DSTest {

// this will create two _different_ forks during setup
function setUp() public {
forkA = vm.createFork("https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf", 15_977_624);
forkA = vm.createFork("rpcAliasMainnet", 15_977_624);
}

function testDummy() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ForkTest is DSTest {

// this will create two _different_ forks during setup
function setUp() public {
forkA = vm.createFork("https://eth-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf", 15_977_624);
forkA = vm.createFork("rpcAliasMainnet", 15_977_624);
}

function testDummy() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract TransactOnForkTest is DSTest {

function testTransact() public {
// A random block https://etherscan.io/block/17134913
uint256 fork = vm.createFork("rpcAlias", 17134913);
uint256 fork = vm.createFork("rpcAliasMainnet", 17134913);
vm.selectFork(fork);
// a random transfer transaction in the next block: https://etherscan.io/tx/0xaf6201d435b216a858c580e20512a16136916d894aa33260650e164e3238c771
bytes32 tx = 0xaf6201d435b216a858c580e20512a16136916d894aa33260650e164e3238c771;
Expand Down Expand Up @@ -48,7 +48,7 @@ contract TransactOnForkTest is DSTest {

function testTransactCooperatesWithCheatcodes() public {
// A random block https://etherscan.io/block/16260609
uint256 fork = vm.createFork("rpcAlias", 16260609);
uint256 fork = vm.createFork("rpcAliasMainnet", 16260609);
vm.selectFork(fork);

// a random ERC20 USDT transfer transaction in the next block: https://etherscan.io/tx/0x33350512fec589e635865cbdb38fa3a20a2aa160c52611f1783d0ba24ad13c8c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Issue2623Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testRollFork() public {
uint256 fork = vm.createFork("rpcAlias", 10);
uint256 fork = vm.createFork("rpcAliasMainnet", 10);
vm.selectFork(fork);

assertEq(block.number, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ contract Issue2629Test is DSTest {
function testSelectFork() public {
address coinbase = 0x0193d941b50d91BE6567c7eE1C0Fe7AF498b4137;

uint256 f1 = vm.createSelectFork("rpcAlias", 9);
uint256 f1 = vm.createSelectFork("rpcAliasMainnet", 9);
vm.selectFork(f1);

assertEq(block.number, 9);
assertEq(coinbase.balance, 11250000000000000000);

uint256 f2 = vm.createFork("rpcAlias", 10);
uint256 f2 = vm.createFork("rpcAliasMainnet", 10);
vm.selectFork(f2);

assertEq(block.number, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Issue2723Test is DSTest {
function testRollFork() public {
address coinbase = 0x0193d941b50d91BE6567c7eE1C0Fe7AF498b4137;

vm.createSelectFork("rpcAlias", 9);
vm.createSelectFork("rpcAliasMainnet", 9);

assertEq(block.number, 9);
assertEq(coinbase.balance, 11250000000000000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract contract ZeroState is DSTest {

function setUp() public virtual {
vm.startPrank(deployer);
mainnetFork = vm.createFork("rpcAlias");
mainnetFork = vm.createFork("rpcAliasMainnet");
vm.selectFork(mainnetFork);
vm.rollFork(block.number - 20);
// deploy tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract contract ZeroState is DSTest {
vm.label(deployer, "Deployer");

vm.startPrank(deployer);
mainnetFork = vm.createFork("rpcAlias");
mainnetFork = vm.createFork("rpcAliasMainnet");
vm.selectFork(mainnetFork);

vm.rollFork(block.number - 20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract Issue3119Test is DSTest {
address public alice = vm.addr(2);

function testRollFork() public {
uint256 fork = vm.createFork("rpcAlias");
uint256 fork = vm.createFork("rpcAliasMainnet");
vm.selectFork(fork);

FortressSwap fortressSwap = new FortressSwap(address(owner));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ contract Issue3192Test is DSTest {
uint256 fork2;

function setUp() public {
fork1 = vm.createFork("rpcAlias", 7475589);
fork2 = vm.createFork("rpcAlias", 12880747);
fork1 = vm.createFork("rpcAliasMainnet", 7475589);
fork2 = vm.createFork("rpcAliasMainnet", 12880747);
vm.selectFork(fork1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ contract Issue3220Test is DSTest {
uint256 counter;

function setUp() public {
fork1 = vm.createFork("rpcAlias", 7475589);
fork1 = vm.createFork("rpcAliasMainnet", 7475589);
vm.selectFork(fork1);
fork2 = vm.createFork("rpcAlias", 12880747);
fork2 = vm.createFork("rpcAliasMainnet", 12880747);
}

function testForkRevert() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Issue3653Test is DSTest {
Token token;

constructor() {
fork = vm.createSelectFork("rpcAlias", 1000000);
fork = vm.createSelectFork("rpcAliasMainnet", 1000000);
token = new Token();
vm.makePersistent(address(token));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Issue3703Test is DSTest {

function setUp() public {
uint256 fork = vm.createSelectFork(
"https://polygon-mainnet.g.alchemy.com/v2/bVjX9v-FpmUhf5R_oHIgwJx2kXvYPRbx",
"rpcAliasPolygon",
bytes32(0xbed0c8c1b9ff8bf0452979d170c52893bb8954f18a904aa5bcbd0f709be050b9)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract Issue4586Test is DSTest {
InvariantHandler handler;

function setUp() public {
vm.createSelectFork("rpcAlias", initialBlock);
vm.createSelectFork("rpcAliasMainnet", initialBlock);
handler = new InvariantHandler();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Issue4640Test is DSTest {

function testArbitrumBlockNumber() public {
// <https://arbiscan.io/block/75219831>
vm.createSelectFork("https://arb-mainnet.alchemyapi.io/v2/Lc7oIGYeL_QvInzI0Wiu_pOZZDEKBrdf", 75219831);
vm.createSelectFork("rpcAliasArbitrum", 75219831);
// L1 block number
assertEq(block.number, 16939475);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Issue5929Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function test_transact_not_working() public {
vm.createSelectFork("rpcAlias", 15625301);
vm.createSelectFork("rpcAliasMainnet", 15625301);
// https://etherscan.io/tx/0x96a129768ec66fd7d65114bf182f4e173bf0b73a44219adaf71f01381a3d0143
vm.transact(hex"96a129768ec66fd7d65114bf182f4e173bf0b73a44219adaf71f01381a3d0143");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ contract Issue5935Test is DSTest {

function testFork() public {
uint256 forkId1 =
vm.createFork("https://eth-mainnet.alchemyapi.io/v2/QC55XC151AgkS3FNtWvz9VZGeu9Xd9lb", 18234083);
vm.createFork("rpcAliasMainnet", 18234083);
uint256 forkId2 =
vm.createFork("https://eth-mainnet.alchemyapi.io/v2/QC55XC151AgkS3FNtWvz9VZGeu9Xd9lb", 18234083);
vm.createFork("rpcAliasMainnet", 18234083);
vm.selectFork(forkId1);
SimpleStorage myContract = new SimpleStorage();
myContract.set(42);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Issue6032Test is DSTest {

address counterAddress = address(counter);
// Enter the fork
vm.createSelectFork("rpcAlias");
vm.createSelectFork("rpcAliasMainnet");
assert(counterAddress.code.length > 0);
// `Counter` is not deployed on the fork, which is expected.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Issue6538Test is DSTest {

function test_transact() public {
bytes32 lastHash = 0xdbdce1d5c14a6ca17f0e527ab762589d6a73f68697606ae0bb90df7ac9ec5087;
vm.createSelectFork("rpcAlias", lastHash);
vm.createSelectFork("rpcAliasMainnet", lastHash);
bytes32 txhash = 0xadbe5cf9269a001d50990d0c29075b402bcc3a0b0f3258821881621b787b35c6;
vm.transact(txhash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ contract Issue6616Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testCreateForkRollLatestBlock() public {
vm.createSelectFork("rpcAlias");
vm.createSelectFork("rpcAliasMainnet");
uint256 startBlock = block.number;
// this will create new forks and exit once a new latest block is found
for (uint256 i; i < 10; i++) {
vm.sleep(5000);
vm.createSelectFork("rpcAlias");
vm.createSelectFork("rpcAliasMainnet");
if (block.number > startBlock) break;
}
assertGt(block.number, startBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ contract Issue6759Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testCreateMulti() public {
uint256 fork1 = vm.createFork("rpcAlias", 10);
uint256 fork2 = vm.createFork("rpcAlias", 10);
uint256 fork3 = vm.createFork("rpcAlias", 10);
uint256 fork1 = vm.createFork("rpcAliasMainnet", 10);
uint256 fork2 = vm.createFork("rpcAliasMainnet", 10);
uint256 fork3 = vm.createFork("rpcAliasMainnet", 10);
assert(fork1 != fork2);
assert(fork1 != fork3);
assert(fork2 != fork3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Issue7481Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testFailTransact() public {
vm.createSelectFork("rpcAlias", 19514903);
vm.createSelectFork("rpcAliasMainnet", 19514903);

// Transfer some funds to sender of tx being transacted to ensure that it appears in journaled state
payable(address(0x5C60cD7a3D50877Bfebd484750FBeb245D936dAD)).call{value: 1}("");
Expand Down
29 changes: 29 additions & 0 deletions crates/edr_test_utils/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,32 @@ pub fn get_alchemy_url() -> String {
pub fn get_infura_url() -> String {
get_non_empty_env_var_or_panic("INFURA_URL")
}

/// Enum representing the different types of networks.
pub enum NetworkType {
Ethereum,
Sepolia,
Optimism,
Arbitrum,
Polygon,
}

/// Return the URL of a specific network Alchemy from environment variables.
///
/// # Panics
///
/// Panics if the environment variable is not defined, or if it is empty.
pub fn get_alchemy_url_for_network(network_type: NetworkType) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

I love this!

let alchemy_url = get_alchemy_url();

let url_without_network = alchemy_url
.strip_prefix("https://eth-mainnet")
.expect("Failed to remove alchemy url network prefix");
match network_type {
NetworkType::Ethereum => alchemy_url,
NetworkType::Sepolia => format!("https://eth-sepolia{url_without_network}"),
NetworkType::Optimism => format!("https://opt-mainnet{url_without_network}"),
NetworkType::Arbitrum => format!("https://arb-mainnet{url_without_network}"),
NetworkType::Polygon => format!("https://polygon-mainnet{url_without_network}"),
}
}
Loading