diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53344cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +.vscode/ +.DS_Store +node_modules diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6b2b812 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,118 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "revive-differential-testing-format" +version = "0.1.0" +dependencies = [ + "anyhow", + "semver", + "serde", + "serde_json", +] + +[[package]] +name = "revive-differential-testing-retester" +version = "0.1.0" +dependencies = [ + "revive-differential-testing-format", + "serde_json", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..74827e4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,35 @@ +[workspace] +resolver = "2" +members = ["crates/*"] + +[workspace.package] +version = "0.1.0" +authors = [ + "Parity Technologies ", +] +license = "MIT/Apache-2.0" +edition = "2024" +repository = "https://github.com/paritytech/revive-differential-testing.git" +rust-version = "1.85.0" + +[workspace.dependencies] +revive-differential-testing-format = { version = "0.1.0", path = "crates/format" } + +anyhow = "1.0" +semver = "1.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = { version = "1.0", features = ["arbitrary_precision"] } + +# revive compiler +revive-llvm-context = { git = "https://github.com/paritytech/revive", rev = "2bbc5d713d1bf8b38c43f6ce9382812561ca3ce1" } + + +# polkadot-sdk and friends +codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" } +scale-info = { version = "2.11.6", default-features = false } +polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c29e72a8628835e34deb6aa7db9a78a2e4eabcee" } + +[profile.bench] +inherits = "release" +lto = true +codegen-units = 1 diff --git a/crates/format/Cargo.toml b/crates/format/Cargo.toml new file mode 100644 index 0000000..4f61f2c --- /dev/null +++ b/crates/format/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "revive-differential-testing-format" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +repository.workspace = true +rust-version.workspace = true + +[dependencies] +anyhow = { workspace = true } +semver = { workspace = true } +serde = { workspace = true, features = [ "derive" ] } +serde_json = { workspace = true } \ No newline at end of file diff --git a/crates/format/src/case.rs b/crates/format/src/case.rs new file mode 100644 index 0000000..3d62704 --- /dev/null +++ b/crates/format/src/case.rs @@ -0,0 +1,9 @@ +use serde::Deserialize; + +use crate::modes::Mode; + +#[derive(Debug, Deserialize)] +pub struct Case { + #[serde(rename(deserialize = "modes"))] + pub modes: Vec, +} diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs new file mode 100644 index 0000000..8161da7 --- /dev/null +++ b/crates/format/src/lib.rs @@ -0,0 +1,4 @@ +//! The revive differential tests case format. + +pub mod case; +pub mod modes; diff --git a/crates/format/src/modes.rs b/crates/format/src/modes.rs new file mode 100644 index 0000000..27616a7 --- /dev/null +++ b/crates/format/src/modes.rs @@ -0,0 +1,70 @@ +use serde::Deserialize; +use serde::de::Deserializer; + +/// Specifies the compilation mode of the test artifact. +#[derive(Debug, Clone, Eq, PartialEq)] +pub enum Mode { + Solidity(SolcMode), + Unknown(String), +} + +/// Specify Solidity specific compiler options. +#[derive(Debug, Default, Clone, Eq, PartialEq)] +pub struct SolcMode { + pub solc_version: Option, + pub solc_optimize: Option, + pub llvm_optimizer_settings: Vec, +} + +impl SolcMode { + /// Try to parse a mode string into a solc mode. + /// Returns `None` if the string wasn't a solc YUL mode string. + /// + /// The mode string is expected to start with the `Y` ID (YUL ID), + /// optionally followed by `+` or `-` for the solc optimizer settings. + /// + /// Options can be separated by a whitespace contain the following + /// - A solc `SemVer version requirement` string + /// - One or more `-OX` where X is a supposed to be an LLVM opt mode + pub fn parse_from_mode_string(mode_string: &str) -> Option { + let mut result = Self::default(); + + let mut parts = mode_string.trim().split(" "); + + match parts.next()? { + "Y" => {} + "Y+" => result.solc_optimize = Some(true), + "Y-" => result.solc_optimize = Some(false), + _ => return None, + } + + while let Some(part) = parts.next() { + if let Ok(solc_version) = semver::VersionReq::parse(part) { + result.solc_version = Some(solc_version); + continue; + } + if part.starts_with("-O") { + result.llvm_optimizer_settings.push(part[2..].to_string()); + continue; + } + panic!("the YUL mode string {mode_string} failed to parse, invalid part: {part}") + } + + Some(result) + } +} + +impl<'de> Deserialize<'de> for Mode { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let mode_string = String::deserialize(deserializer)?; + + if let Some(solc_mode) = SolcMode::parse_from_mode_string(&mode_string) { + return Ok(Self::Solidity(solc_mode)); + } + + Ok(Self::Unknown(mode_string)) + } +} diff --git a/crates/retester/Cargo.toml b/crates/retester/Cargo.toml new file mode 100644 index 0000000..1b41551 --- /dev/null +++ b/crates/retester/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "revive-differential-testing-retester" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +repository.workspace = true +rust-version.workspace = true + +[[bin]] +name = "retester" +path = "src/main.rs" + +[dependencies] +revive-differential-testing-format = { workspace = true } +serde_json = { workspace = true } diff --git a/crates/retester/src/main.rs b/crates/retester/src/main.rs new file mode 100644 index 0000000..ae3eb69 --- /dev/null +++ b/crates/retester/src/main.rs @@ -0,0 +1,9 @@ +use revive_differential_testing_format::case::Case; + +fn main() { + let example_def = include_str!("../../../test.json"); + + let case: Case = serde_json::from_str(example_def).unwrap(); + + println!("{case:?}"); +}