Skip to content

Commit

Permalink
Imports depending on era contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrigada committed Sep 25, 2024
1 parent e9f47dd commit 68d88b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 8 additions & 6 deletions crates/forge/tests/fixtures/zk/MyPaymaster.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "forge-std/console2.sol";

import {
IPaymaster,
ExecutionResult,
PAYMASTER_VALIDATION_SUCCESS_MAGIC
} from "../lib/zksync-contracts/zksync-contracts/l2/system-contracts/interfaces/IPaymaster.sol";
} from "era-contracts/system-contracts/contracts/interfaces/IPaymaster.sol";
import {IPaymasterFlow} from
"../lib/zksync-contracts/zksync-contracts/l2/system-contracts/interfaces/IPaymasterFlow.sol";
"era-contracts/system-contracts/contracts/interfaces/IPaymasterFlow.sol";
import {
TransactionHelper,
Transaction
} from "../lib/zksync-contracts/zksync-contracts/l2/system-contracts/libraries/TransactionHelper.sol";
import "../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "../lib/zksync-contracts/zksync-contracts/l2/system-contracts/Constants.sol";
} from "era-contracts/system-contracts/contracts/libraries/TransactionHelper.sol";
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

contract MyPaymaster is IPaymaster {
// TODO: Replace this once the following issue is fixed:
// https://github.com/matter-labs/era-contracts/issues/802
address payable constant BOOTLOADER_FORMAL_ADDRESS = payable(address(0x8000 + 0x01));
uint256 constant PRICE_FOR_PAYING_FEES = 1;

address public allowedToken;
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/tests/fixtures/zk/Paymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import "../lib/zksync-contracts/zksync-contracts/l2/system-contracts/Constants.sol";
import {MyPaymaster, MyERC20} from "./MyPaymaster.sol";

contract TestPaymasterFlow is Test {
Expand Down Expand Up @@ -80,6 +79,7 @@ contract TestPaymasterFlow is Test {
}

contract DoStuff {
address payable constant BOOTLOADER_FORMAL_ADDRESS = payable(address(0x8000 + 0x01));
function do_stuff() public {
(bool success,) = payable(BOOTLOADER_FORMAL_ADDRESS).call{value: address(this).balance}("");
require(success, "Failed to transfer tx fee to the bootloader. Paymaster balance might not be enough.");
Expand Down
13 changes: 12 additions & 1 deletion crates/forge/tests/it/zk/paymaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use foundry_config::fs_permissions::PathPermission;
use foundry_test_utils::util;

use std::fs;

#[tokio::test(flavor = "multi_thread")]
async fn test_zk_contract_paymaster() {
let (prj, mut cmd) = util::setup_forge(
Expand All @@ -14,13 +16,19 @@ async fn test_zk_contract_paymaster() {
cmd.args([
"install",
"OpenZeppelin/openzeppelin-contracts",
"cyfrin/zksync-contracts",
"matter-labs/era-contracts",
"--no-commit",
"--shallow",
])
.ensure_execute_success()
.expect("able to install dependencies");

//ls the lib/era-contracts/system-contracts folder
let entries = fs::read_dir(prj.root().join("lib").join("era-contracts").join("system-contracts").join("contracts").join("interfaces")).unwrap();
for entry in entries {
println!("Found in lib: {:?}", entry.unwrap().path().to_str().unwrap());
}

cmd.forge_fuse();

let mut config = cmd.config();
Expand All @@ -30,6 +38,9 @@ async fn test_zk_contract_paymaster() {
prj.add_source("MyPaymaster.sol", include_str!("../../fixtures/zk/MyPaymaster.sol")).unwrap();
prj.add_source("Paymaster.t.sol", include_str!("../../fixtures/zk/Paymaster.t.sol")).unwrap();



//add mc to the command
cmd.args(["test", "--zk-startup", "--evm-version", "shanghai", "--via-ir"]);
assert!(cmd.stdout_lossy().contains("Suite result: ok"));
}

0 comments on commit 68d88b1

Please sign in to comment.