Skip to content

Commit

Permalink
feat: update cheatcodes-test CI to use local era-test-node (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
aon authored Feb 9, 2024
1 parent 4b7e1e6 commit fc0391a
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 23 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
Expand All @@ -115,15 +115,33 @@ jobs:
name: cheatcode-test
runs-on: ubuntu-22.04-github-hosted-16core
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-09-30


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

- name: Test Cheatcodes
env:
ERA_TEST_NODE_RPC_URL: http://localhost:8011
run: cd crates/era-cheatcodes/tests && ./test.sh

- name: Upload era_test_node log
uses: actions/upload-artifact@v3
with:
name: era_test_node.log
path: era_test_node.log
2 changes: 1 addition & 1 deletion crates/era-cheatcodes/tests/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ libs = ['lib']
local = "${ERA_TEST_NODE_RPC_URL}"
mainnet = "https://mainnet.era.zksync.io:443"
testnet = "https://testnet.era.zksync.dev:443"
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
6 changes: 3 additions & 3 deletions crates/era-cheatcodes/tests/src/cheatcodes/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract ForkTest is Test {
"Local node doesn't have blocks above 1000"
);

vm.createSelectFork("mainnet", FORK_BLOCK);
vm.createSelectFork("local", FORK_BLOCK);

require(decimals_before == 0, "Contract exists locally");
}
Expand All @@ -46,7 +46,7 @@ contract ForkTest is Test {
}

function testCreateSelectFork() public {
uint256 forkId = vm.createFork("mainnet", FORK_BLOCK + 100);
uint256 forkId = vm.createFork("local", FORK_BLOCK + 100);

vm.selectFork(forkId);

Expand All @@ -69,7 +69,7 @@ contract ForkTest is Test {
}

function testActiveFork() public {
uint256 data = vm.createFork("mainnet", FORK_BLOCK + 100);
uint256 data = vm.createFork("local", FORK_BLOCK + 100);

uint256 forkId = uint256(bytes32(data));
vm.selectFork(forkId);
Expand Down
4 changes: 2 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/ForkBytecode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ contract ForkBytecodeTest is Test {

function testCreateSelectForkHasNonDeployedBytecodes() public {
console.log("run");
vm.createSelectFork("mainnet", FORK_BLOCK);
vm.createSelectFork("local", FORK_BLOCK);

// target should be able to deploy
Target target = new Target();
require(255 == target.output(), "incorrect output after fork");
}

function testSelectForkForkHasNonDeployedBytecodes() public {
uint256 forkId = vm.createFork("mainnet", FORK_BLOCK);
uint256 forkId = vm.createFork("local", FORK_BLOCK);
vm.selectFork(forkId);

// target should be able to deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract ForkBytecodeSetupTest is Test {
uint256 constant FORK_BLOCK = 19579636;

function setUp() public {
vm.createSelectFork("mainnet", FORK_BLOCK);
vm.createSelectFork("local", FORK_BLOCK);
Target target = new Target();
require(255 == target.output(), "incorrect output after fork");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract ForkBytecodeSetup2Test is Test {
uint256 constant FORK_BLOCK = 19579636;

function setUp() public {
vm.createSelectFork("mainnet", FORK_BLOCK);
vm.createSelectFork("local", FORK_BLOCK);
}

function testForkBytecodeSetup2Success() public {
Expand Down
4 changes: 2 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/ForkStorage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract ForkStorageTest is Test {
// Contract gets successfully deployed
require(255 == target.output(), "incorrect output");

vm.createSelectFork("mainnet", FORK_BLOCK);
vm.createSelectFork("local", FORK_BLOCK);

// Contract is still deployed
require(255 == target.output(), "incorrect output after fork");
Expand All @@ -31,4 +31,4 @@ contract ForkStorageTest is Test {
Target newTarget = new Target();
require(255 == newTarget.output(), "incorrect new target output");
}
}
}
4 changes: 2 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/Persistent.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ contract ForkPersistentTest is Test {

/// checks that marking as persistent works
function testMakePersistent() public {
uint256 fork1 = vm.createFork("mainnet", FORK_BLOCK + 100);
uint256 fork2 = vm.createFork("mainnet", FORK_BLOCK + 100);
uint256 fork1 = vm.createFork("local", FORK_BLOCK + 100);
uint256 fork2 = vm.createFork("local", FORK_BLOCK + 100);

DummyContract dummy = new DummyContract();

Expand Down
4 changes: 2 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/RollFork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract RollForkTest is Test {
uint256 mainnetFork;

function setUp() public {
mainnetFork = vm.createFork("mainnet");
mainnetFork = vm.createFork("local");
}

// test that we can switch between forks, and "roll" blocks
Expand All @@ -22,7 +22,7 @@ contract RollForkTest is Test {
assertEq(block.number, mainBlock - 1);

// can also roll by id
uint256 otherMain = vm.createFork("mainnet", block.number - 1);
uint256 otherMain = vm.createFork("local", block.number - 1);
vm.rollFork(otherMain, mainBlock - 10);

assertEq(block.number, mainBlock - 1); // should not have rolled
Expand Down
12 changes: 10 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/RpcUrls.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ contract RpcUrlsTest is Test {
);
}

function testRpcUrls() public view {
function testRpcUrls() public {
string[2][] memory rpc_urls = vm.rpcUrls();

require(
keccak256(bytes(rpc_urls[0][0])) == keccak256("local"),
"invalid alias for [0]"
);
require(
keccak256(bytes(rpc_urls[0][1])) == keccak256("local"),
keccak256(bytes(rpc_urls[0][1])) ==
keccak256(
bytes(
vm.envOr(
string("ERA_TEST_NODE_RPC_URL"),
string("local")
)
)
),
"invalid url for [0]"
);
require(
Expand Down
4 changes: 2 additions & 2 deletions crates/era-cheatcodes/tests/src/cheatcodes/Transact.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract CheatcodeTransactTest is Test {

function testTransact() public {
// A random block https://explorer.zksync.io/block/23942350
vm.createSelectFork("mainnet", 23942350);
vm.createSelectFork("local", 23942350);

// A random transfer in the next block
bytes32 transaction = 0x272c2251368cae9eceaea67f52855c9858fd6b00dd68d6dfadab3ab1d66f9e4b;
Expand Down Expand Up @@ -50,7 +50,7 @@ contract CheatcodeTransactTest is Test {

function testTransactCooperatesWithCheatcodes() public {
// A random block https://explorer.zksync.io/block/20570164
vm.createSelectFork("mainnet", 20570164);
vm.createSelectFork("local", 20570164);

// a random ERC20 USDT transfer transaction in the next block: https://explorer.zksync.io/tx/0xa4124eed3fcb2eea3883915839004107a76597107a74c5eaf00a7d6c43638152
bytes32 transaction = 0xa4124eed3fcb2eea3883915839004107a76597107a74c5eaf00a7d6c43638152;
Expand Down

0 comments on commit fc0391a

Please sign in to comment.