Skip to content
Closed

DNM #182

Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,28 @@ env:
POLKADOT_VERSION: polkadot-stable2506-2

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install nightly toolchain
run: rustup toolchain install nightly

- name: Install rustfmt for nightly
run: rustup component add --toolchain nightly rustfmt

- name: Cargo fmt
run: cargo +nightly fmt --all -- --check

cache-polkadot:
name: Build and cache Polkadot binaries on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: [fmt]
strategy:
matrix:
os: [ubuntu-24.04, macos-14]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ resolc-compiler-tests
workdir

!/schema.json
!/dev-genesis.json
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions crates/common/src/cached_fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! This module implements a cached file system allowing for results to be stored in-memory rather
//! rather being queried from the file system again.

use std::fs;
use std::io::{Error, Result};
use std::path::{Path, PathBuf};
use std::{
fs,
io::{Error, Result},
path::{Path, PathBuf},
};

use moka::sync::Cache;
use once_cell::sync::Lazy;
Expand Down
3 changes: 1 addition & 2 deletions crates/common/src/futures/poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::ops::ControlFlow;
use std::time::Duration;
use std::{ops::ControlFlow, time::Duration};

use anyhow::{Context as _, Result, anyhow};

Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/macros/define_wrapper_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ macro_rules! define_wrapper_type {
};
}

/// Technically not needed but this allows for the macro to be found in the `macros` module of the
/// crate in addition to being found in the root of the crate.
/// Technically not needed but this allows for the macro to be found in the `macros` module of
/// the crate in addition to being found in the root of the crate.
pub use {define_wrapper_type, impl_for_wrapper};
4 changes: 1 addition & 3 deletions crates/common/src/types/mode.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::types::VersionOrRequirement;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use std::str::FromStr;
use std::sync::LazyLock;
use std::{fmt::Display, str::FromStr, sync::LazyLock};

/// This represents a mode that a given test should be run with, if possible.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/common/src/types/private_key_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use alloy::primitives::U256;
use alloy::signers::local::PrivateKeySigner;
use alloy::{primitives::U256, signers::local::PrivateKeySigner};
use anyhow::{Context, Result, bail};

/// This is a sequential private key allocator. When instantiated, it allocated private keys in
Expand Down
3 changes: 1 addition & 2 deletions crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::{
pin::Pin,
};

