mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-22 07:57:58 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c47b66de3b | |||
| e5a898a0b9 | |||
| f67a9bf643 | |||
| 67d767ffde | |||
| f7fbe094ec |
Generated
+2
@@ -4095,6 +4095,7 @@ dependencies = [
|
||||
"alloy-primitives",
|
||||
"alloy-sol-types",
|
||||
"anyhow",
|
||||
"revive-common",
|
||||
"revive-dt-common",
|
||||
"semver 1.0.26",
|
||||
"serde",
|
||||
@@ -4109,6 +4110,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"alloy",
|
||||
"anyhow",
|
||||
"revive-common",
|
||||
"revive-dt-common",
|
||||
"revive-dt-config",
|
||||
"revive-dt-format",
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2024"
|
||||
repository = "https://github.com/paritytech/revive-differential-testing.git"
|
||||
rust-version = "1.85.0"
|
||||
rust-version = "1.87.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
revive-dt-common = { version = "0.1.0", path = "crates/common" }
|
||||
|
||||
@@ -8,6 +8,18 @@
|
||||
{
|
||||
"name": "first",
|
||||
"inputs": [
|
||||
{
|
||||
"address": "0xdeadbeef00000000000000000000000000000042",
|
||||
"expected_balance": "1233"
|
||||
},
|
||||
{
|
||||
"address": "0xdeadbeef00000000000000000000000000000042",
|
||||
"is_storage_empty": true
|
||||
},
|
||||
{
|
||||
"address": "0xdeadbeef00000000000000000000000000000042",
|
||||
"is_storage_empty": false
|
||||
},
|
||||
{
|
||||
"instance": "WBTC_1",
|
||||
"method": "#deployer",
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
use std::{borrow::Cow, collections::HashSet, path::PathBuf};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashSet,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
/// An iterator that finds files of a certain extension in the provided directory. You can think of
|
||||
/// this a glob pattern similar to: `${path}/**/*.md`
|
||||
@@ -18,10 +22,10 @@ pub struct FilesWithExtensionIterator {
|
||||
}
|
||||
|
||||
impl FilesWithExtensionIterator {
|
||||
pub fn new(root_directory: PathBuf) -> Self {
|
||||
pub fn new(root_directory: impl AsRef<Path>) -> Self {
|
||||
Self {
|
||||
allowed_extensions: Default::default(),
|
||||
directories_to_search: vec![root_directory],
|
||||
directories_to_search: vec![root_directory.as_ref().to_path_buf()],
|
||||
files_matching_allowed_extensions: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
+222
-25
@@ -4,6 +4,7 @@ use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use alloy::consensus::EMPTY_ROOT_HASH;
|
||||
use alloy::hex;
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use alloy::network::{Ethereum, TransactionBuilder};
|
||||
@@ -26,9 +27,12 @@ use revive_dt_format::traits::{ResolutionContext, ResolverApi};
|
||||
use semver::Version;
|
||||
|
||||
use revive_dt_format::case::{Case, CaseIdx};
|
||||
use revive_dt_format::input::{Calldata, EtherValue, Expected, ExpectedOutput, Method};
|
||||
use revive_dt_format::input::{
|
||||
BalanceAssertion, Calldata, EtherValue, Expected, ExpectedOutput, Input, Method,
|
||||
StorageEmptyAssertion,
|
||||
};
|
||||
use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdent};
|
||||
use revive_dt_format::{input::Input, metadata::Metadata};
|
||||
use revive_dt_format::{input::Step, metadata::Metadata};
|
||||
use revive_dt_node::Node;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use tracing::Instrument;
|
||||
@@ -70,6 +74,32 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_step(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
case_idx: CaseIdx,
|
||||
step: &Step,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<StepOutput> {
|
||||
match step {
|
||||
Step::FunctionCall(input) => {
|
||||
let (receipt, geth_trace, diff_mode) =
|
||||
self.handle_input(metadata, case_idx, input, node).await?;
|
||||
Ok(StepOutput::FunctionCall(receipt, geth_trace, diff_mode))
|
||||
}
|
||||
Step::BalanceAssertion(balance_assertion) => {
|
||||
self.handle_balance_assertion(metadata, case_idx, balance_assertion, node)
|
||||
.await?;
|
||||
Ok(StepOutput::BalanceAssertion)
|
||||
}
|
||||
Step::StorageEmptyAssertion(storage_empty) => {
|
||||
self.handle_storage_empty(metadata, case_idx, storage_empty, node)
|
||||
.await?;
|
||||
Ok(StepOutput::StorageEmptyAssertion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_input(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
@@ -78,7 +108,7 @@ where
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
|
||||
let deployment_receipts = self
|
||||
.handle_contract_deployment(metadata, case_idx, input, node)
|
||||
.handle_input_contract_deployment(metadata, case_idx, input, node)
|
||||
.await?;
|
||||
let execution_receipt = self
|
||||
.handle_input_execution(input, deployment_receipts, node)
|
||||
@@ -93,8 +123,36 @@ where
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn handle_balance_assertion(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
_: CaseIdx,
|
||||
balance_assertion: &BalanceAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
self.handle_balance_assertion_contract_deployment(metadata, balance_assertion, node)
|
||||
.await?;
|
||||
self.handle_balance_assertion_execution(balance_assertion, node)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_storage_empty(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
_: CaseIdx,
|
||||
storage_empty: &StorageEmptyAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
self.handle_storage_empty_assertion_contract_deployment(metadata, storage_empty, node)
|
||||
.await?;
|
||||
self.handle_storage_empty_assertion_execution(storage_empty, node)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handles the contract deployment for a given input performing it if it needs to be performed.
|
||||
async fn handle_contract_deployment(
|
||||
async fn handle_input_contract_deployment(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
case_idx: CaseIdx,
|
||||
@@ -462,6 +520,128 @@ where
|
||||
Ok((execution_receipt, trace, diff))
|
||||
}
|
||||
|
||||
pub async fn handle_balance_assertion_contract_deployment(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
balance_assertion: &BalanceAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
let Some(instance) = balance_assertion
|
||||
.address
|
||||
.strip_prefix(".address")
|
||||
.map(ContractInstance::new)
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
self.get_or_deploy_contract_instance(
|
||||
&instance,
|
||||
metadata,
|
||||
Input::default_caller(),
|
||||
None,
|
||||
None,
|
||||
node,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_balance_assertion_execution(
|
||||
&mut self,
|
||||
BalanceAssertion {
|
||||
address: address_string,
|
||||
expected_balance: amount,
|
||||
..
|
||||
}: &BalanceAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
let address = Address::from_slice(
|
||||
Calldata::new_compound([address_string])
|
||||
.calldata(node, self.default_resolution_context())
|
||||
.await?
|
||||
.get(12..32)
|
||||
.expect("Can't fail"),
|
||||
);
|
||||
|
||||
let balance = node.balance_of(address).await?;
|
||||
|
||||
let expected = *amount;
|
||||
let actual = balance;
|
||||
if expected != actual {
|
||||
tracing::error!(%expected, %actual, %address, "Balance assertion failed");
|
||||
anyhow::bail!(
|
||||
"Balance assertion failed - Expected {} but got {} for {} resolved to {}",
|
||||
expected,
|
||||
actual,
|
||||
address_string,
|
||||
address,
|
||||
)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_storage_empty_assertion_contract_deployment(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
storage_empty_assertion: &StorageEmptyAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
let Some(instance) = storage_empty_assertion
|
||||
.address
|
||||
.strip_prefix(".address")
|
||||
.map(ContractInstance::new)
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
self.get_or_deploy_contract_instance(
|
||||
&instance,
|
||||
metadata,
|
||||
Input::default_caller(),
|
||||
None,
|
||||
None,
|
||||
node,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_storage_empty_assertion_execution(
|
||||
&mut self,
|
||||
StorageEmptyAssertion {
|
||||
address: address_string,
|
||||
is_storage_empty,
|
||||
..
|
||||
}: &StorageEmptyAssertion,
|
||||
node: &T::Blockchain,
|
||||
) -> anyhow::Result<()> {
|
||||
let address = Address::from_slice(
|
||||
Calldata::new_compound([address_string])
|
||||
.calldata(node, self.default_resolution_context())
|
||||
.await?
|
||||
.get(12..32)
|
||||
.expect("Can't fail"),
|
||||
);
|
||||
|
||||
let storage = node.latest_state_proof(address, Default::default()).await?;
|
||||
let is_empty = storage.storage_hash == EMPTY_ROOT_HASH;
|
||||
|
||||
let expected = is_storage_empty;
|
||||
let actual = is_empty;
|
||||
|
||||
if *expected != actual {
|
||||
tracing::error!(%expected, %actual, %address, "Storage Empty Assertion failed");
|
||||
anyhow::bail!(
|
||||
"Storage Empty Assertion failed - Expected {} but got {} for {} resolved to {}",
|
||||
expected,
|
||||
actual,
|
||||
address_string,
|
||||
address,
|
||||
)
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets the information of a deployed contract or library from the state. If it's found to not
|
||||
/// be deployed then it will be deployed.
|
||||
///
|
||||
@@ -651,38 +831,55 @@ where
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
let mut inputs_executed = 0;
|
||||
for (input_idx, input) in self.case.inputs_iterator().enumerate() {
|
||||
let tracing_span = tracing::info_span!("Handling input", input_idx);
|
||||
let mut steps_executed = 0;
|
||||
for (step_idx, step) in self.case.steps_iterator().enumerate() {
|
||||
let tracing_span = tracing::info_span!("Handling input", step_idx);
|
||||
|
||||
let (leader_receipt, _, leader_diff) = self
|
||||
let leader_step_output = self
|
||||
.leader_state
|
||||
.handle_input(self.metadata, self.case_idx, &input, self.leader_node)
|
||||
.handle_step(self.metadata, self.case_idx, &step, self.leader_node)
|
||||
.instrument(tracing_span.clone())
|
||||
.await?;
|
||||
let (follower_receipt, _, follower_diff) = self
|
||||
let follower_step_output = self
|
||||
.follower_state
|
||||
.handle_input(self.metadata, self.case_idx, &input, self.follower_node)
|
||||
.handle_step(self.metadata, self.case_idx, &step, self.follower_node)
|
||||
.instrument(tracing_span)
|
||||
.await?;
|
||||
match (leader_step_output, follower_step_output) {
|
||||
(
|
||||
StepOutput::FunctionCall(leader_receipt, _, leader_diff),
|
||||
StepOutput::FunctionCall(follower_receipt, _, follower_diff),
|
||||
) => {
|
||||
if leader_diff == follower_diff {
|
||||
tracing::debug!("State diffs match between leader and follower.");
|
||||
} else {
|
||||
tracing::debug!("State diffs mismatch between leader and follower.");
|
||||
Self::trace_diff_mode("Leader", &leader_diff);
|
||||
Self::trace_diff_mode("Follower", &follower_diff);
|
||||
}
|
||||
|
||||
if leader_diff == follower_diff {
|
||||
tracing::debug!("State diffs match between leader and follower.");
|
||||
} else {
|
||||
tracing::debug!("State diffs mismatch between leader and follower.");
|
||||
Self::trace_diff_mode("Leader", &leader_diff);
|
||||
Self::trace_diff_mode("Follower", &follower_diff);
|
||||
if leader_receipt.logs() != follower_receipt.logs() {
|
||||
tracing::debug!("Log/event mismatch between leader and follower.");
|
||||
tracing::trace!("Leader logs: {:?}", leader_receipt.logs());
|
||||
tracing::trace!("Follower logs: {:?}", follower_receipt.logs());
|
||||
}
|
||||
}
|
||||
(StepOutput::BalanceAssertion, StepOutput::BalanceAssertion) => {}
|
||||
(StepOutput::StorageEmptyAssertion, StepOutput::StorageEmptyAssertion) => {}
|
||||
_ => unreachable!("The two step outputs can not be of a different kind"),
|
||||
}
|
||||
|
||||
if leader_receipt.logs() != follower_receipt.logs() {
|
||||
tracing::debug!("Log/event mismatch between leader and follower.");
|
||||
tracing::trace!("Leader logs: {:?}", leader_receipt.logs());
|
||||
tracing::trace!("Follower logs: {:?}", follower_receipt.logs());
|
||||
}
|
||||
|
||||
inputs_executed += 1;
|
||||
steps_executed += 1;
|
||||
}
|
||||
|
||||
Ok(inputs_executed)
|
||||
Ok(steps_executed)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum StepOutput {
|
||||
FunctionCall(TransactionReceipt, GethTrace, DiffMode),
|
||||
BalanceAssertion,
|
||||
StorageEmptyAssertion,
|
||||
}
|
||||
|
||||
+28
-3
@@ -32,7 +32,7 @@ use revive_dt_core::{
|
||||
use revive_dt_format::{
|
||||
case::{Case, CaseIdx},
|
||||
corpus::Corpus,
|
||||
input::Input,
|
||||
input::{Input, Step},
|
||||
metadata::{ContractInstance, ContractPathAndIdent, Metadata, MetadataFile},
|
||||
mode::SolcMode,
|
||||
};
|
||||
@@ -177,6 +177,27 @@ where
|
||||
Some(false) | None => true,
|
||||
},
|
||||
)
|
||||
.filter(|(metadata_file_path, metadata, ..)| match metadata.required_evm_version {
|
||||
Some(evm_version_requirement) => {
|
||||
let is_allowed = evm_version_requirement
|
||||
.matches(&<L::Blockchain as revive_dt_node::Node>::evm_version())
|
||||
&& evm_version_requirement
|
||||
.matches(&<F::Blockchain as revive_dt_node::Node>::evm_version());
|
||||
|
||||
if !is_allowed {
|
||||
tracing::warn!(
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
leader_evm_version = %<L::Blockchain as revive_dt_node::Node>::evm_version(),
|
||||
follower_evm_version = %<F::Blockchain as revive_dt_node::Node>::evm_version(),
|
||||
version_requirement = %evm_version_requirement,
|
||||
"Skipped test since the EVM version requirement was not fulfilled."
|
||||
);
|
||||
}
|
||||
|
||||
is_allowed
|
||||
}
|
||||
None => true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let metadata_case_status = Arc::new(RwLock::new(test_cases.iter().fold(
|
||||
@@ -446,9 +467,13 @@ where
|
||||
// doing the deployments from different accounts and therefore we're not slowed down by
|
||||
// the nonce.
|
||||
let deployer_address = case
|
||||
.inputs
|
||||
.steps
|
||||
.iter()
|
||||
.map(|input| input.caller)
|
||||
.filter_map(|step| match step {
|
||||
Step::FunctionCall(input) => Some(input.caller),
|
||||
Step::BalanceAssertion(..) => None,
|
||||
Step::StorageEmptyAssertion(..) => None,
|
||||
})
|
||||
.next()
|
||||
.unwrap_or(Input::default_caller());
|
||||
let leader_tx = TransactionBuilder::<Ethereum>::with_deploy_code(
|
||||
|
||||
@@ -11,6 +11,8 @@ rust-version.workspace = true
|
||||
[dependencies]
|
||||
revive-dt-common = { workspace = true }
|
||||
|
||||
revive-common = { workspace = true }
|
||||
|
||||
alloy = { workspace = true }
|
||||
alloy-primitives = { workspace = true }
|
||||
alloy-sol-types = { workspace = true }
|
||||
|
||||
@@ -3,30 +3,42 @@ use serde::{Deserialize, Serialize};
|
||||
use revive_dt_common::macros::define_wrapper_type;
|
||||
|
||||
use crate::{
|
||||
input::{Expected, Input},
|
||||
input::{Expected, Step},
|
||||
mode::Mode,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||
pub struct Case {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub modes: Option<Vec<Mode>>,
|
||||
pub inputs: Vec<Input>,
|
||||
#[serde(rename = "inputs")]
|
||||
pub steps: Vec<Step>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub group: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expected: Option<Expected>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ignore: Option<bool>,
|
||||
}
|
||||
|
||||
impl Case {
|
||||
pub fn inputs_iterator(&self) -> impl Iterator<Item = Input> {
|
||||
let inputs_len = self.inputs.len();
|
||||
self.inputs
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
pub fn steps_iterator(&self) -> impl Iterator<Item = Step> {
|
||||
let steps_len = self.steps.len();
|
||||
self.steps
|
||||
.clone()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(move |(idx, mut input)| {
|
||||
if idx + 1 == inputs_len {
|
||||
.map(move |(idx, mut step)| {
|
||||
let Step::FunctionCall(ref mut input) = step else {
|
||||
return step;
|
||||
};
|
||||
|
||||
if idx + 1 == steps_len {
|
||||
if input.expected.is_none() {
|
||||
input.expected = self.expected.clone();
|
||||
}
|
||||
@@ -36,9 +48,9 @@ impl Case {
|
||||
// the case? What are we supposed to do with that final expected field on the
|
||||
// case?
|
||||
|
||||
input
|
||||
step
|
||||
} else {
|
||||
input
|
||||
step
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,22 +17,78 @@ use revive_dt_common::macros::define_wrapper_type;
|
||||
use crate::traits::ResolverApi;
|
||||
use crate::{metadata::ContractInstance, traits::ResolutionContext};
|
||||
|
||||
/// A test step.
|
||||
///
|
||||
/// A test step can be anything. It could be an invocation to a function, an assertion, or any other
|
||||
/// action that needs to be run or executed on the nodes used in the tests.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum Step {
|
||||
/// A function call or an invocation to some function on some smart contract.
|
||||
FunctionCall(Box<Input>),
|
||||
/// A step for performing a balance assertion on some account or contract.
|
||||
BalanceAssertion(Box<BalanceAssertion>),
|
||||
/// A step for asserting that the storage of some contract or account is empty.
|
||||
StorageEmptyAssertion(Box<StorageEmptyAssertion>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct Input {
|
||||
#[serde(default = "Input::default_caller")]
|
||||
pub caller: Address,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
#[serde(default = "Input::default_instance")]
|
||||
pub instance: ContractInstance,
|
||||
pub method: Method,
|
||||
#[serde(default)]
|
||||
pub calldata: Calldata,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expected: Option<Expected>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub value: Option<EtherValue>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub storage: Option<HashMap<String, Calldata>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub variable_assignments: Option<VariableAssignments>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct BalanceAssertion {
|
||||
/// An optional comment on the balance assertion.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
|
||||
/// The address that the balance assertion should be done on.
|
||||
///
|
||||
/// This is a string which will be resolved into an address when being processed. Therefore,
|
||||
/// this could be a normal hex address, a variable such as `Test.address`, or perhaps even a
|
||||
/// full on variable like `$VARIABLE:Uniswap`. It follows the same resolution rules that are
|
||||
/// followed in the calldata.
|
||||
pub address: String,
|
||||
|
||||
/// The amount of balance to assert that the account or contract has.
|
||||
pub expected_balance: U256,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct StorageEmptyAssertion {
|
||||
/// An optional comment on the storage empty assertion.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub comment: Option<String>,
|
||||
|
||||
/// The address that the balance assertion should be done on.
|
||||
///
|
||||
/// This is a string which will be resolved into an address when being processed. Therefore,
|
||||
/// this could be a normal hex address, a variable such as `Test.address`, or perhaps even a
|
||||
/// full on variable like `$VARIABLE:Uniswap`. It follows the same resolution rules that are
|
||||
/// followed in the calldata.
|
||||
pub address: String,
|
||||
|
||||
/// A boolean of whether the storage of the address is empty or not.
|
||||
pub is_storage_empty: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum Expected {
|
||||
@@ -43,8 +99,11 @@ pub enum Expected {
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct ExpectedOutput {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub compiler_version: Option<VersionReq>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub return_data: Option<Calldata>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub events: Option<Vec<Event>>,
|
||||
#[serde(default)]
|
||||
pub exception: bool,
|
||||
@@ -52,6 +111,7 @@ pub struct ExpectedOutput {
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct Event {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub address: Option<String>,
|
||||
pub topics: Vec<String>,
|
||||
pub values: Calldata,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::BTreeMap,
|
||||
fmt::Display,
|
||||
fs::{File, read_to_string},
|
||||
@@ -9,6 +10,7 @@ use std::{
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::{iterators::FilesWithExtensionIterator, macros::define_wrapper_type};
|
||||
|
||||
use crate::{
|
||||
@@ -45,13 +47,25 @@ impl Deref for MetadataFile {
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||
pub struct Metadata {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub targets: Option<Vec<String>>,
|
||||
pub cases: Vec<Case>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdent>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub libraries: Option<BTreeMap<PathBuf, BTreeMap<ContractIdent, ContractInstance>>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ignore: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub modes: Option<Vec<Mode>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_path: Option<PathBuf>,
|
||||
|
||||
/// This field specifies an EVM version requirement that the test case has
|
||||
/// where the test might be run of the evm version of the nodes match the
|
||||
/// evm version specified here.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub required_evm_version: Option<EvmVersionRequirement>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
@@ -342,6 +356,131 @@ impl From<ContractPathAndIdent> for String {
|
||||
}
|
||||
}
|
||||
|
||||
/// An EVM version requirement that the test case has. This gets serialized and
|
||||
/// deserialized from and into [`String`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(try_from = "String", into = "String")]
|
||||
pub struct EvmVersionRequirement {
|
||||
ordering: Ordering,
|
||||
or_equal: bool,
|
||||
evm_version: EVMVersion,
|
||||
}
|
||||
|
||||
impl EvmVersionRequirement {
|
||||
pub fn new_greater_than_or_equals(version: EVMVersion) -> Self {
|
||||
Self {
|
||||
ordering: Ordering::Greater,
|
||||
or_equal: true,
|
||||
evm_version: version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_greater_than(version: EVMVersion) -> Self {
|
||||
Self {
|
||||
ordering: Ordering::Greater,
|
||||
or_equal: false,
|
||||
evm_version: version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_equals(version: EVMVersion) -> Self {
|
||||
Self {
|
||||
ordering: Ordering::Equal,
|
||||
or_equal: false,
|
||||
evm_version: version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_less_than(version: EVMVersion) -> Self {
|
||||
Self {
|
||||
ordering: Ordering::Less,
|
||||
or_equal: false,
|
||||
evm_version: version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_less_than_or_equals(version: EVMVersion) -> Self {
|
||||
Self {
|
||||
ordering: Ordering::Less,
|
||||
or_equal: true,
|
||||
evm_version: version,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matches(&self, other: &EVMVersion) -> bool {
|
||||
let ordering = other.cmp(&self.evm_version);
|
||||
ordering == self.ordering || (self.or_equal && matches!(ordering, Ordering::Equal))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for EvmVersionRequirement {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self {
|
||||
ordering,
|
||||
or_equal,
|
||||
evm_version,
|
||||
} = self;
|
||||
match ordering {
|
||||
Ordering::Less => write!(f, "<")?,
|
||||
Ordering::Equal => write!(f, "=")?,
|
||||
Ordering::Greater => write!(f, ">")?,
|
||||
}
|
||||
if *or_equal && !matches!(ordering, Ordering::Equal) {
|
||||
write!(f, "=")?;
|
||||
}
|
||||
write!(f, "{evm_version}")
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for EvmVersionRequirement {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.as_bytes() {
|
||||
[b'>', b'=', remaining @ ..] => Ok(Self {
|
||||
ordering: Ordering::Greater,
|
||||
or_equal: true,
|
||||
evm_version: str::from_utf8(remaining)?.try_into()?,
|
||||
}),
|
||||
[b'>', remaining @ ..] => Ok(Self {
|
||||
ordering: Ordering::Greater,
|
||||
or_equal: false,
|
||||
evm_version: str::from_utf8(remaining)?.try_into()?,
|
||||
}),
|
||||
[b'<', b'=', remaining @ ..] => Ok(Self {
|
||||
ordering: Ordering::Less,
|
||||
or_equal: true,
|
||||
evm_version: str::from_utf8(remaining)?.try_into()?,
|
||||
}),
|
||||
[b'<', remaining @ ..] => Ok(Self {
|
||||
ordering: Ordering::Less,
|
||||
or_equal: false,
|
||||
evm_version: str::from_utf8(remaining)?.try_into()?,
|
||||
}),
|
||||
[b'=', remaining @ ..] => Ok(Self {
|
||||
ordering: Ordering::Equal,
|
||||
or_equal: false,
|
||||
evm_version: str::from_utf8(remaining)?.try_into()?,
|
||||
}),
|
||||
_ => anyhow::bail!("Invalid EVM version requirement {s}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for EvmVersionRequirement {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
value.parse()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EvmVersionRequirement> for String {
|
||||
fn from(value: EvmVersionRequirement) -> Self {
|
||||
value.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! This crate implements all node interactions.
|
||||
|
||||
use alloy::primitives::{Address, StorageKey, U256};
|
||||
use alloy::rpc::types::trace::geth::{DiffMode, GethDebugTracingOptions, GethTrace};
|
||||
use alloy::rpc::types::{TransactionReceipt, TransactionRequest};
|
||||
use alloy::rpc::types::{EIP1186AccountProofResponse, TransactionReceipt, TransactionRequest};
|
||||
use anyhow::Result;
|
||||
|
||||
/// An interface for all interactions with Ethereum compatible nodes.
|
||||
@@ -21,4 +22,14 @@ pub trait EthereumNode {
|
||||
|
||||
/// Returns the state diff of the transaction hash in the [TransactionReceipt].
|
||||
fn state_diff(&self, receipt: &TransactionReceipt) -> impl Future<Output = Result<DiffMode>>;
|
||||
|
||||
/// Returns the balance of the provided [`Address`] back.
|
||||
fn balance_of(&self, address: Address) -> impl Future<Output = Result<U256>>;
|
||||
|
||||
/// Returns the latest storage proof of the provided [`Address`]
|
||||
fn latest_state_proof(
|
||||
&self,
|
||||
address: Address,
|
||||
keys: Vec<StorageKey>,
|
||||
) -> impl Future<Output = Result<EIP1186AccountProofResponse>>;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ alloy = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
revive-common = { workspace = true }
|
||||
revive-dt-common = { workspace = true }
|
||||
revive-dt-config = { workspace = true }
|
||||
revive-dt-format = { workspace = true }
|
||||
|
||||
+32
-2
@@ -17,19 +17,22 @@ use alloy::{
|
||||
eips::BlockNumberOrTag,
|
||||
genesis::{Genesis, GenesisAccount},
|
||||
network::{Ethereum, EthereumWallet, NetworkWallet},
|
||||
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, TxHash, U256},
|
||||
primitives::{
|
||||
Address, BlockHash, BlockNumber, BlockTimestamp, FixedBytes, StorageKey, TxHash, U256,
|
||||
},
|
||||
providers::{
|
||||
Provider, ProviderBuilder,
|
||||
ext::DebugApi,
|
||||
fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller},
|
||||
},
|
||||
rpc::types::{
|
||||
TransactionReceipt, TransactionRequest,
|
||||
EIP1186AccountProofResponse, TransactionReceipt, TransactionRequest,
|
||||
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
|
||||
},
|
||||
signers::local::PrivateKeySigner,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use revive_common::EVMVersion;
|
||||
use tracing::{Instrument, Level};
|
||||
|
||||
use revive_dt_common::{fs::clear_directory, futures::poll};
|
||||
@@ -371,6 +374,29 @@ impl EthereumNode for GethNode {
|
||||
_ => anyhow::bail!("expected a diff mode trace"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
||||
self.provider()
|
||||
.await?
|
||||
.get_balance(address)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
async fn latest_state_proof(
|
||||
&self,
|
||||
address: Address,
|
||||
keys: Vec<StorageKey>,
|
||||
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
||||
self.provider()
|
||||
.await?
|
||||
.get_proof(address, keys)
|
||||
.latest()
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl ResolverApi for GethNode {
|
||||
@@ -554,6 +580,10 @@ impl Node for GethNode {
|
||||
Some(targets) => targets.iter().any(|str| str.as_str() == "evm"),
|
||||
}
|
||||
}
|
||||
|
||||
fn evm_version() -> EVMVersion {
|
||||
EVMVersion::Cancun
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for GethNode {
|
||||
|
||||
@@ -17,7 +17,7 @@ use alloy::{
|
||||
},
|
||||
primitives::{
|
||||
Address, B64, B256, BlockHash, BlockNumber, BlockTimestamp, Bloom, Bytes, FixedBytes,
|
||||
TxHash, U256,
|
||||
StorageKey, TxHash, U256,
|
||||
},
|
||||
providers::{
|
||||
Provider, ProviderBuilder,
|
||||
@@ -25,13 +25,14 @@ use alloy::{
|
||||
fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller},
|
||||
},
|
||||
rpc::types::{
|
||||
TransactionReceipt,
|
||||
EIP1186AccountProofResponse, TransactionReceipt,
|
||||
eth::{Block, Header, Transaction},
|
||||
trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame},
|
||||
},
|
||||
signers::local::PrivateKeySigner,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::fs::clear_directory;
|
||||
use revive_dt_format::traits::ResolverApi;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -428,6 +429,29 @@ impl EthereumNode for KitchensinkNode {
|
||||
_ => anyhow::bail!("expected a diff mode trace"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
||||
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
||||
self.provider()
|
||||
.await?
|
||||
.get_balance(address)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
||||
async fn latest_state_proof(
|
||||
&self,
|
||||
address: Address,
|
||||
keys: Vec<StorageKey>,
|
||||
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
||||
self.provider()
|
||||
.await?
|
||||
.get_proof(address, keys)
|
||||
.latest()
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl ResolverApi for KitchensinkNode {
|
||||
@@ -615,6 +639,10 @@ impl Node for KitchensinkNode {
|
||||
Some(targets) => targets.iter().any(|str| str.as_str() == "pvm"),
|
||||
}
|
||||
}
|
||||
|
||||
fn evm_version() -> EVMVersion {
|
||||
EVMVersion::Cancun
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for KitchensinkNode {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! This crate implements the testing nodes.
|
||||
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
|
||||
@@ -36,4 +37,7 @@ pub trait Node: EthereumNode {
|
||||
/// Given a list of targets from the metadata file, this function determines if the metadata
|
||||
/// file can be ran on this node or not.
|
||||
fn matches_target(&self, targets: Option<&[String]>) -> bool;
|
||||
|
||||
/// Returns the EVM version of the node.
|
||||
fn evm_version() -> EVMVersion;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user