Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrq committed Nov 27, 2024
1 parent 3428136 commit f0d420e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 154 deletions.
275 changes: 131 additions & 144 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,37 +1414,32 @@ casttest!(block_number_hash, |_prj, cmd| {
assert_eq!(s.trim().parse::<u64>().unwrap(), 1, "{s}")
});

casttest!(
send_eip7702,
async | _prj,
cmd | {
let (_api, handle) = anvil::spawn(
NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())),
)
.await;
let endpoint = handle.http_endpoint();

cmd.args([
"send",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"--auth",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&endpoint,
])
.assert_success();
casttest!(send_eip7702, async |_prj, cmd| {
let (_api, handle) =
anvil::spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())))
.await;
let endpoint = handle.http_endpoint();

cmd.cast_fuse()
.args(["code", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "--rpc-url", &endpoint])
.assert_success()
.stdout_eq(str![[r#"
cmd.args([
"send",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"--auth",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"--private-key",
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"--rpc-url",
&endpoint,
])
.assert_success();

cmd.cast_fuse()
.args(["code", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "--rpc-url", &endpoint])
.assert_success()
.stdout_eq(str![[r#"
0xef010070997970c51812dc3a010c7d01b50e0d17dc79c8
"#]]);
}
);
});

casttest!(hash_message, |_prj, cmd| {
cmd.args(["hash-message", "hello"]).assert_success().stdout_eq(str![[r#"
Expand Down Expand Up @@ -1607,67 +1602,64 @@ casttest!(fetch_artifact_from_etherscan, |_prj, cmd| {
"#]]);
});

casttest!(
zk_cast_using_paymaster,
async | prj,
cmd | {
util::initialize(prj.root());
casttest!(zk_cast_using_paymaster, async |prj, cmd| {
util::initialize(prj.root());

let node = ZkSyncNode::start();
let url = node.url();
let node = ZkSyncNode::start();
let url = node.url();

let (addr, private_key) = ZkSyncNode::rich_wallets()
.next()
.map(|(addr, pk, _)| (addr, pk))
.expect("No rich wallets available");
let (addr, private_key) = ZkSyncNode::rich_wallets()
.next()
.map(|(addr, pk, _)| (addr, pk))
.expect("No rich wallets available");

// Deploy paymaster
cmd.args([
// Deploy paymaster
cmd.args([
"rpc",
"hardhat_setCode",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
PAYMASTER_BYTECODE,
"--rpc-url",
&url,
])
.assert_success();

// Deploy counter
cmd.cast_fuse()
.args([
"rpc",
"hardhat_setCode",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
COUNTER_BYTECODE,
"--rpc-url",
&url,
])
.assert_success();

// Fund the paymaster
cmd.cast_fuse()
.args([
"send",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
PAYMASTER_BYTECODE,
"0x",
"--value",
"0.1ether",
"--private-key",
private_key,
"--rpc-url",
&url,
])
.assert_success();

// Deploy counter
cmd.cast_fuse()
.args([
"rpc",
"hardhat_setCode",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
COUNTER_BYTECODE,
"--rpc-url",
&url,
])
.assert_success();

// Fund the paymaster
cmd.cast_fuse()
.args([
"send",
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x",
"--value",
"0.1ether",
"--private-key",
private_key,
"--rpc-url",
&url,
])
.assert_success();

let balance_before = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

// Interact with the counter using the paymaster
cmd.cast_fuse().args([
let balance_before = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

// Interact with the counter using the paymaster
cmd.cast_fuse().args([
"send",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"increment()",
Expand All @@ -1682,71 +1674,66 @@ casttest!(
])
.assert_success();

let balance_after = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();
let balance_after = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

assert_eq!(balance_after, balance_before);
}
);

casttest!(
zk_cast_without_paymaster,
async | prj,
cmd | {
util::initialize(prj.root());

let node = ZkSyncNode::start();
let url = node.url();

let (addr, private_key) = ZkSyncNode::rich_wallets()
.next()
.map(|(addr, pk, _)| (addr, pk))
.expect("No rich wallets available");

// Deploy counter
cmd.cast_fuse()
.args([
"rpc",
"hardhat_setCode",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
COUNTER_BYTECODE,
"--rpc-url",
&url,
])
.assert_success();

let balance_before = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

cmd.cast_fuse()
.args([
"send",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"increment()",
"--private-key",
private_key,
"--rpc-url",
&url,
"--gas-price",
"1000000000000002",
])
.assert_success();

let balance_after = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

assert!(balance_after != balance_before);
}
);
assert_eq!(balance_after, balance_before);
});

casttest!(zk_cast_without_paymaster, async |prj, cmd| {
util::initialize(prj.root());

let node = ZkSyncNode::start();
let url = node.url();

let (addr, private_key) = ZkSyncNode::rich_wallets()
.next()
.map(|(addr, pk, _)| (addr, pk))
.expect("No rich wallets available");

// Deploy counter
cmd.cast_fuse()
.args([
"rpc",
"hardhat_setCode",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
COUNTER_BYTECODE,
"--rpc-url",
&url,
])
.assert_success();

let balance_before = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

cmd.cast_fuse()
.args([
"send",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"increment()",
"--private-key",
private_key,
"--rpc-url",
&url,
"--gas-price",
"1000000000000002",
])
.assert_success();

let balance_after = cmd
.cast_fuse()
.args(["balance", addr, "--rpc-url", &url])
.assert_success()
.get_output()
.stdout_lossy();

assert!(balance_after != balance_before);
});
10 changes: 4 additions & 6 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use foundry_compilers::{
cache::{CacheEntry, CompilerCache},
utils::read_json_file,
zksync::artifact_output::zk::ZkContractArtifact,
Artifact, ProjectCompileOutput,
ArtifactId
Artifact, ArtifactId, ProjectCompileOutput,
};
use foundry_config::{error::ExtractConfigError, figment::Figment, Chain, Config, NamedChain};
use foundry_debugger::Debugger;
Expand Down Expand Up @@ -92,9 +91,7 @@ pub fn remove_zk_contract(
}
}) else {
let mut err = format!("could not find artifact: `{name}`");
if let Some(suggestion) =
super::did_you_mean(name, other).pop()
{
if let Some(suggestion) = super::did_you_mean(name, other).pop() {
if suggestion != name {
err = format!(
r#"{err}
Expand All @@ -106,7 +103,8 @@ pub fn remove_zk_contract(
eyre::bail!(err)
};

let contract = output.remove(id.source.as_ref(), &id.name).expect("contract found to exist in zk output");
let contract =
output.remove(id.source.as_ref(), &id.name).expect("contract found to exist in zk output");

Ok((contract, id))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{
};
use alloy_consensus::Transaction as TransactionTrait;
use alloy_genesis::GenesisAccount;
use alloy_network::{AnyRpcBlock, AnyTxEnvelope, TransactionResponse};
use alloy_primitives::{keccak256, map::HashMap, uint, Address, B256, U256};
use alloy_rpc_types::{BlockNumberOrTag, Transaction, TransactionRequest};
use alloy_network::{AnyRpcBlock, AnyTxEnvelope, TransactionResponse};
use eyre::Context;
use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
pub use foundry_fork_db::{cache::BlockchainDbMeta, BlockchainDb, SharedBackend};
Expand Down
5 changes: 3 additions & 2 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use foundry_common::{
};
use foundry_compilers::{
artifacts::BytecodeObject, info::ContractInfo, utils::canonicalize,
zksync::artifact_output::zk::ZkContractArtifact, ArtifactId
zksync::artifact_output::zk::ZkContractArtifact, ArtifactId,
};
use foundry_config::{
figment::{
Expand Down Expand Up @@ -153,7 +153,8 @@ impl CreateArgs {
let zk_compiler = ProjectCompiler::new().files([target_path.clone()]);
let mut zk_output = zk_compiler.zksync_compile(&zk_project)?;

let (artifact, id) = remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?;
let (artifact, id) =
remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?;

let ZkContractArtifact { bytecode, hash, factory_dependencies, abi, .. } = artifact;

Expand Down
4 changes: 3 additions & 1 deletion crates/zksync/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub mod vm;
pub mod state;

use alloy_network::{AnyNetwork, TxSigner};
use alloy_primitives::{address, hex, keccak256, Address, Bytes, PrimitiveSignature, U256 as rU256};
use alloy_primitives::{
address, hex, keccak256, Address, Bytes, PrimitiveSignature, U256 as rU256,
};
use alloy_provider::Provider;
use alloy_rpc_types::TransactionRequest;
use alloy_serde::WithOtherFields;
Expand Down

0 comments on commit f0d420e

Please sign in to comment.