use alloy::json_abi::JsonAbi;
use alloy::primitives::Address;
use alloy::{json_abi::JsonAbi, primitives::Address};
use anyhow::{Context as _, Result};
use semver::Version;
use serde::{Deserialize, Serialize};
Expand Down
75 changes: 37 additions & 38 deletions crates/compiler/src/revive_resolc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,45 +253,44 @@ impl SolidityCompiler for Resolc {
.evm
.and_then(|evm| evm.bytecode.clone())
.context("Unexpected - Contract compiled with resolc has no bytecode")?;
let abi = {
let metadata = contract_information
.metadata
.as_ref()
.context("No metadata found for the contract")?;
let solc_metadata_str = match metadata {
serde_json::Value::String(solc_metadata_str) => {
solc_metadata_str.as_str()
}
serde_json::Value::Object(metadata_object) => {
let solc_metadata_value = metadata_object
.get("solc_metadata")
.context("Contract doesn't have a 'solc_metadata' field")?;
solc_metadata_value
.as_str()
.context("The 'solc_metadata' field is not a string")?
}
serde_json::Value::Null
| serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::Array(_) => {
anyhow::bail!("Unsupported type of metadata {metadata:?}")
}
let abi =
{
let metadata = contract_information
.metadata
.as_ref()
.context("No metadata found for the contract")?;
let solc_metadata_str = match metadata {
serde_json::Value::String(solc_metadata_str) => {
solc_metadata_str.as_str()
}
serde_json::Value::Object(metadata_object) => {
let solc_metadata_value = metadata_object
.get("solc_metadata")
.context("Contract doesn't have a 'solc_metadata' field")?;
solc_metadata_value
.as_str()
.context("The 'solc_metadata' field is not a string")?
}
serde_json::Value::Null
| serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::Array(_) => {
anyhow::bail!("Unsupported type of metadata {metadata:?}")
}
};
let solc_metadata =
serde_json::from_str::<serde_json::Value>(solc_metadata_str).context(
"Failed to deserialize the solc_metadata as a serde_json generic value",
)?;
let output_value = solc_metadata
.get("output")
.context("solc_metadata doesn't have an output field")?;
let abi_value = output_value
.get("abi")
.context("solc_metadata output doesn't contain an abi field")?;
serde_json::from_value::<JsonAbi>(abi_value.clone())
.context("ABI found in solc_metadata output is not valid ABI")?
};
let solc_metadata = serde_json::from_str::<serde_json::Value>(
solc_metadata_str,
)
.context(
"Failed to deserialize the solc_metadata as a serde_json generic value",
)?;
let output_value = solc_metadata
.get("output")
.context("solc_metadata doesn't have an output field")?;
let abi_value = output_value
.get("abi")
.context("solc_metadata output doesn't contain an abi field")?;
serde_json::from_value::<JsonAbi>(abi_value.clone())
.context("ABI found in solc_metadata output is not valid ABI")?
};
map.insert(contract_name, (bytecode.object, abi));
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/compiler/src/solc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use foundry_compilers_artifacts::{
output_selection::{
BytecodeOutputSelection, ContractOutputSelection, EvmOutputSelection, OutputSelection,
},
solc::CompilerOutput as SolcOutput,
solc::*,
solc::{CompilerOutput as SolcOutput, *},
};
use semver::Version;
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
Expand Down Expand Up @@ -284,8 +283,9 @@ impl SolidityCompiler for Solc {
_optimize_setting: ModeOptimizerSetting,
pipeline: ModePipeline,
) -> bool {
// solc 0.8.13 and above supports --via-ir, and less than that does not. Thus, we support mode E
// (ie no Yul IR) in either case, but only support Y (via Yul IR) if the compiler is new enough.
// solc 0.8.13 and above supports --via-ir, and less than that does not. Thus, we support
// mode E (ie no Yul IR) in either case, but only support Y (via Yul IR) if the compiler
// is new enough.
pipeline == ModePipeline::ViaEVMAssembly
|| (pipeline == ModePipeline::ViaYulIR && self.compiler_supports_yul())
}
Expand Down
28 changes: 14 additions & 14 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ impl AsRef<ReportConfiguration> for Context {

#[derive(Clone, Debug, Parser, Serialize)]
pub struct TestExecutionContext {
/// The working directory that the program will use for all of the temporary artifacts needed at
/// runtime.
/// The working directory that the program will use for all of the temporary artifacts needed
/// at runtime.
///
/// If not specified, then a temporary directory will be created and used by the program for all
/// temporary artifacts.
/// If not specified, then a temporary directory will be created and used by the program for
/// all temporary artifacts.
#[clap(
short,
long,
Expand Down Expand Up @@ -282,11 +282,11 @@ pub struct TestExecutionContext {

#[derive(Clone, Debug, Parser, Serialize)]
pub struct BenchmarkingContext {
/// The working directory that the program will use for all of the temporary artifacts needed at
/// runtime.
/// The working directory that the program will use for all of the temporary artifacts needed
/// at runtime.
///
/// If not specified, then a temporary directory will be created and used by the program for all
/// temporary artifacts.
/// If not specified, then a temporary directory will be created and used by the program for
/// all temporary artifacts.
#[clap(
short,
long,
Expand Down Expand Up @@ -580,8 +580,8 @@ pub struct ResolcConfiguration {
pub struct PolkadotParachainConfiguration {
/// Specifies the path of the polkadot-parachain node to be used by the tool.
///
/// If this is not specified, then the tool assumes that it should use the polkadot-parachain binary
/// that's provided in the user's $PATH.
/// If this is not specified, then the tool assumes that it should use the polkadot-parachain
/// binary that's provided in the user's $PATH.
#[clap(
id = "polkadot-parachain.path",
long = "polkadot-parachain.path",
Expand Down Expand Up @@ -624,8 +624,8 @@ pub struct GethConfiguration {
pub struct KurtosisConfiguration {
/// Specifies the path of the kurtosis node to be used by the tool.
///
/// If this is not specified, then the tool assumes that it should use the kurtosis binary that's
/// provided in the user's $PATH.
/// If this is not specified, then the tool assumes that it should use the kurtosis binary
/// that's provided in the user's $PATH.
#[clap(
id = "kurtosis.path",
long = "kurtosis.path",
Expand Down Expand Up @@ -663,8 +663,8 @@ pub struct KitchensinkConfiguration {
pub struct ReviveDevNodeConfiguration {
/// Specifies the path of the revive dev node to be used by the tool.
///
/// If this is not specified, then the tool assumes that it should use the revive dev node binary
/// that's provided in the user's $PATH.
/// If this is not specified, then the tool assumes that it should use the revive dev node
/// binary that's provided in the user's $PATH.
#[clap(
id = "revive-dev-node.path",
long = "revive-dev-node.path",
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/differential_benchmarks/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub struct Driver<'a, I> {
/// The definition of the test that the driver is instructed to execute.
test_definition: &'a TestDefinition<'a>,

/// The private key allocator used by this driver and other drivers when account allocations are
/// needed.
/// The private key allocator used by this driver and other drivers when account allocations
/// are needed.
private_key_allocator: Arc<Mutex<PrivateKeyAllocator>>,

/// The execution state associated with the platform.
Expand Down
7 changes: 4 additions & 3 deletions crates/core/src/differential_benchmarks/execution_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use revive_dt_format::metadata::{ContractIdent, ContractInstance};
#[derive(Clone)]
/// The state associated with the test execution of one of the workloads.
pub struct ExecutionState {
/// The compiled contracts, these contracts have been compiled and have had the libraries linked
/// against them and therefore they're ready to be deployed on-demand.
/// The compiled contracts, these contracts have been compiled and have had the libraries
/// linked against them and therefore they're ready to be deployed on-demand.
pub compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>,

/// A map of all of the deployed contracts and information about them.
pub deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>,

/// This map stores the variables used for each one of the cases contained in the metadata file.
/// This map stores the variables used for each one of the cases contained in the metadata
/// file.
pub variables: HashMap<String, U256>,
}

Expand Down
27 changes: 22 additions & 5 deletions crates/core/src/differential_tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ pub struct PlatformDriver<'a, I> {
/// The definition of the test that the driver is instructed to execute.
test_definition: &'a TestDefinition<'a>,

/// The private key allocator used by this driver and other drivers when account allocations are
/// needed.
/// The private key allocator used by this driver and other drivers when account allocations
/// are needed.
private_key_allocator: Arc<Mutex<PrivateKeyAllocator>>,

/// The execution state associated with the platform.
Expand Down Expand Up @@ -415,9 +415,13 @@ where
let caller = {
let context = self.default_resolution_context();
let resolver = self.platform_information.node.resolver().await?;
step.caller
let resolved = step
.caller
.resolve_address(resolver.as_ref(), context)
.await?
.await?;
self.platform_information
.node
.resolve_signer_or_default(resolved)
};
if let (_, _, Some(receipt)) = self
.get_or_deploy_contract_instance(&instance, caller, calldata, value)
Expand Down Expand Up @@ -445,7 +449,7 @@ where
.context("Failed to find deployment receipt for constructor call"),
Method::Fallback | Method::FunctionName(_) => {
let resolver = self.platform_information.node.resolver().await?;
let tx = match step
let mut tx = match step
.as_transaction(resolver.as_ref(), self.default_resolution_context())
.await
{
Expand All @@ -455,6 +459,15 @@ where
}
};

// Resolve the signer to ensure we use an address that has keys
if let Some(from) = tx.from {
tx.from = Some(
self.platform_information
.node
.resolve_signer_or_default(from),
);
}

self.platform_information.node.execute_transaction(tx).await
}
}
Expand Down Expand Up @@ -954,6 +967,10 @@ where
}

let tx = {
let deployer = self
.platform_information
.node
.resolve_signer_or_default(deployer);
let tx = TransactionRequest::default().from(deployer);
let tx = match value {
Some(ref value) => tx.value(value.into_inner()),
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/differential_tests/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::{
time::{Duration, Instant},
};

use crate::Platform;
use anyhow::Context as _;
use futures::{FutureExt, StreamExt};
use revive_dt_common::types::PrivateKeyAllocator;
use revive_dt_core::Platform;
use tokio::sync::{Mutex, RwLock, Semaphore};
use tracing::{Instrument, error, info, info_span, instrument};

Expand Down
Loading
Loading