Compare commits

...

1 Commits

Author SHA1 Message Date
Omar Abdulla 49cbc51546 Generate schema for the metadata file 2025-09-08 17:09:35 +03:00
12 changed files with 709 additions and 34 deletions
+2
View File
@@ -11,3 +11,5 @@ node_modules
profile.json.gz profile.json.gz
resolc-compiler-tests resolc-compiler-tests
workdir workdir
!/schema.json
Generated
+27
View File
@@ -4528,6 +4528,7 @@ dependencies = [
"revive-dt-node", "revive-dt-node",
"revive-dt-node-interaction", "revive-dt-node-interaction",
"revive-dt-report", "revive-dt-report",
"schemars 1.0.4",
"semver 1.0.26", "semver 1.0.26",
"serde", "serde",
"serde_json", "serde_json",
@@ -4549,6 +4550,7 @@ dependencies = [
"regex", "regex",
"revive-common", "revive-common",
"revive-dt-common", "revive-dt-common",
"schemars 1.0.4",
"semver 1.0.26", "semver 1.0.26",
"serde", "serde",
"serde_json", "serde_json",
@@ -4872,10 +4874,24 @@ checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0"
dependencies = [ dependencies = [
"dyn-clone", "dyn-clone",
"ref-cast", "ref-cast",
"schemars_derive",
"semver 1.0.26",
"serde", "serde",
"serde_json", "serde_json",
] ]
[[package]]
name = "schemars_derive"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d020396d1d138dc19f1165df7545479dcd58d93810dc5d646a16e55abefa80"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn 2.0.101",
]
[[package]] [[package]]
name = "schnellru" name = "schnellru"
version = "0.2.4" version = "0.2.4"
@@ -5060,6 +5076,17 @@ dependencies = [
"syn 2.0.101", "syn 2.0.101",
] ]
[[package]]
name = "serde_derive_internals"
version = "0.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.101",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.140" version = "1.0.140"
+1
View File
@@ -37,6 +37,7 @@ moka = "0.12.10"
paste = "1.0.15" paste = "1.0.15"
reqwest = { version = "0.12.15", features = ["json"] } reqwest = { version = "0.12.15", features = ["json"] }
once_cell = "1.21" once_cell = "1.21"
schemars = { version = "1.0.4", features = ["semver1"] }
semver = { version = "1.0", features = ["serde"] } semver = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", default-features = false, features = ["derive"] } serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = [ serde_json = { version = "1.0", default-features = false, features = [
+5 -1
View File
@@ -27,7 +27,9 @@ use temp_dir::TempDir;
#[command(name = "retester")] #[command(name = "retester")]
pub enum Context { pub enum Context {
/// Executes tests in the MatterLabs format differentially against a leader and a follower. /// Executes tests in the MatterLabs format differentially against a leader and a follower.
ExecuteTests(ExecutionContext), ExecuteTests(Box<ExecutionContext>),
/// Exports the JSON schema of the MatterLabs test format used by the tool.
ExportJsonSchema,
} }
impl Context { impl Context {
@@ -44,6 +46,7 @@ impl AsRef<WorkingDirectoryConfiguration> for Context {
fn as_ref(&self) -> &WorkingDirectoryConfiguration { fn as_ref(&self) -> &WorkingDirectoryConfiguration {
match self { match self {
Context::ExecuteTests(execution_context) => &execution_context.working_directory, Context::ExecuteTests(execution_context) => &execution_context.working_directory,
Context::ExportJsonSchema => unreachable!(),
} }
} }
} }
@@ -52,6 +55,7 @@ impl AsRef<ReportConfiguration> for Context {
fn as_ref(&self) -> &ReportConfiguration { fn as_ref(&self) -> &ReportConfiguration {
match self { match self {
Context::ExecuteTests(execution_context) => &execution_context.report_configuration, Context::ExecuteTests(execution_context) => &execution_context.report_configuration,
Context::ExportJsonSchema => unreachable!(),
} }
} }
} }
+1
View File
@@ -32,6 +32,7 @@ tokio = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
tracing-appender = { workspace = true } tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true } tracing-subscriber = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true } semver = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
+8 -2
View File
@@ -23,6 +23,7 @@ use revive_dt_report::{
NodeDesignation, ReportAggregator, Reporter, ReporterEvent, TestCaseStatus, NodeDesignation, ReportAggregator, Reporter, ReporterEvent, TestCaseStatus,
TestSpecificReporter, TestSpecifier, TestSpecificReporter, TestSpecifier,
}; };
use schemars::schema_for;
use serde_json::{Value, json}; use serde_json::{Value, json};
use tokio::try_join; use tokio::try_join;
use tracing::{debug, error, info, info_span, instrument}; use tracing::{debug, error, info, info_span, instrument};
@@ -39,7 +40,7 @@ use revive_dt_format::{
case::{Case, CaseIdx}, case::{Case, CaseIdx},
corpus::Corpus, corpus::Corpus,
input::{Input, Step}, input::{Input, Step},
metadata::{ContractPathAndIdent, MetadataFile}, metadata::{ContractPathAndIdent, Metadata, MetadataFile},
mode::ParsedMode, mode::ParsedMode,
}; };
use revive_dt_node::{Node, pool::NodePool}; use revive_dt_node::{Node, pool::NodePool};
@@ -96,11 +97,16 @@ fn main() -> anyhow::Result<()> {
.build() .build()
.expect("Failed building the Runtime") .expect("Failed building the Runtime")
.block_on(async move { .block_on(async move {
execute_corpus(context, &tests, reporter, report_aggregator_task) execute_corpus(*context, &tests, reporter, report_aggregator_task)
.await .await
.context("Failed to execute corpus") .context("Failed to execute corpus")
}) })
} }
Context::ExportJsonSchema => {
let schema = schema_for!(Metadata);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
Ok(())
}
} }
} }
+1
View File
@@ -20,6 +20,7 @@ anyhow = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
schemars = { workspace = true }
semver = { workspace = true } semver = { workspace = true }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true } serde_json = { workspace = true }
+24 -1
View File
@@ -1,3 +1,4 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use revive_dt_common::{macros::define_wrapper_type, types::Mode}; use revive_dt_common::{macros::define_wrapper_type, types::Mode};
@@ -7,26 +8,48 @@ use crate::{
mode::ParsedMode, mode::ParsedMode,
}; };
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)] #[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)]
pub struct Case { pub struct Case {
/// An optional name of the test case.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>, pub name: Option<String>,
/// An optional comment on the case which has no impact on the execution in any way.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<String>, pub comment: Option<String>,
/// This represents a mode that has been parsed from test metadata.
///
/// Mode strings can take the following form (in pseudo-regex):
///
/// ```text
/// [YEILV][+-]? (M[0123sz])? <semver>?
/// ```
///
/// If this is provided then it takes higher priority than the modes specified in the metadata
/// file.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub modes: Option<Vec<ParsedMode>>, pub modes: Option<Vec<ParsedMode>>,
/// The set of steps to run as part of this test case.
#[serde(rename = "inputs")] #[serde(rename = "inputs")]
pub steps: Vec<Step>, pub steps: Vec<Step>,
/// An optional name of the group of tests that this test belongs to.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub group: Option<String>, pub group: Option<String>,
/// An optional set of expectations and assertions to make about the transaction after it ran.
///
/// If this is not specified then the only assertion that will be ran is that the transaction
/// was successful.
///
/// This expectation that's on the case itself will be attached to the final step of the case.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub expected: Option<Expected>, pub expected: Option<Expected>,
/// An optional boolean which defines if the case as a whole should be ignored. If null then the
/// case will not be ignored.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub ignore: Option<bool>, pub ignore: Option<bool>,
} }
+60 -15
View File
@@ -10,6 +10,7 @@ use alloy::{
use alloy_primitives::{FixedBytes, utils::parse_units}; use alloy_primitives::{FixedBytes, utils::parse_units};
use anyhow::Context as _; use anyhow::Context as _;
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream}; use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream};
use schemars::JsonSchema;
use semver::VersionReq; use semver::VersionReq;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -23,7 +24,7 @@ use crate::{metadata::ContractInstance, traits::ResolutionContext};
/// ///
/// A test step can be anything. It could be an invocation to a function, an assertion, or any other /// 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. /// action that needs to be run or executed on the nodes used in the tests.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum Step { pub enum Step {
/// A function call or an invocation to some function on some smart contract. /// A function call or an invocation to some function on some smart contract.
@@ -39,36 +40,51 @@ define_wrapper_type!(
pub struct StepIdx(usize) impl Display; pub struct StepIdx(usize) impl Display;
); );
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] /// This is an input step which is a transaction description that the framework translates into a
/// transaction and executes on the nodes.
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
pub struct Input { pub struct Input {
/// The address of the account performing the call and paying the fees for it.
#[serde(default = "Input::default_caller")] #[serde(default = "Input::default_caller")]
#[schemars(with = "String")]
pub caller: Address, pub caller: Address,
/// An optional comment on the step which has no impact on the execution in any way.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<String>, pub comment: Option<String>,
/// The contract instance that's being called in this transaction step.
#[serde(default = "Input::default_instance")] #[serde(default = "Input::default_instance")]
pub instance: ContractInstance, pub instance: ContractInstance,
/// The method that's being called in this step.
pub method: Method, pub method: Method,
/// The calldata that the function should be invoked with.
#[serde(default)] #[serde(default)]
pub calldata: Calldata, pub calldata: Calldata,
/// A set of assertions and expectations to have for the transaction.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub expected: Option<Expected>, pub expected: Option<Expected>,
/// An optional value to provide as part of the transaction.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<EtherValue>, pub value: Option<EtherValue>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[schemars(skip)]
pub storage: Option<HashMap<String, Calldata>>, pub storage: Option<HashMap<String, Calldata>>,
/// Variable assignment to perform in the framework allowing us to reference them again later on
/// during the execution.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub variable_assignments: Option<VariableAssignments>, pub variable_assignments: Option<VariableAssignments>,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] /// This represents a balance assertion step where the framework needs to query the balance of some
/// account or contract and assert that it's some amount.
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
pub struct BalanceAssertion { pub struct BalanceAssertion {
/// An optional comment on the balance assertion. /// An optional comment on the balance assertion.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@@ -82,11 +98,13 @@ pub struct BalanceAssertion {
/// followed in the calldata. /// followed in the calldata.
pub address: String, pub address: String,
/// The amount of balance to assert that the account or contract has. /// The amount of balance to assert that the account or contract has. This is a 256 bit string
/// that's serialized and deserialized into a decimal string.
#[schemars(with = "String")]
pub expected_balance: U256, pub expected_balance: U256,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
pub struct StorageEmptyAssertion { pub struct StorageEmptyAssertion {
/// An optional comment on the storage empty assertion. /// An optional comment on the storage empty assertion.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@@ -104,31 +122,52 @@ pub struct StorageEmptyAssertion {
pub is_storage_empty: bool, pub is_storage_empty: bool,
} }
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] /// A set of expectations and assertions to make about the transaction after it ran.
///
/// If this is not specified then the only assertion that will be ran is that the transaction
/// was successful.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[serde(untagged)] #[serde(untagged)]
pub enum Expected { pub enum Expected {
/// An assertion that the transaction succeeded and returned the provided set of data.
Calldata(Calldata), Calldata(Calldata),
/// A more complex assertion.
Expected(ExpectedOutput), Expected(ExpectedOutput),
/// A set of assertions.
ExpectedMany(Vec<ExpectedOutput>), ExpectedMany(Vec<ExpectedOutput>),
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] /// A set of assertions to run on the transaction.
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
pub struct ExpectedOutput { pub struct ExpectedOutput {
/// An optional compiler version that's required in order for this assertion to run.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[schemars(with = "Option<String>")]
pub compiler_version: Option<VersionReq>, pub compiler_version: Option<VersionReq>,
/// An optional field of the expected returns from the invocation.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub return_data: Option<Calldata>, pub return_data: Option<Calldata>,
/// An optional set of assertions to run on the emitted events from the transaction.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<Event>>, pub events: Option<Vec<Event>>,
/// A boolean which defines whether we expect the transaction to succeed or fail.
#[serde(default)] #[serde(default)]
pub exception: bool, pub exception: bool,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
pub struct Event { pub struct Event {
/// An optional field of the address of the emitter of the event.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub address: Option<String>, pub address: Option<String>,
/// The set of topics to expect the event to have.
pub topics: Vec<String>, pub topics: Vec<String>,
/// The set of values to expect the event to have.
pub values: Calldata, pub values: Calldata,
} }
@@ -183,16 +222,17 @@ pub struct Event {
/// [`Single`]: Calldata::Single /// [`Single`]: Calldata::Single
/// [`Compound`]: Calldata::Compound /// [`Compound`]: Calldata::Compound
/// [reverse polish notation]: https://en.wikipedia.org/wiki/Reverse_Polish_notation /// [reverse polish notation]: https://en.wikipedia.org/wiki/Reverse_Polish_notation
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[serde(untagged)] #[serde(untagged)]
pub enum Calldata { pub enum Calldata {
Single(Bytes), Single(#[schemars(with = "String")] Bytes),
Compound(Vec<CalldataItem>), Compound(Vec<CalldataItem>),
} }
define_wrapper_type! { define_wrapper_type! {
/// This represents an item in the [`Calldata::Compound`] variant. /// This represents an item in the [`Calldata::Compound`] variant. Each item will be resolved
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] /// according to the resolution rules of the tool.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)] #[serde(transparent)]
pub struct CalldataItem(String) impl Display; pub struct CalldataItem(String) impl Display;
} }
@@ -217,7 +257,7 @@ enum Operation {
} }
/// Specify how the contract is called. /// Specify how the contract is called.
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)] #[derive(Debug, Default, Serialize, Deserialize, JsonSchema, Clone, Eq, PartialEq)]
pub enum Method { pub enum Method {
/// Initiate a deploy transaction, calling contracts constructor. /// Initiate a deploy transaction, calling contracts constructor.
/// ///
@@ -238,11 +278,16 @@ pub enum Method {
} }
define_wrapper_type!( define_wrapper_type!(
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] /// Defines an Ether value.
///
/// This is an unsigned 256 bit integer that's followed by some denomination which can either be
/// eth, ether, gwei, or wei.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema)]
#[schemars(with = "String")]
pub struct EtherValue(U256) impl Display; pub struct EtherValue(U256) impl Display;
); );
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)] #[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
pub struct VariableAssignments { pub struct VariableAssignments {
/// A vector of the variable names to assign to the return data. /// A vector of the variable names to assign to the return data.
/// ///
+80 -13
View File
@@ -8,6 +8,7 @@ use std::{
str::FromStr, str::FromStr,
}; };
use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use revive_common::EVMVersion; use revive_common::EVMVersion;
@@ -56,30 +57,62 @@ impl Deref for MetadataFile {
} }
} }
#[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq)] /// A MatterLabs metadata file.
///
/// This defines the structure that the MatterLabs metadata files follow for defining the tests or
/// the workloads.
///
/// Each metadata file is composed of multiple test cases where each test case is isolated from the
/// others and runs in a completely different address space. Each test case is composed of a number
/// of steps and assertions that should be performed as part of the test case.
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema, Clone, Eq, PartialEq)]
pub struct Metadata { pub struct Metadata {
/// A comment on the test case that's added for human-readability. /// This is an optional comment on the metadata file which has no impact on the execution in any
/// way.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<String>, pub comment: Option<String>,
/// An optional boolean which defines if the metadata file as a whole should be ignored. If null
/// then the metadata file will not be ignored.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub ignore: Option<bool>, pub ignore: Option<bool>,
/// An optional vector of targets that this Metadata file's cases can be executed on. As an
/// example, if we wish for the metadata file's cases to only be run on PolkaVM then we'd
/// specify a target of "PolkaVM" in here.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub targets: Option<Vec<String>>, pub targets: Option<Vec<String>>,
/// A vector of the test cases and workloads contained within the metadata file. This is their
/// primary description.
pub cases: Vec<Case>, pub cases: Vec<Case>,
/// A map of all of the contracts that the test requires to run.
///
/// This is a map where the key is the name of the contract instance and the value is the
/// contract's path and ident in the file.
///
/// If any contract is to be used by the test then it must be included in here first so that the
/// framework is aware of its path, compiles it, and prepares it.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdent>>, pub contracts: Option<BTreeMap<ContractInstance, ContractPathAndIdent>>,
/// The set of libraries that this metadata file requires.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub libraries: Option<BTreeMap<PathBuf, BTreeMap<ContractIdent, ContractInstance>>>, pub libraries: Option<BTreeMap<PathBuf, BTreeMap<ContractIdent, ContractInstance>>>,
/// This represents a mode that has been parsed from test metadata.
///
/// Mode strings can take the following form (in pseudo-regex):
///
/// ```text
/// [YEILV][+-]? (M[0123sz])? <semver>?
/// ```
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub modes: Option<Vec<ParsedMode>>, pub modes: Option<Vec<ParsedMode>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[schemars(skip)]
pub file_path: Option<PathBuf>, pub file_path: Option<PathBuf>,
/// This field specifies an EVM version requirement that the test case has where the test might /// This field specifies an EVM version requirement that the test case has where the test might
@@ -87,9 +120,9 @@ pub struct Metadata {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub required_evm_version: Option<EvmVersionRequirement>, pub required_evm_version: Option<EvmVersionRequirement>,
/// A set of compilation directives that will be passed to the compiler whenever the contracts for /// A set of compilation directives that will be passed to the compiler whenever the contracts
/// the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is /// for the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`]
/// just a filter for when a test can run whereas this is an instruction to the compiler. /// is just a filter for when a test can run whereas this is an instruction to the compiler.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub compiler_directives: Option<CompilationDirectives>, pub compiler_directives: Option<CompilationDirectives>,
} }
@@ -262,7 +295,7 @@ define_wrapper_type!(
/// ///
/// Typically, this is used as the key to the "contracts" field of metadata files. /// Typically, this is used as the key to the "contracts" field of metadata files.
#[derive( #[derive(
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema
)] )]
#[serde(transparent)] #[serde(transparent)]
pub struct ContractInstance(String) impl Display; pub struct ContractInstance(String) impl Display;
@@ -273,7 +306,7 @@ define_wrapper_type!(
/// ///
/// A contract identifier is the name of the contract in the source code. /// A contract identifier is the name of the contract in the source code.
#[derive( #[derive(
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema
)] )]
#[serde(transparent)] #[serde(transparent)]
pub struct ContractIdent(String) impl Display; pub struct ContractIdent(String) impl Display;
@@ -286,7 +319,9 @@ define_wrapper_type!(
/// ```text /// ```text
/// ${path}:${contract_ident} /// ${path}:${contract_ident}
/// ``` /// ```
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[derive(
Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(try_from = "String", into = "String")] #[serde(try_from = "String", into = "String")]
pub struct ContractPathAndIdent { pub struct ContractPathAndIdent {
/// The path of the contract source code relative to the directory containing the metadata file. /// The path of the contract source code relative to the directory containing the metadata file.
@@ -363,9 +398,15 @@ impl From<ContractPathAndIdent> for String {
} }
} }
/// An EVM version requirement that the test case has. This gets serialized and /// An EVM version requirement that the test case has. This gets serialized and deserialized from
/// deserialized from and into [`String`]. /// and into [`String`]. This follows a simple format of (>=|<=|=|>|<) followed by a string of the
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] /// EVM version.
///
/// When specified, the framework will only run the test if the node's EVM version matches that
/// required by the metadata file.
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[serde(try_from = "String", into = "String")] #[serde(try_from = "String", into = "String")]
pub struct EvmVersionRequirement { pub struct EvmVersionRequirement {
ordering: Ordering, ordering: Ordering,
@@ -493,7 +534,18 @@ impl From<EvmVersionRequirement> for String {
/// just a filter for when a test can run whereas this is an instruction to the compiler. /// just a filter for when a test can run whereas this is an instruction to the compiler.
/// Defines how the compiler should handle revert strings. /// Defines how the compiler should handle revert strings.
#[derive( #[derive(
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, Clone,
Debug,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Default,
Serialize,
Deserialize,
JsonSchema,
)] )]
pub struct CompilationDirectives { pub struct CompilationDirectives {
/// Defines how the revert strings should be handled. /// Defines how the revert strings should be handled.
@@ -502,14 +554,29 @@ pub struct CompilationDirectives {
/// Defines how the compiler should handle revert strings. /// Defines how the compiler should handle revert strings.
#[derive( #[derive(
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, Clone,
Debug,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Default,
Serialize,
Deserialize,
JsonSchema,
)] )]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum RevertString { pub enum RevertString {
/// The default handling of the revert strings.
#[default] #[default]
Default, Default,
/// The debug handling of the revert strings.
Debug, Debug,
/// Strip the revert strings.
Strip, Strip,
/// Provide verbose debug strings for the revert string.
VerboseDebug, VerboseDebug,
} }
+2 -1
View File
@@ -2,6 +2,7 @@ use anyhow::Context as _;
use regex::Regex; use regex::Regex;
use revive_dt_common::iterators::EitherIter; use revive_dt_common::iterators::EitherIter;
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline}; use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Display; use std::fmt::Display;
@@ -17,7 +18,7 @@ use std::sync::LazyLock;
/// ``` /// ```
/// ///
/// We can parse valid mode strings into [`ParsedMode`] using [`ParsedMode::from_str`]. /// We can parse valid mode strings into [`ParsedMode`] using [`ParsedMode::from_str`].
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema)]
#[serde(try_from = "String", into = "String")] #[serde(try_from = "String", into = "String")]
pub struct ParsedMode { pub struct ParsedMode {
pub pipeline: Option<ModePipeline>, pub pipeline: Option<ModePipeline>,
+497
View File
@@ -0,0 +1,497 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Metadata",
"description": "A MatterLabs metadata file.\n\nThis defines the structure that the MatterLabs metadata files follow for defining the tests or\nthe workloads.\n\nEach metadata file is composed of multiple test cases where each test case is isolated from the\nothers and runs in a completely different address space. Each test case is composed of a number\nof steps and assertions that should be performed as part of the test case.",
"type": "object",
"properties": {
"comment": {
"description": "This is an optional comment on the metadata file which has no impact on the execution in any\nway.",
"type": [
"string",
"null"
]
},
"ignore": {
"description": "An optional boolean which defines if the metadata file as a whole should be ignored. If null\nthen the metadata file will not be ignored.",
"type": [
"boolean",
"null"
]
},
"targets": {
"description": "An optional vector of targets that this Metadata file's cases can be executed on. As an\nexample, if we wish for the metadata file's cases to only be run on PolkaVM then we'd\nspecify a target of \"PolkaVM\" in here.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"cases": {
"description": "A vector of the test cases and workloads contained within the metadata file. This is their\nprimary description.",
"type": "array",
"items": {
"$ref": "#/$defs/Case"
}
},
"contracts": {
"description": "A map of all of the contracts that the test requires to run.\n\nThis is a map where the key is the name of the contract instance and the value is the\ncontract's path and ident in the file.\n\nIf any contract is to be used by the test then it must be included in here first so that the\nframework is aware of its path, compiles it, and prepares it.",
"type": [
"object",
"null"
],
"additionalProperties": {
"$ref": "#/$defs/ContractPathAndIdent"
}
},
"libraries": {
"description": "The set of libraries that this metadata file requires.",
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/ContractInstance"
}
}
},
"modes": {
"description": "This represents a mode that has been parsed from test metadata.\n\nMode strings can take the following form (in pseudo-regex):\n\n```text\n[YEILV][+-]? (M[0123sz])? <semver>?\n```",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/ParsedMode"
}
},
"required_evm_version": {
"description": "This field specifies an EVM version requirement that the test case has where the test might\nbe run of the evm version of the nodes match the evm version specified here.",
"anyOf": [
{
"$ref": "#/$defs/EvmVersionRequirement"
},
{
"type": "null"
}
]
},
"compiler_directives": {
"description": "A set of compilation directives that will be passed to the compiler whenever the contracts\nfor the test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`]\nis just a filter for when a test can run whereas this is an instruction to the compiler.",
"anyOf": [
{
"$ref": "#/$defs/CompilationDirectives"
},
{
"type": "null"
}
]
}
},
"required": [
"cases"
],
"$defs": {
"Case": {
"type": "object",
"properties": {
"name": {
"description": "An optional name of the test case.",
"type": [
"string",
"null"
]
},
"comment": {
"description": "An optional comment on the case which has no impact on the execution in any way.",
"type": [
"string",
"null"
]
},
"modes": {
"description": "This represents a mode that has been parsed from test metadata.\n\nMode strings can take the following form (in pseudo-regex):\n\n```text\n[YEILV][+-]? (M[0123sz])? <semver>?\n```\n\nIf this is provided then it takes higher priority than the modes specified in the metadata\nfile.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/ParsedMode"
}
},
"inputs": {
"description": "The set of steps to run as part of this test case.",
"type": "array",
"items": {
"$ref": "#/$defs/Step"
}
},
"group": {
"description": "An optional name of the group of tests that this test belongs to.",
"type": [
"string",
"null"
]
},
"expected": {
"description": "An optional set of expectations and assertions to make about the transaction after it ran.\n\nIf this is not specified then the only assertion that will be ran is that the transaction\nwas successful.\n\nThis expectation that's on the case itself will be attached to the final step of the case.",
"anyOf": [
{
"$ref": "#/$defs/Expected"
},
{
"type": "null"
}
]
},
"ignore": {
"description": "An optional boolean which defines if the case as a whole should be ignored. If null then the\ncase will not be ignored.",
"type": [
"boolean",
"null"
]
}
},
"required": [
"inputs"
]
},
"ParsedMode": {
"description": "This represents a mode that has been parsed from test metadata.\n\nMode strings can take the following form (in pseudo-regex):\n\n```text\n[YEILV][+-]? (M[0123sz])? <semver>?\n```\n\nWe can parse valid mode strings into [`ParsedMode`] using [`ParsedMode::from_str`].",
"type": "string"
},
"Step": {
"description": "A test step.\n\nA test step can be anything. It could be an invocation to a function, an assertion, or any other\naction that needs to be run or executed on the nodes used in the tests.",
"anyOf": [
{
"description": "A function call or an invocation to some function on some smart contract.",
"$ref": "#/$defs/Input"
},
{
"description": "A step for performing a balance assertion on some account or contract.",
"$ref": "#/$defs/BalanceAssertion"
},
{
"description": "A step for asserting that the storage of some contract or account is empty.",
"$ref": "#/$defs/StorageEmptyAssertion"
}
]
},
"Input": {
"description": "This is an input step which is a transaction description that the framework translates into a\ntransaction and executes on the nodes.",
"type": "object",
"properties": {
"caller": {
"description": "The address of the account performing the call and paying the fees for it.",
"type": "string",
"default": "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1"
},
"comment": {
"description": "An optional comment on the step which has no impact on the execution in any way.",
"type": [
"string",
"null"
]
},
"instance": {
"description": "The contract instance that's being called in this transaction step.",
"$ref": "#/$defs/ContractInstance",
"default": "Test"
},
"method": {
"description": "The method that's being called in this step.",
"$ref": "#/$defs/Method"
},
"calldata": {
"description": "The calldata that the function should be invoked with.",
"$ref": "#/$defs/Calldata",
"default": []
},
"expected": {
"description": "A set of assertions and expectations to have for the transaction.",
"anyOf": [
{
"$ref": "#/$defs/Expected"
},
{
"type": "null"
}
]
},
"value": {
"description": "An optional value to provide as part of the transaction.",
"anyOf": [
{
"$ref": "#/$defs/EtherValue"
},
{
"type": "null"
}
]
},
"variable_assignments": {
"description": "Variable assignment to perform in the framework allowing us to reference them again later on\nduring the execution.",
"anyOf": [
{
"$ref": "#/$defs/VariableAssignments"
},
{
"type": "null"
}
]
}
},
"required": [
"method"
]
},
"ContractInstance": {
"description": "Represents a contract instance found a metadata file.\n\nTypically, this is used as the key to the \"contracts\" field of metadata files.",
"type": "string"
},
"Method": {
"description": "Specify how the contract is called.",
"anyOf": [
{
"description": "Initiate a deploy transaction, calling contracts constructor.\n\nIndicated by `#deployer`.",
"type": "string",
"const": "#deployer"
},
{
"description": "Does not calculate and insert a function selector.\n\nIndicated by `#fallback`.",
"type": "string",
"const": "#fallback"
},
{
"description": "Call the public function with the given name.",
"type": "string"
}
]
},
"Calldata": {
"description": "A type definition for the calldata supported by the testing framework.\n\nWe choose to document all of the types used in [`Calldata`] in this one doc comment to elaborate\non why they exist and consolidate all of the documentation for calldata in a single place where\nit can be viewed and understood.\n\nThe [`Single`] variant of this enum is quite simple and straightforward: it's a hex-encoded byte\narray of the calldata.\n\nThe [`Compound`] type is more intricate and allows for capabilities such as resolution and some\nsimple arithmetic operations. It houses a vector of [`CalldataItem`]s which is just a wrapper\naround an owned string.\n\nA [`CalldataItem`] could be a simple hex string of a single calldata argument, but it could also\nbe something that requires resolution such as `MyContract.address` which is a variable that is\nunderstood by the resolution logic to mean \"Lookup the address of this particular contract\ninstance\".\n\nIn addition to the above, the format supports some simple arithmetic operations like add, sub,\ndivide, multiply, bitwise AND, bitwise OR, and bitwise XOR. Our parser understands the [reverse\npolish notation] simply because it's easy to write a calculator for that notation and since we\ndo not have plans to use arithmetic too often in tests. In reverse polish notation a typical\n`2 + 4` would be written as `2 4 +` which makes this notation very simple to implement through\na stack.\n\nCombining the above, a single [`CalldataItem`] could employ both resolution and arithmetic at\nthe same time. For example, a [`CalldataItem`] of `$BLOCK_NUMBER $BLOCK_NUMBER +` means that\nthe block number should be retrieved and then it should be added to itself.\n\nInternally, we split the [`CalldataItem`] by spaces. Therefore, `$BLOCK_NUMBER $BLOCK_NUMBER+`\nis invalid but `$BLOCK_NUMBER $BLOCK_NUMBER +` is valid and can be understood by the parser and\ncalculator. After the split is done, each token is parsed into a [`CalldataToken<&str>`] forming\nan [`Iterator`] over [`CalldataToken<&str>`]. A [`CalldataToken<&str>`] can then be resolved\ninto a [`CalldataToken<U256>`] through the resolution logic. Finally, after resolution is done,\nthis iterator of [`CalldataToken<U256>`] is collapsed into the final result by applying the\narithmetic operations requested.\n\nFor example, supplying a [`Compound`] calldata of `0xdeadbeef` produces an iterator of a single\n[`CalldataToken<&str>`] items of the value [`CalldataToken::Item`] of the string value 12 which\nwe can then resolve into the appropriate [`U256`] value and convert into calldata.\n\nIn summary, the various types used in [`Calldata`] represent the following:\n- [`CalldataItem`]: A calldata string from the metadata files.\n- [`CalldataToken<&str>`]: Typically used in an iterator of items from the space splitted\n [`CalldataItem`] and represents a token that has not yet been resolved into its value.\n- [`CalldataToken<U256>`]: Represents a token that's been resolved from being a string and into\n the word-size calldata argument on which we can perform arithmetic.\n\n[`Single`]: Calldata::Single\n[`Compound`]: Calldata::Compound\n[reverse polish notation]: https://en.wikipedia.org/wiki/Reverse_Polish_notation",
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/CalldataItem"
}
}
]
},
"CalldataItem": {
"description": "This represents an item in the [`Calldata::Compound`] variant. Each item will be resolved\naccording to the resolution rules of the tool.",
"type": "string"
},
"Expected": {
"description": "A set of expectations and assertions to make about the transaction after it ran.\n\nIf this is not specified then the only assertion that will be ran is that the transaction\nwas successful.",
"anyOf": [
{
"description": "An assertion that the transaction succeeded and returned the provided set of data.",
"$ref": "#/$defs/Calldata"
},
{
"description": "A more complex assertion.",
"$ref": "#/$defs/ExpectedOutput"
},
{
"description": "A set of assertions.",
"type": "array",
"items": {
"$ref": "#/$defs/ExpectedOutput"
}
}
]
},
"ExpectedOutput": {
"description": "A set of assertions to run on the transaction.",
"type": "object",
"properties": {
"compiler_version": {
"description": "An optional compiler version that's required in order for this assertion to run.",
"type": [
"string",
"null"
]
},
"return_data": {
"description": "An optional field of the expected returns from the invocation.",
"anyOf": [
{
"$ref": "#/$defs/Calldata"
},
{
"type": "null"
}
]
},
"events": {
"description": "An optional set of assertions to run on the emitted events from the transaction.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/$defs/Event"
}
},
"exception": {
"description": "A boolean which defines whether we expect the transaction to succeed or fail.",
"type": "boolean",
"default": false
}
}
},
"Event": {
"type": "object",
"properties": {
"address": {
"description": "An optional field of the address of the emitter of the event.",
"type": [
"string",
"null"
]
},
"topics": {
"description": "The set of topics to expect the event to have.",
"type": "array",
"items": {
"type": "string"
}
},
"values": {
"description": "The set of values to expect the event to have.",
"$ref": "#/$defs/Calldata"
}
},
"required": [
"topics",
"values"
]
},
"EtherValue": {
"description": "Defines an Ether value.\n\nThis is an unsigned 256 bit integer that's followed by some denomination which can either be\neth, ether, gwei, or wei.",
"type": "string"
},
"VariableAssignments": {
"type": "object",
"properties": {
"return_data": {
"description": "A vector of the variable names to assign to the return data.\n\nExample: `UniswapV3PoolAddress`",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"return_data"
]
},
"BalanceAssertion": {
"description": "This represents a balance assertion step where the framework needs to query the balance of some\naccount or contract and assert that it's some amount.",
"type": "object",
"properties": {
"comment": {
"description": "An optional comment on the balance assertion.",
"type": [
"string",
"null"
]
},
"address": {
"description": "The address that the balance assertion should be done on.\n\nThis is a string which will be resolved into an address when being processed. Therefore,\nthis could be a normal hex address, a variable such as `Test.address`, or perhaps even a\nfull on variable like `$VARIABLE:Uniswap`. It follows the same resolution rules that are\nfollowed in the calldata.",
"type": "string"
},
"expected_balance": {
"description": "The amount of balance to assert that the account or contract has. This is a 256 bit string\nthat's serialized and deserialized into a decimal string.",
"type": "string"
}
},
"required": [
"address",
"expected_balance"
]
},
"StorageEmptyAssertion": {
"type": "object",
"properties": {
"comment": {
"description": "An optional comment on the storage empty assertion.",
"type": [
"string",
"null"
]
},
"address": {
"description": "The address that the balance assertion should be done on.\n\nThis is a string which will be resolved into an address when being processed. Therefore,\nthis could be a normal hex address, a variable such as `Test.address`, or perhaps even a\nfull on variable like `$VARIABLE:Uniswap`. It follows the same resolution rules that are\nfollowed in the calldata.",
"type": "string"
},
"is_storage_empty": {
"description": "A boolean of whether the storage of the address is empty or not.",
"type": "boolean"
}
},
"required": [
"address",
"is_storage_empty"
]
},
"ContractPathAndIdent": {
"description": "Represents an identifier used for contracts.\n\nThe type supports serialization from and into the following string format:\n\n```text\n${path}:${contract_ident}\n```",
"type": "string"
},
"EvmVersionRequirement": {
"description": "An EVM version requirement that the test case has. This gets serialized and deserialized from\nand into [`String`]. This follows a simple format of (>=|<=|=|>|<) followed by a string of the\nEVM version.\n\nWhen specified, the framework will only run the test if the node's EVM version matches that\nrequired by the metadata file.",
"type": "string"
},
"CompilationDirectives": {
"description": "A set of compilation directives that will be passed to the compiler whenever the contracts for\nthe test are being compiled. Note that this differs from the [`Mode`]s in that a [`Mode`] is\njust a filter for when a test can run whereas this is an instruction to the compiler.\nDefines how the compiler should handle revert strings.",
"type": "object",
"properties": {
"revert_string_handling": {
"description": "Defines how the revert strings should be handled.",
"anyOf": [
{
"$ref": "#/$defs/RevertString"
},
{
"type": "null"
}
]
}
}
},
"RevertString": {
"description": "Defines how the compiler should handle revert strings.",
"oneOf": [
{
"description": "The default handling of the revert strings.",
"type": "string",
"const": "default"
},
{
"description": "The debug handling of the revert strings.",
"type": "string",
"const": "debug"
},
{
"description": "Strip the revert strings.",
"type": "string",
"const": "strip"
},
{
"description": "Provide verbose debug strings for the revert string.",
"type": "string",
"const": "verboseDebug"
}
]
}
}
}