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: RpcUrls cheatcodes implementation #214

Merged
merged 27 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ab71c46
first impl fork cheatcode
Deniallugo Dec 14, 2023
5c7f0da
Implement some forking
Deniallugo Dec 15, 2023
4607a6a
Balance
Deniallugo Dec 15, 2023
bd5a564
Merge branch 'main' into deniallugo-fork-cheatcode
Deniallugo Dec 15, 2023
337cdb4
Add zksync provider
Deniallugo Dec 15, 2023
f3599ce
It's alive
Deniallugo Dec 15, 2023
d633bea
Use the correct urls
Deniallugo Dec 15, 2023
5ae99e1
Make it work properly with l2blocks
Deniallugo Dec 15, 2023
4663344
Remove local era test-node
Deniallugo Dec 16, 2023
038b19a
Update to latest vm
Deniallugo Dec 18, 2023
9c1249b
Merge branch 'main' into deniallugo-fork-cheatcode
Deniallugo Dec 18, 2023
1845c4e
Small follow ups
Deniallugo Dec 18, 2023
c0b3a72
Fix test
Deniallugo Dec 18, 2023
6c87893
add create and select blocks
Deniallugo Dec 18, 2023
dcc8ff9
Remove cheatcode tests
Deniallugo Dec 18, 2023
3ded7e4
Remove release tests
Deniallugo Dec 18, 2023
96d6f8c
Merge branch 'main' into deniallugo-fork-cheatcode
nbaztec Dec 21, 2023
b8a718d
decouple env, modified keys, readd tests, make fuzz work
nbaztec Dec 22, 2023
f77f615
Merge branch 'main' into deniallugo-fork-cheatcode
nbaztec Dec 22, 2023
9ce601e
fix tests
nbaztec Dec 22, 2023
984b322
remove console.log for failed()
nbaztec Dec 22, 2023
0adab36
clippy
nbaztec Dec 22, 2023
b79285b
first iteration of rpcUrls cheatcodes
Dec 22, 2023
8ab8286
Merge branch 'main' into jr-fear-rpcUrls-cheatcodes
Jrigada Jan 2, 2024
43a1699
remove clone
Jan 2, 2024
ea2a15a
remove wrong merged code
Jan 3, 2024
e8aaddb
joined together
Jan 3, 2024
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
27 changes: 27 additions & 0 deletions crates/era-cheatcodes/src/cheatcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,33 @@ impl CheatcodeTracer {
&mut storage,
);
}
rpcUrl(rpcUrlCall { rpcAlias }) => {
tracing::info!("👷 Getting rpc url of {}", rpcAlias);
let rpc_endpoints = &self.config.rpc_endpoints;
let rpc_url = match rpc_endpoints.get(&rpcAlias) {
Some(Ok(url)) => Some(url.clone()),
_ => None,
};
//this should revert but we don't have reverts yet
assert!(
rpc_url.is_some(),
"Failed to resolve env var `${rpcAlias}`: environment variable not found"
);
self.add_trimmed_return_data(rpc_url.unwrap().as_bytes());
}
rpcUrls(rpcUrlsCall {}) => {
tracing::info!("👷 Getting rpc urls");
let rpc_endpoints = &self.config.rpc_endpoints;
let rpc_urls: Vec<String> = rpc_endpoints
.iter()
.map(|(alias, url)| match url {
Ok(url) => format!("{}:{}", alias, url),
Err(_) => alias.clone(),
})
.collect();
let rpc_urls = rpc_urls.join(",");
Jrigada marked this conversation as resolved.
Show resolved Hide resolved
self.add_trimmed_return_data(rpc_urls.as_bytes());
}
serializeAddress_0(serializeAddress_0Call {
objectKey: object_key,
valueKey: value_key,
Expand Down
48 changes: 48 additions & 0 deletions crates/era-cheatcodes/tests/src/cheatcodes/RpcUrls.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console2 as console} from "../../lib/forge-std/src/Test.sol";
import {Constants} from "./Constants.sol";
import {Utils} from "./Utils.sol";

contract RpcUrlsTest is Test {
function testRpcUrl() public {
(bool success, bytes memory rawData) = Constants.CHEATCODE_ADDRESS.call(
abi.encodeWithSignature("rpcUrl(string)", "mainnet")
);

bytes memory return_data = Utils.trimReturnBytes(rawData);
string memory rpc_url = string(return_data);
console.log("rpc_url", rpc_url);
require(success, "rpcUrl() failed");
require(
keccak256(abi.encodePacked(rpc_url)) ==
keccak256(
abi.encodePacked("https://mainnet.era.zksync.io:443")
),
"rpc url retrieved does not match expected value"
);
}

function testRpcUrls() public {
(bool success, bytes memory rawData2) = Constants
.CHEATCODE_ADDRESS
.call(abi.encodeWithSignature("rpcUrls()"));

bytes memory return_data2 = Utils.trimReturnBytes(rawData2);
string memory rpc_urls = string(return_data2);

console.log("rpc_urls", rpc_urls);

require(success, "rpcUrls() failed");
require(
keccak256(abi.encodePacked(rpc_urls)) ==
keccak256(
abi.encodePacked(
"local,mainnet:https://mainnet.era.zksync.io:443,testnet:https://testnet.era.zksync.dev:443"
)
),
"rpc urls retrieved does not match expected value"
);
}
}
Loading