Skip to content

Commit

Permalink
Merge branch 'master' into zerosnacks/traces-field-is-mising
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks authored Oct 7, 2024
2 parents e2fba55 + 8905af3 commit 9b7a2d3
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 181 deletions.
265 changes: 137 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use anvil_core::eth::{
utils::meets_eip155,
};
use anvil_rpc::error::RpcError;
use chrono::Datelike;
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use foundry_evm::{
backend::{DatabaseError, DatabaseResult, RevertStateSnapshotAction},
Expand Down Expand Up @@ -1123,7 +1124,12 @@ impl Backend {

node_info!(" Block Number: {}", block_number);
node_info!(" Block Hash: {:?}", block_hash);
node_info!(" Block Time: {:?}\n", timestamp.to_rfc2822());
if timestamp.year() > 9999 {
// rf2822 panics with more than 4 digits
node_info!(" Block Time: {:?}\n", timestamp.to_rfc3339());
} else {
node_info!(" Block Time: {:?}\n", timestamp.to_rfc2822());
}

let outcome = MinedBlockOutcome { block_number, included, invalid };

Expand Down
12 changes: 12 additions & 0 deletions crates/anvil/tests/it/anvil.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! tests for anvil specific logic

use alloy_eips::BlockNumberOrTag;
use alloy_primitives::Address;
use alloy_provider::Provider;
use anvil::{spawn, NodeConfig};
Expand Down Expand Up @@ -76,3 +77,14 @@ async fn test_can_use_default_genesis_timestamp() {
provider.get_block(0.into(), false.into()).await.unwrap().unwrap().header.timestamp
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_can_handle_large_timestamp() {
let (api, _handle) = spawn(NodeConfig::test()).await;
let num = 317071597274;
api.evm_set_next_block_timestamp(num).unwrap();
api.mine_one().await;

let block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap();
assert_eq!(block.header.timestamp, num);
}
16 changes: 5 additions & 11 deletions crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ impl SessionSourceConfig {

match solc_req {
SolcReq::Version(version) => {
// Validate that the requested evm version is supported by the solc version
let req_evm_version = self.foundry_config.evm_version;
if let Some(compat_evm_version) = req_evm_version.normalize_version_solc(&version) {
if req_evm_version > compat_evm_version {
eyre::bail!(
"The set evm version, {req_evm_version}, is not supported by solc {version}. Upgrade to a newer solc version."
);
}
}

let solc = if let Some(solc) = Solc::find_svm_installed_version(&version)? {
solc
} else {
Expand Down Expand Up @@ -322,7 +312,11 @@ impl SessionSource {

let settings = Settings {
remappings,
evm_version: Some(self.config.foundry_config.evm_version),
evm_version: self
.config
.foundry_config
.evm_version
.normalize_version_solc(&self.solc.version),
..Default::default()
};

Expand Down
27 changes: 1 addition & 26 deletions crates/chisel/tests/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chisel::session::ChiselSession;
use foundry_compilers::artifacts::EvmVersion;
use foundry_config::{Config, SolcReq};
use semver::Version;
use foundry_config::Config;
use serial_test::serial;
use std::path::Path;

Expand Down Expand Up @@ -221,27 +220,3 @@ fn test_load_latest_cache() {
assert_eq!(new_env.id.unwrap(), "1");
assert_eq!(new_env.session_source.to_repl_source(), env.session_source.to_repl_source());
}

#[test]
#[serial]
fn test_solc_evm_configuration_mismatch() {
// Create and clear the cache directory
ChiselSession::create_cache_dir().unwrap();
ChiselSession::clear_cache().unwrap();

// Force the solc version to be 0.8.13 which does not support Paris
let foundry_config = Config {
evm_version: EvmVersion::Paris,
solc: Some(SolcReq::Version(Version::new(0, 8, 13))),
..Default::default()
};

// Create a new session that is expected to fail
let error = ChiselSession::new(chisel::session_source::SessionSourceConfig {
foundry_config,
..Default::default()
})
.unwrap_err();

assert_eq!(error.to_string(), "The set evm version, paris, is not supported by solc 0.8.13. Upgrade to a newer solc version.");
}
5 changes: 1 addition & 4 deletions crates/forge/bin/cmd/bind_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,7 @@ impl CompiledState {
for ((path, id), (def, contract_name)) in structs {
// For some structs there's no schema (e.g. if they contain a mapping), so we just skip
// those.
let Some(schema) = resolver.resolve_struct_eip712(id, &mut Default::default(), true)?
else {
continue
};
let Some(schema) = resolver.resolve_struct_eip712(id)? else { continue };

if !include.is_empty() {
if !include.iter().any(|matcher| matcher.is_match(path)) {
Expand Down
37 changes: 26 additions & 11 deletions crates/forge/bin/cmd/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use foundry_compilers::{
},
CompilerSettings,
};
use std::{collections::BTreeMap, path::PathBuf};
use std::{collections::BTreeMap, fmt::Write, path::PathBuf};

foundry_config::impl_figment_convert!(Eip712Args, opts);

Expand Down Expand Up @@ -62,9 +62,7 @@ impl Eip712Args {
};

for (id, _) in structs_in_target {
if let Some(resolved) =
resolver.resolve_struct_eip712(id, &mut Default::default(), true)?
{
if let Some(resolved) = resolver.resolve_struct_eip712(id)? {
println!("{resolved}");
println!();
}
Expand Down Expand Up @@ -128,14 +126,19 @@ impl Resolver {
///
/// Returns `None` if struct contains any fields that are not supported by EIP-712 (e.g.
/// mappings or function pointers).
pub fn resolve_struct_eip712(
pub fn resolve_struct_eip712(&self, id: usize) -> Result<Option<String>> {
self.resolve_eip712_inner(id, &mut Default::default(), true, None)
}

fn resolve_eip712_inner(
&self,
id: usize,
subtypes: &mut BTreeMap<String, usize>,
append_subtypes: bool,
rename: Option<&str>,
) -> Result<Option<String>> {
let def = &self.structs[&id];
let mut result = format!("{}(", def.name);
let mut result = format!("{}(", rename.unwrap_or(&def.name));

for (idx, member) in def.members.iter().enumerate() {
let Some(ty) = self.resolve_type(
Expand All @@ -146,9 +149,7 @@ impl Resolver {
return Ok(None)
};

result.push_str(&ty);
result.push(' ');
result.push_str(&member.name);
write!(result, "{ty} {name}", name = member.name)?;

if idx < def.members.len() - 1 {
result.push(',');
Expand All @@ -161,11 +162,14 @@ impl Resolver {
return Ok(Some(result))
}

for subtype_id in subtypes.values().copied().collect::<Vec<_>>() {
for (subtype_name, subtype_id) in
subtypes.iter().map(|(name, id)| (name.clone(), *id)).collect::<Vec<_>>()
{
if subtype_id == id {
continue
}
let Some(encoded_subtype) = self.resolve_struct_eip712(subtype_id, subtypes, false)?
let Some(encoded_subtype) =
self.resolve_eip712_inner(subtype_id, subtypes, false, Some(&subtype_name))?
else {
return Ok(None)
};
Expand Down Expand Up @@ -204,6 +208,17 @@ impl Resolver {
name.clone()
// Otherwise, try assigning a new name.
} else {
// iterate over members to check if they are resolvable and to populate subtypes
for member in &def.members {
if self.resolve_type(
member.type_name.as_ref().ok_or_eyre("missing type name")?,
subtypes,
)?
.is_none()
{
return Ok(None)
}
}
let mut i = 0;
let mut name = def.name.clone();
while subtypes.contains_key(&name) {
Expand Down
52 changes: 52 additions & 0 deletions crates/forge/tests/cli/eip712.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
forgetest!(test_eip712, |prj, cmd| {
let path = prj
.add_source(
"Structs",
r#"
library Structs {
struct Foo {
Bar bar;
}
struct Bar {
Art art;
}
struct Art {
uint256 id;
}
struct Complex {
Structs2.Foo foo2;
Foo[] foos;
}
}
library Structs2 {
struct Foo {
uint256 id;
}
}
"#,
)
.unwrap();

cmd.forge_fuse().args(["eip712", path.to_string_lossy().as_ref()]).assert_success().stdout_eq(
str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
No files changed, compilation skipped
Foo(Bar bar)Art(uint256 id)Bar(Art art)
Bar(Art art)Art(uint256 id)
Art(uint256 id)
Complex(Foo foo2,Foo_1[] foos)Art(uint256 id)Bar(Art art)Foo(uint256 id)Foo_1(Bar bar)
Foo(uint256 id)
"#]],
);
});
1 change: 1 addition & 0 deletions crates/forge/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod coverage;
mod create;
mod debug;
mod doc;
mod eip712;
mod multi_script;
mod script;
mod soldeer;
Expand Down

0 comments on commit 9b7a2d3

Please sign in to comment.