mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-22 20:47:58 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6e0701ec9 | |||
| f99b3dbc3c | |||
| 0e79594bb2 | |||
| 5c75228496 | |||
| 8229675ba8 | |||
| dd94b12b34 | |||
| 4af9f6695d | |||
| 8b1afc36a3 | |||
| 4d8adb553c | |||
| 60328cd493 | |||
| eb264fcc7b | |||
| 84b139d3b4 | |||
| d93824d973 | |||
| bdd2eab194 | |||
| eb754bc9e8 | |||
| 0e5e57e703 | |||
| 491a9a32b2 | |||
| bec5a7e390 | |||
| 85033cfead | |||
| 76d6a154c1 |
@@ -7,3 +7,7 @@ node_modules
|
|||||||
# We do not want to commit any log files that we produce from running the code locally so this is
|
# We do not want to commit any log files that we produce from running the code locally so this is
|
||||||
# added to the .gitignore file.
|
# added to the .gitignore file.
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
profile.json.gz
|
||||||
|
resolc-compiler-tests
|
||||||
|
workdir
|
||||||
Generated
+53
-13
@@ -4482,6 +4482,7 @@ dependencies = [
|
|||||||
"alloy",
|
"alloy",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"dashmap",
|
||||||
"foundry-compilers-artifacts",
|
"foundry-compilers-artifacts",
|
||||||
"revive-common",
|
"revive-common",
|
||||||
"revive-dt-common",
|
"revive-dt-common",
|
||||||
@@ -4491,6 +4492,7 @@ dependencies = [
|
|||||||
"semver 1.0.26",
|
"semver 1.0.26",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
@@ -4503,7 +4505,7 @@ dependencies = [
|
|||||||
"clap",
|
"clap",
|
||||||
"semver 1.0.26",
|
"semver 1.0.26",
|
||||||
"serde",
|
"serde",
|
||||||
"temp-dir",
|
"tempfile",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4528,10 +4530,10 @@ dependencies = [
|
|||||||
"semver 1.0.26",
|
"semver 1.0.26",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"temp-dir",
|
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-appender",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4543,6 +4545,7 @@ dependencies = [
|
|||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-sol-types",
|
"alloy-sol-types",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"futures",
|
||||||
"regex",
|
"regex",
|
||||||
"revive-common",
|
"revive-common",
|
||||||
"revive-dt-common",
|
"revive-dt-common",
|
||||||
@@ -4568,7 +4571,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-runtime",
|
"sp-runtime",
|
||||||
"temp-dir",
|
"tempfile",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
@@ -4585,13 +4588,18 @@ dependencies = [
|
|||||||
name = "revive-dt-report"
|
name = "revive-dt-report"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"alloy-primitives",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"indexmap 2.10.0",
|
||||||
|
"paste",
|
||||||
"revive-dt-common",
|
"revive-dt-common",
|
||||||
"revive-dt-compiler",
|
"revive-dt-compiler",
|
||||||
"revive-dt-config",
|
"revive-dt-config",
|
||||||
"revive-dt-format",
|
"revive-dt-format",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_with",
|
||||||
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4843,6 +4851,30 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schemars"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f"
|
||||||
|
dependencies = [
|
||||||
|
"dyn-clone",
|
||||||
|
"ref-cast",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schemars"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0"
|
||||||
|
dependencies = [
|
||||||
|
"dyn-clone",
|
||||||
|
"ref-cast",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schnellru"
|
name = "schnellru"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
@@ -5073,15 +5105,17 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with"
|
name = "serde_with"
|
||||||
version = "3.12.0"
|
version = "3.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa"
|
checksum = "f2c45cd61fefa9db6f254525d46e392b852e0e61d9a1fd36e5bd183450a556d5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
"indexmap 1.9.3",
|
"indexmap 1.9.3",
|
||||||
"indexmap 2.10.0",
|
"indexmap 2.10.0",
|
||||||
|
"schemars 0.9.0",
|
||||||
|
"schemars 1.0.4",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -5091,9 +5125,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with_macros"
|
name = "serde_with_macros"
|
||||||
version = "3.12.0"
|
version = "3.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e"
|
checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -5783,12 +5817,6 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "temp-dir"
|
|
||||||
version = "0.1.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "83176759e9416cf81ee66cb6508dbfe9c96f20b8b56265a39917551c23c70964"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.20.0"
|
version = "3.20.0"
|
||||||
@@ -6108,6 +6136,18 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-appender"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-channel",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
"time",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-attributes"
|
name = "tracing-attributes"
|
||||||
version = "0.1.28"
|
version = "0.1.28"
|
||||||
|
|||||||
+7
-2
@@ -28,11 +28,13 @@ anyhow = "1.0"
|
|||||||
bson = { version = "2.15.0" }
|
bson = { version = "2.15.0" }
|
||||||
cacache = { version = "13.1.0" }
|
cacache = { version = "13.1.0" }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
dashmap = { version = "6.1.0" }
|
||||||
foundry-compilers-artifacts = { version = "0.18.0" }
|
foundry-compilers-artifacts = { version = "0.18.0" }
|
||||||
futures = { version = "0.3.31" }
|
futures = { version = "0.3.31" }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
moka = "0.12.10"
|
moka = "0.12.10"
|
||||||
|
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"
|
||||||
semver = { version = "1.0", features = ["serde"] }
|
semver = { version = "1.0", features = ["serde"] }
|
||||||
@@ -42,10 +44,10 @@ serde_json = { version = "1.0", default-features = false, features = [
|
|||||||
"std",
|
"std",
|
||||||
"unbounded_depth",
|
"unbounded_depth",
|
||||||
] }
|
] }
|
||||||
|
serde_with = { version = "3.14.0" }
|
||||||
sha2 = { version = "0.10.9" }
|
sha2 = { version = "0.10.9" }
|
||||||
sp-core = "36.1.0"
|
sp-core = "36.1.0"
|
||||||
sp-runtime = "41.1.0"
|
sp-runtime = "41.1.0"
|
||||||
temp-dir = { version = "0.1.16" }
|
|
||||||
tempfile = "3.3"
|
tempfile = "3.3"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
tokio = { version = "1.47.0", default-features = false, features = [
|
tokio = { version = "1.47.0", default-features = false, features = [
|
||||||
@@ -54,7 +56,8 @@ tokio = { version = "1.47.0", default-features = false, features = [
|
|||||||
"rt",
|
"rt",
|
||||||
] }
|
] }
|
||||||
uuid = { version = "1.8", features = ["v4"] }
|
uuid = { version = "1.8", features = ["v4"] }
|
||||||
tracing = "0.1.41"
|
tracing = { version = "0.1.41" }
|
||||||
|
tracing-appender = { version = "0.2.3" }
|
||||||
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
|
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
|
||||||
"fmt",
|
"fmt",
|
||||||
"json",
|
"json",
|
||||||
@@ -89,3 +92,5 @@ features = [
|
|||||||
inherits = "release"
|
inherits = "release"
|
||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
||||||
|
[workspace.lints.clippy]
|
||||||
|
|||||||
@@ -1,34 +1,210 @@
|
|||||||
# revive-differential-tests
|
<div align="center">
|
||||||
|
<h1><code>Revive Differential Tests</code></h1>
|
||||||
|
|
||||||
The revive differential testing framework allows to define smart contract tests in a declarative manner in order to compile and execute them against different Ethereum-compatible blockchain implmentations. This is useful to:
|
<p>
|
||||||
- Analyze observable differences in contract compilation and execution across different blockchain implementations, including contract storage, account balances, transaction output and emitted events on a per-transaction base.
|
<strong>Differential testing for Ethereum-compatible smart contract stacks</strong>
|
||||||
- Collect and compare benchmark metrics such as code size, gas usage or transaction throughput per seconds (TPS) of different blockchain implementations.
|
</p>
|
||||||
- Ensure reproducible contract builds across multiple compiler implementations or multiple host platforms.
|
</div>
|
||||||
- Implement end-to-end regression tests for Ethereum-compatible smart contract stacks.
|
|
||||||
|
|
||||||
# Declarative test format
|
This project compiles and executes declarative smart-contract tests against multiple platforms, then compares behavior (status, return data, events, and state diffs). Today it supports:
|
||||||
|
|
||||||
For now, the format used to write tests is the [matter-labs era compiler format](https://github.com/matter-labs/era-compiler-tests?tab=readme-ov-file#matter-labs-simplecomplex-format). This allows us to re-use many tests from their corpora.
|
- Geth (EVM reference implementation)
|
||||||
|
- Revive Kitchensink (Substrate-based PolkaVM + `eth-rpc` proxy)
|
||||||
|
|
||||||
# The `retester` utility
|
Use it to:
|
||||||
|
|
||||||
The `retester` helper utilty is used to run the tests. To get an idea of what `retester` can do, please consults its command line help:
|
- Detect observable differences between platforms (execution success, logs, state changes)
|
||||||
|
- Ensure reproducible builds across compilers/hosts
|
||||||
|
- Run end-to-end regression suites
|
||||||
|
|
||||||
```
|
This framework uses the [MatterLabs tests format](https://github.com/matter-labs/era-compiler-tests/tree/main/solidity) for declarative tests which is composed of the following:
|
||||||
cargo run -p revive-dt-core -- --help
|
|
||||||
|
- Metadata files, this is akin to a module of tests in Rust.
|
||||||
|
- Each metadata file contains multiple cases, a case is akin to a Rust test where a module can contain multiple tests.
|
||||||
|
- Each case contains multiple steps and assertions, this is akin to any Rust test that contains multiple statements.
|
||||||
|
|
||||||
|
Metadata files are JSON files, but Solidity files can also be metadata files if they include inline metadata provided as a comment at the top of the contract.
|
||||||
|
|
||||||
|
All of the steps contained within each test case are either:
|
||||||
|
|
||||||
|
- Transactions that need to be submitted and assertions to run on the submitted transactions.
|
||||||
|
- Assertions on the state of the chain (e.g., account balances, storage, etc...)
|
||||||
|
|
||||||
|
All of the transactions submitted by the this tool to the test nodes follow a similar logic to what wallets do. We first use alloy to estimate the transaction fees, then we attach that to the transaction and submit it to the node and then await the transaction receipt.
|
||||||
|
|
||||||
|
This repository contains none of the tests and only contains the testing framework or the test runner. The tests can be found in the [`resolc-compiler-tests`](https://github.com/paritytech/resolc-compiler-tests) repository which is a clone of [MatterLab's test suite](https://github.com/matter-labs/era-compiler-tests) with some modifications and adjustments made to suit our use case.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
This section describes the required dependencies that this framework requires to run. Compiling this framework is pretty straightforward and no additional dependencies beyond what's specified in the `Cargo.toml` file should be required.
|
||||||
|
|
||||||
|
- Stable Rust
|
||||||
|
- Geth - When doing differential testing against the PVM we submit transactions to a Geth node and to Kitchensink to compare them.
|
||||||
|
- Kitchensink - When doing differential testing against the PVM we submit transactions to a Geth node and to Kitchensink to compare them.
|
||||||
|
- ETH-RPC - All communication with Kitchensink is done through the ETH RPC.
|
||||||
|
- Solc - This is actually a transitive dependency, while this tool doesn't require solc as it downloads the versions that it requires, resolc requires that Solc is installed and available in the path.
|
||||||
|
- Resolc - This is required to compile the contracts to PolkaVM bytecode.
|
||||||
|
|
||||||
|
All of the above need to be installed and available in the path in order for the tool to work.
|
||||||
|
|
||||||
|
## Running The Tool
|
||||||
|
|
||||||
|
This tool is being updated quite frequently. Therefore, it's recommended that you don't install the tool and then run it, but rather that you run it from the root of the directory using `cargo run --release`. The help command of the tool gives you all of the information you need to know about each of the options and flags that the tool offers.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo run --release -- --help
|
||||||
|
Usage: retester [OPTIONS]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-s, --solc <SOLC>
|
||||||
|
The `solc` version to use if the test didn't specify it explicitly
|
||||||
|
|
||||||
|
[default: 0.8.29]
|
||||||
|
|
||||||
|
--wasm
|
||||||
|
Use the Wasm compiler versions
|
||||||
|
|
||||||
|
-r, --resolc <RESOLC>
|
||||||
|
The path to the `resolc` executable to be tested.
|
||||||
|
|
||||||
|
By default it uses the `resolc` binary found in `$PATH`.
|
||||||
|
|
||||||
|
If `--wasm` is set, this should point to the resolc Wasm ile.
|
||||||
|
|
||||||
|
[default: resolc]
|
||||||
|
|
||||||
|
-c, --corpus <CORPUS>
|
||||||
|
A list of test corpus JSON files to be tested
|
||||||
|
|
||||||
|
-w, --workdir <WORKING_DIRECTORY>
|
||||||
|
A place to store temporary artifacts during test execution.
|
||||||
|
|
||||||
|
Creates a temporary dir if not specified.
|
||||||
|
|
||||||
|
-g, --geth <GETH>
|
||||||
|
The path to the `geth` executable.
|
||||||
|
|
||||||
|
By default it uses `geth` binary found in `$PATH`.
|
||||||
|
|
||||||
|
[default: geth]
|
||||||
|
|
||||||
|
--geth-start-timeout <GETH_START_TIMEOUT>
|
||||||
|
The maximum time in milliseconds to wait for geth to start
|
||||||
|
|
||||||
|
[default: 5000]
|
||||||
|
|
||||||
|
--genesis <GENESIS_FILE>
|
||||||
|
Configure nodes according to this genesis.json file
|
||||||
|
|
||||||
|
[default: genesis.json]
|
||||||
|
|
||||||
|
-a, --account <ACCOUNT>
|
||||||
|
The signing account private key
|
||||||
|
|
||||||
|
[default: 0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d]
|
||||||
|
|
||||||
|
--private-keys-count <PRIVATE_KEYS_TO_ADD>
|
||||||
|
This argument controls which private keys the nodes should have access to and be added to its wallet signers. With a value of N, private keys (0, N] will be added to the signer set of the node
|
||||||
|
|
||||||
|
[default: 100000]
|
||||||
|
|
||||||
|
-l, --leader <LEADER>
|
||||||
|
The differential testing leader node implementation
|
||||||
|
|
||||||
|
[default: geth]
|
||||||
|
|
||||||
|
Possible values:
|
||||||
|
- geth: The go-ethereum reference full node EVM implementation
|
||||||
|
- kitchensink: The kitchensink runtime provides the PolkaVM (PVM) based node implentation
|
||||||
|
|
||||||
|
-f, --follower <FOLLOWER>
|
||||||
|
The differential testing follower node implementation
|
||||||
|
|
||||||
|
[default: kitchensink]
|
||||||
|
|
||||||
|
Possible values:
|
||||||
|
- geth: The go-ethereum reference full node EVM implementation
|
||||||
|
- kitchensink: The kitchensink runtime provides the PolkaVM (PVM) based node implentation
|
||||||
|
|
||||||
|
--compile-only <COMPILE_ONLY>
|
||||||
|
Only compile against this testing platform (doesn't execute the tests)
|
||||||
|
|
||||||
|
Possible values:
|
||||||
|
- geth: The go-ethereum reference full node EVM implementation
|
||||||
|
- kitchensink: The kitchensink runtime provides the PolkaVM (PVM) based node implentation
|
||||||
|
|
||||||
|
--number-of-nodes <NUMBER_OF_NODES>
|
||||||
|
Determines the amount of nodes that will be spawned for each chain
|
||||||
|
|
||||||
|
[default: 1]
|
||||||
|
|
||||||
|
--number-of-threads <NUMBER_OF_THREADS>
|
||||||
|
Determines the amount of tokio worker threads that will will be used
|
||||||
|
|
||||||
|
[default: 16]
|
||||||
|
|
||||||
|
--number-concurrent-tasks <NUMBER_CONCURRENT_TASKS>
|
||||||
|
Determines the amount of concurrent tasks that will be spawned to run tests. Defaults to 10 x the number of nodes
|
||||||
|
|
||||||
|
-e, --extract-problems
|
||||||
|
Extract problems back to the test corpus
|
||||||
|
|
||||||
|
-k, --kitchensink <KITCHENSINK>
|
||||||
|
The path to the `kitchensink` executable.
|
||||||
|
|
||||||
|
By default it uses `substrate-node` binary found in `$PATH`.
|
||||||
|
|
||||||
|
[default: substrate-node]
|
||||||
|
|
||||||
|
-p, --eth_proxy <ETH_PROXY>
|
||||||
|
The path to the `eth_proxy` executable.
|
||||||
|
|
||||||
|
By default it uses `eth-rpc` binary found in `$PATH`.
|
||||||
|
|
||||||
|
[default: eth-rpc]
|
||||||
|
|
||||||
|
-i, --invalidate-compilation-cache
|
||||||
|
Controls if the compilation cache should be invalidated or not
|
||||||
|
|
||||||
|
-h, --help
|
||||||
|
Print help (see a summary with '-h')
|
||||||
```
|
```
|
||||||
|
|
||||||
For example, to run the [complex Solidity tests](https://github.com/matter-labs/era-compiler-tests/tree/main/solidity/complex), define a corpus structure as follows:
|
To run tests with this tool you need a corpus JSON file that defines the tests included in the corpus. The simplest corpus file looks like the following:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"name": "ML Solidity Complex",
|
"name": "MatterLabs Solidity Simple, Complex, and Semantic Tests",
|
||||||
"path": "/path/to/era-compiler-tests/solidity/complex"
|
"path": "resolc-compiler-tests/fixtures/solidity"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Assuming this to be saved in a `ml-solidity-complex.json` file, the following command will try to compile and execute the tests found inside the corpus:
|
> [!NOTE]
|
||||||
|
> Note that the tests can be found in the [`resolc-compiler-tests`](https://github.com/paritytech/resolc-compiler-tests) repository.
|
||||||
|
|
||||||
|
The above corpus file instructs the tool to look for all of the test cases contained within all of the metadata files of the specified directory.
|
||||||
|
|
||||||
|
The simplest command to run this tool is the following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
RUST_LOG=debug cargo r --release -p revive-dt-core -- --corpus ml-solidity-complex.json
|
RUST_LOG="info" cargo run --release -- \
|
||||||
|
--corpus path_to_your_corpus_file.json \
|
||||||
|
--workdir path_to_a_temporary_directory_to_cache_things_in \
|
||||||
|
--number-of-nodes 5 \
|
||||||
|
> logs.log \
|
||||||
|
2> output.log
|
||||||
|
```
|
||||||
|
|
||||||
|
The above command will run the tool executing every one of the tests discovered in the path specified in the corpus file. All of the logs from the execution will be persisted in the `logs.log` file and all of the output of the tool will be persisted to the `output.log` file. If all that you're looking for is to run the tool and check which tests succeeded and failed, then the `output.log` file is what you need to be looking at. However, if you're contributing the to the tool then the `logs.log` file will be very valuable.
|
||||||
|
|
||||||
|
If you only want to run a subset of tests, then you can specify that in your corpus file. The following is an example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "MatterLabs Solidity Simple, Complex, and Semantic Tests",
|
||||||
|
"paths": [
|
||||||
|
"path/to/a/single/metadata/file/I/want/to/run.json",
|
||||||
|
"path/to/a/directory/to/find/all/metadata/files/within"
|
||||||
|
]
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -15,3 +15,6 @@ once_cell = { workspace = true }
|
|||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
tokio = { workspace = true, default-features = false, features = ["time"] }
|
tokio = { workspace = true, default-features = false, features = ["time"] }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -3,19 +3,28 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
/// This method clears the passed directory of all of the files and directories contained within
|
/// This method clears the passed directory of all of the files and directories contained within
|
||||||
/// without deleting the directory.
|
/// without deleting the directory.
|
||||||
pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> {
|
pub fn clear_directory(path: impl AsRef<Path>) -> Result<()> {
|
||||||
for entry in read_dir(path.as_ref())? {
|
for entry in read_dir(path.as_ref())
|
||||||
let entry = entry?;
|
.with_context(|| format!("Failed to read directory: {}", path.as_ref().display()))?
|
||||||
|
{
|
||||||
|
let entry = entry.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to read an entry in directory: {}",
|
||||||
|
path.as_ref().display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
let entry_path = entry.path();
|
let entry_path = entry.path();
|
||||||
|
|
||||||
if entry_path.is_file() {
|
if entry_path.is_file() {
|
||||||
remove_file(entry_path)?
|
remove_file(&entry_path)
|
||||||
|
.with_context(|| format!("Failed to remove file: {}", entry_path.display()))?
|
||||||
} else {
|
} else {
|
||||||
remove_dir_all(entry_path)?
|
remove_dir_all(&entry_path)
|
||||||
|
.with_context(|| format!("Failed to remove directory: {}", entry_path.display()))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Context as _, Result, anyhow};
|
||||||
|
|
||||||
const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60);
|
const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60);
|
||||||
|
|
||||||
@@ -38,7 +38,10 @@ where
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
match future().await? {
|
match future()
|
||||||
|
.await
|
||||||
|
.context("Polled future returned an error during polling loop")?
|
||||||
|
{
|
||||||
ControlFlow::Continue(()) => {
|
ControlFlow::Continue(()) => {
|
||||||
let next_wait_duration = match polling_wait_behavior {
|
let next_wait_duration = match polling_wait_behavior {
|
||||||
PollingWaitBehavior::Constant(duration) => duration,
|
PollingWaitBehavior::Constant(duration) => duration,
|
||||||
|
|||||||
@@ -1,3 +1,25 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! impl_for_wrapper {
|
||||||
|
(Display, $ident: ident) => {
|
||||||
|
#[automatically_derived]
|
||||||
|
impl std::fmt::Display for $ident {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
(FromStr, $ident: ident) => {
|
||||||
|
#[automatically_derived]
|
||||||
|
impl std::str::FromStr for $ident {
|
||||||
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> anyhow::Result<Self> {
|
||||||
|
s.parse().map(Self).map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Defines wrappers around types.
|
/// Defines wrappers around types.
|
||||||
///
|
///
|
||||||
/// For example, the macro invocation seen below:
|
/// For example, the macro invocation seen below:
|
||||||
@@ -42,7 +64,13 @@
|
|||||||
macro_rules! define_wrapper_type {
|
macro_rules! define_wrapper_type {
|
||||||
(
|
(
|
||||||
$(#[$meta: meta])*
|
$(#[$meta: meta])*
|
||||||
$vis:vis struct $ident: ident($ty: ty);
|
$vis:vis struct $ident: ident($ty: ty)
|
||||||
|
|
||||||
|
$(
|
||||||
|
impl $($trait_ident: ident),*
|
||||||
|
)?
|
||||||
|
|
||||||
|
;
|
||||||
) => {
|
) => {
|
||||||
$(#[$meta])*
|
$(#[$meta])*
|
||||||
$vis struct $ident($ty);
|
$vis struct $ident($ty);
|
||||||
@@ -98,9 +126,15 @@ macro_rules! define_wrapper_type {
|
|||||||
value.0
|
value.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
$(
|
||||||
|
$crate::macros::impl_for_wrapper!($trait_ident, $ident);
|
||||||
|
)*
|
||||||
|
)?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Technically not needed but this allows for the macro to be found in the `macros` module of the
|
/// 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.
|
/// crate in addition to being found in the root of the crate.
|
||||||
pub use define_wrapper_type;
|
pub use {define_wrapper_type, impl_for_wrapper};
|
||||||
|
|||||||
@@ -6,6 +6,42 @@ pub enum VersionOrRequirement {
|
|||||||
Requirement(VersionReq),
|
Requirement(VersionReq),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionOrRequirement {
|
||||||
|
/// A helper function to convert a [`semver::Version`] into a [`semver::VersionReq`].
|
||||||
|
pub fn version_to_requirement(version: &Version) -> VersionReq {
|
||||||
|
// Ignoring "build" metadata in the version, we can turn
|
||||||
|
// it into a requirement which is an exact match for the
|
||||||
|
// given version and nothing else:
|
||||||
|
VersionReq {
|
||||||
|
comparators: vec![semver::Comparator {
|
||||||
|
op: semver::Op::Exact,
|
||||||
|
major: version.major,
|
||||||
|
minor: Some(version.minor),
|
||||||
|
patch: Some(version.patch),
|
||||||
|
pre: version.pre.clone(),
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serde::Serialize for VersionOrRequirement {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
VersionOrRequirement::Version(v) => serializer.serialize_str(&v.to_string()),
|
||||||
|
VersionOrRequirement::Requirement(r) => serializer.serialize_str(&r.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for VersionOrRequirement {
|
||||||
|
fn default() -> Self {
|
||||||
|
VersionOrRequirement::Requirement(VersionReq::STAR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Version> for VersionOrRequirement {
|
impl From<Version> for VersionOrRequirement {
|
||||||
fn from(value: Version) -> Self {
|
fn from(value: Version) -> Self {
|
||||||
Self::Version(value)
|
Self::Version(value)
|
||||||
@@ -18,24 +54,45 @@ impl From<VersionReq> for VersionOrRequirement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<VersionOrRequirement> for VersionReq {
|
||||||
|
fn from(value: VersionOrRequirement) -> Self {
|
||||||
|
match value {
|
||||||
|
VersionOrRequirement::Version(version) => {
|
||||||
|
VersionOrRequirement::version_to_requirement(&version)
|
||||||
|
}
|
||||||
|
VersionOrRequirement::Requirement(version_req) => version_req,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<VersionOrRequirement> for Version {
|
impl TryFrom<VersionOrRequirement> for Version {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(value: VersionOrRequirement) -> Result<Self, Self::Error> {
|
fn try_from(value: VersionOrRequirement) -> Result<Self, Self::Error> {
|
||||||
let VersionOrRequirement::Version(version) = value else {
|
match value {
|
||||||
anyhow::bail!("Version or requirement was not a version");
|
VersionOrRequirement::Version(version) => Ok(version),
|
||||||
};
|
VersionOrRequirement::Requirement(mut version_req) => {
|
||||||
Ok(version)
|
if version_req.comparators.len() != 1 {
|
||||||
}
|
anyhow::bail!(
|
||||||
|
"The version requirement in VersionOrRequirement is not a single exact version"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<VersionOrRequirement> for VersionReq {
|
let c = version_req.comparators.pop().unwrap();
|
||||||
type Error = anyhow::Error;
|
let (semver::Op::Exact, Some(minor), Some(patch)) = (c.op, c.minor, c.patch) else {
|
||||||
|
anyhow::bail!(
|
||||||
fn try_from(value: VersionOrRequirement) -> Result<Self, Self::Error> {
|
"The version requirement in VersionOrRequirement is not an exact version"
|
||||||
let VersionOrRequirement::Requirement(requirement) = value else {
|
);
|
||||||
anyhow::bail!("Version or requirement was not a requirement");
|
|
||||||
};
|
};
|
||||||
Ok(requirement)
|
|
||||||
|
Ok(Version {
|
||||||
|
major: c.major,
|
||||||
|
minor,
|
||||||
|
patch,
|
||||||
|
pre: c.pre,
|
||||||
|
build: Default::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,16 @@ revive-common = { workspace = true }
|
|||||||
alloy = { workspace = true }
|
alloy = { workspace = true }
|
||||||
alloy-primitives = { workspace = true }
|
alloy-primitives = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
dashmap = { workspace = true }
|
||||||
foundry-compilers-artifacts = { workspace = true }
|
foundry-compilers-artifacts = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
use semver::Version;
|
|
||||||
|
|
||||||
/// This is the first version of solc that supports the `--via-ir` flag / "viaIR" input JSON.
|
|
||||||
pub const SOLC_VERSION_SUPPORTING_VIA_YUL_IR: Version = Version::new(0, 8, 13);
|
|
||||||
+22
-25
@@ -3,7 +3,7 @@
|
|||||||
//! - Polkadot revive resolc compiler
|
//! - Polkadot revive resolc compiler
|
||||||
//! - Polkadot revive Wasm compiler
|
//! - Polkadot revive Wasm compiler
|
||||||
|
|
||||||
mod constants;
|
mod utils;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@@ -13,17 +13,19 @@ use std::{
|
|||||||
|
|
||||||
use alloy::json_abi::JsonAbi;
|
use alloy::json_abi::JsonAbi;
|
||||||
use alloy_primitives::Address;
|
use alloy_primitives::Address;
|
||||||
use semver::Version;
|
use anyhow::Context;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use revive_common::EVMVersion;
|
use revive_common::EVMVersion;
|
||||||
use revive_dt_common::cached_fs::read_to_string;
|
use revive_dt_common::cached_fs::read_to_string;
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
|
|
||||||
// Re-export this as it's a part of the compiler interface.
|
// Re-export this as it's a part of the compiler interface.
|
||||||
pub use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
pub use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
||||||
|
|
||||||
|
// Expose functionality for instantiating a SolcCompiler.
|
||||||
|
pub use utils::{SolcCompiler, solc_compiler};
|
||||||
|
|
||||||
pub mod revive_js;
|
pub mod revive_js;
|
||||||
pub mod revive_resolc;
|
pub mod revive_resolc;
|
||||||
pub mod solc;
|
pub mod solc;
|
||||||
@@ -40,28 +42,19 @@ pub trait SolidityCompiler {
|
|||||||
additional_options: Self::Options,
|
additional_options: Self::Options,
|
||||||
) -> impl Future<Output = anyhow::Result<CompilerOutput>>;
|
) -> impl Future<Output = anyhow::Result<CompilerOutput>>;
|
||||||
|
|
||||||
fn new(solc_executable: PathBuf) -> Self;
|
/// Instantiate a new compiler.
|
||||||
|
fn new(config: &Arguments) -> Self;
|
||||||
fn get_compiler_executable(
|
|
||||||
config: &Arguments,
|
|
||||||
version: impl Into<VersionOrRequirement>,
|
|
||||||
) -> impl Future<Output = anyhow::Result<PathBuf>>;
|
|
||||||
|
|
||||||
fn version(&self) -> anyhow::Result<Version>;
|
|
||||||
|
|
||||||
/// Does the compiler support the provided mode and version settings?
|
/// Does the compiler support the provided mode and version settings?
|
||||||
fn supports_mode(
|
fn supports_mode(optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool;
|
||||||
compiler_version: &Version,
|
|
||||||
optimize_setting: ModeOptimizerSetting,
|
|
||||||
pipeline: ModePipeline,
|
|
||||||
) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The generic compilation input configuration.
|
/// The generic compilation input configuration.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct CompilerInput {
|
pub struct CompilerInput {
|
||||||
pub pipeline: Option<ModePipeline>,
|
pub pipeline: Option<ModePipeline>,
|
||||||
pub optimization: Option<ModeOptimizerSetting>,
|
pub optimization: Option<ModeOptimizerSetting>,
|
||||||
|
pub solc: Option<SolcCompiler>,
|
||||||
pub evm_version: Option<EVMVersion>,
|
pub evm_version: Option<EVMVersion>,
|
||||||
pub allow_paths: Vec<PathBuf>,
|
pub allow_paths: Vec<PathBuf>,
|
||||||
pub base_path: Option<PathBuf>,
|
pub base_path: Option<PathBuf>,
|
||||||
@@ -99,6 +92,7 @@ where
|
|||||||
input: CompilerInput {
|
input: CompilerInput {
|
||||||
pipeline: Default::default(),
|
pipeline: Default::default(),
|
||||||
optimization: Default::default(),
|
optimization: Default::default(),
|
||||||
|
solc: Default::default(),
|
||||||
evm_version: Default::default(),
|
evm_version: Default::default(),
|
||||||
allow_paths: Default::default(),
|
allow_paths: Default::default(),
|
||||||
base_path: Default::default(),
|
base_path: Default::default(),
|
||||||
@@ -110,6 +104,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_solc(mut self, value: impl Into<Option<SolcCompiler>>) -> Self {
|
||||||
|
self.input.solc = value.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_optimization(mut self, value: impl Into<Option<ModeOptimizerSetting>>) -> Self {
|
pub fn with_optimization(mut self, value: impl Into<Option<ModeOptimizerSetting>>) -> Self {
|
||||||
self.input.optimization = value.into();
|
self.input.optimization = value.into();
|
||||||
self
|
self
|
||||||
@@ -136,9 +135,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
pub fn with_source(mut self, path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||||
self.input
|
self.input.sources.insert(
|
||||||
.sources
|
path.as_ref().to_path_buf(),
|
||||||
.insert(path.as_ref().to_path_buf(), read_to_string(path.as_ref())?);
|
read_to_string(path.as_ref()).context("Failed to read the contract source")?,
|
||||||
|
);
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,11 +177,8 @@ where
|
|||||||
callback(self)
|
callback(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn try_build(
|
pub async fn try_build(self, config: &Arguments) -> anyhow::Result<CompilerOutput> {
|
||||||
self,
|
T::new(config)
|
||||||
compiler_path: impl AsRef<Path>,
|
|
||||||
) -> anyhow::Result<CompilerOutput> {
|
|
||||||
T::new(compiler_path.as_ref().to_path_buf())
|
|
||||||
.build(self.input, self.additional_options)
|
.build(self.input, self.additional_options)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
//! Implements the [SolidityCompiler] trait with `resolc` for
|
//! Implements the [SolidityCompiler] trait with `resolc` for
|
||||||
//! compiling contracts to PolkaVM (PVM) bytecode.
|
//! compiling contracts to PolkaVM (PVM) bytecode.
|
||||||
|
|
||||||
use std::{
|
use std::{path::PathBuf, process::Stdio};
|
||||||
path::PathBuf,
|
|
||||||
process::{Command, Stdio},
|
|
||||||
};
|
|
||||||
|
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_solc_json_interface::{
|
use revive_solc_json_interface::{
|
||||||
SolcStandardJsonInput, SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
|
SolcStandardJsonInput, SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
|
||||||
@@ -14,7 +10,6 @@ use revive_solc_json_interface::{
|
|||||||
SolcStandardJsonOutput,
|
SolcStandardJsonOutput,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::constants::SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
|
|
||||||
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
||||||
|
|
||||||
use alloy::json_abi::JsonAbi;
|
use alloy::json_abi::JsonAbi;
|
||||||
@@ -22,10 +17,6 @@ use anyhow::Context;
|
|||||||
use semver::Version;
|
use semver::Version;
|
||||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||||
|
|
||||||
// TODO: I believe that we need to also pass the solc compiler to resolc so that resolc uses the
|
|
||||||
// specified solc compiler. I believe that currently we completely ignore the specified solc binary
|
|
||||||
// when invoking resolc which doesn't seem right if we're using solc as a compiler frontend.
|
|
||||||
|
|
||||||
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
|
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Resolc {
|
pub struct Resolc {
|
||||||
@@ -42,6 +33,7 @@ impl SolidityCompiler for Resolc {
|
|||||||
CompilerInput {
|
CompilerInput {
|
||||||
pipeline,
|
pipeline,
|
||||||
optimization,
|
optimization,
|
||||||
|
solc,
|
||||||
evm_version,
|
evm_version,
|
||||||
allow_paths,
|
allow_paths,
|
||||||
base_path,
|
base_path,
|
||||||
@@ -59,6 +51,7 @@ impl SolidityCompiler for Resolc {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let solc = solc.ok_or_else(|| anyhow::anyhow!("solc compiler not provided to resolc."))?;
|
||||||
let input = SolcStandardJsonInput {
|
let input = SolcStandardJsonInput {
|
||||||
language: SolcStandardJsonInputLanguage::Solidity,
|
language: SolcStandardJsonInputLanguage::Solidity,
|
||||||
sources: sources
|
sources: sources
|
||||||
@@ -104,6 +97,8 @@ impl SolidityCompiler for Resolc {
|
|||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
|
.arg("--solc")
|
||||||
|
.arg(&solc.path)
|
||||||
.arg("--standard-json");
|
.arg("--standard-json");
|
||||||
|
|
||||||
if let Some(ref base_path) = base_path {
|
if let Some(ref base_path) = base_path {
|
||||||
@@ -118,18 +113,28 @@ impl SolidityCompiler for Resolc {
|
|||||||
.join(","),
|
.join(","),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let mut child = command.spawn()?;
|
let mut child = command
|
||||||
|
.spawn()
|
||||||
|
.with_context(|| format!("Failed to spawn resolc at {}", self.resolc_path.display()))?;
|
||||||
|
|
||||||
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
|
let stdin_pipe = child.stdin.as_mut().expect("stdin must be piped");
|
||||||
let serialized_input = serde_json::to_vec(&input)?;
|
let serialized_input = serde_json::to_vec(&input)
|
||||||
stdin_pipe.write_all(&serialized_input).await?;
|
.context("Failed to serialize Standard JSON input for resolc")?;
|
||||||
|
stdin_pipe
|
||||||
|
.write_all(&serialized_input)
|
||||||
|
.await
|
||||||
|
.context("Failed to write Standard JSON to resolc stdin")?;
|
||||||
|
|
||||||
let output = child.wait_with_output().await?;
|
let output = child
|
||||||
|
.wait_with_output()
|
||||||
|
.await
|
||||||
|
.context("Failed while waiting for resolc process to finish")?;
|
||||||
let stdout = output.stdout;
|
let stdout = output.stdout;
|
||||||
let stderr = output.stderr;
|
let stderr = output.stderr;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
let json_in = serde_json::to_string_pretty(&input)?;
|
let json_in = serde_json::to_string_pretty(&input)
|
||||||
|
.context("Failed to pretty-print Standard JSON input for logging")?;
|
||||||
let message = String::from_utf8_lossy(&stderr);
|
let message = String::from_utf8_lossy(&stderr);
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
status = %output.status,
|
status = %output.status,
|
||||||
@@ -140,12 +145,14 @@ impl SolidityCompiler for Resolc {
|
|||||||
anyhow::bail!("Compilation failed with an error: {message}");
|
anyhow::bail!("Compilation failed with an error: {message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsed = serde_json::from_slice::<SolcStandardJsonOutput>(&stdout).map_err(|e| {
|
let parsed = serde_json::from_slice::<SolcStandardJsonOutput>(&stdout)
|
||||||
|
.map_err(|e| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
||||||
String::from_utf8_lossy(&stderr)
|
String::from_utf8_lossy(&stderr)
|
||||||
)
|
)
|
||||||
})?;
|
})
|
||||||
|
.context("Failed to parse resolc standard JSON output")?;
|
||||||
|
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
output = %serde_json::to_string(&parsed).unwrap(),
|
output = %serde_json::to_string(&parsed).unwrap(),
|
||||||
@@ -172,7 +179,10 @@ impl SolidityCompiler for Resolc {
|
|||||||
|
|
||||||
let mut compiler_output = CompilerOutput::default();
|
let mut compiler_output = CompilerOutput::default();
|
||||||
for (source_path, contracts) in contracts.into_iter() {
|
for (source_path, contracts) in contracts.into_iter() {
|
||||||
let source_path = PathBuf::from(source_path).canonicalize()?;
|
let src_for_msg = source_path.clone();
|
||||||
|
let source_path = PathBuf::from(source_path)
|
||||||
|
.canonicalize()
|
||||||
|
.with_context(|| format!("Failed to canonicalize path {src_for_msg}"))?;
|
||||||
|
|
||||||
let map = compiler_output.contracts.entry(source_path).or_default();
|
let map = compiler_output.contracts.entry(source_path).or_default();
|
||||||
for (contract_name, contract_information) in contracts.into_iter() {
|
for (contract_name, contract_information) in contracts.into_iter() {
|
||||||
@@ -180,23 +190,41 @@ impl SolidityCompiler for Resolc {
|
|||||||
.evm
|
.evm
|
||||||
.and_then(|evm| evm.bytecode.clone())
|
.and_then(|evm| evm.bytecode.clone())
|
||||||
.context("Unexpected - Contract compiled with resolc has no bytecode")?;
|
.context("Unexpected - Contract compiled with resolc has no bytecode")?;
|
||||||
let abi = contract_information
|
let abi = {
|
||||||
|
let metadata = contract_information
|
||||||
.metadata
|
.metadata
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|metadata| metadata.as_object())
|
.context("No metadata found for the contract")?;
|
||||||
.and_then(|metadata| metadata.get("solc_metadata"))
|
let solc_metadata_str = match metadata {
|
||||||
.and_then(|solc_metadata| solc_metadata.as_str())
|
serde_json::Value::String(solc_metadata_str) => solc_metadata_str.as_str(),
|
||||||
.and_then(|metadata| serde_json::from_str::<serde_json::Value>(metadata).ok())
|
serde_json::Value::Object(metadata_object) => {
|
||||||
.and_then(|metadata| {
|
let solc_metadata_value = metadata_object
|
||||||
metadata.get("output").and_then(|output| {
|
.get("solc_metadata")
|
||||||
output
|
.context("Contract doesn't have a 'solc_metadata' field")?;
|
||||||
.get("abi")
|
solc_metadata_value
|
||||||
.and_then(|abi| serde_json::from_value::<JsonAbi>(abi.clone()).ok())
|
.as_str()
|
||||||
})
|
.context("The 'solc_metadata' field is not a string")?
|
||||||
})
|
}
|
||||||
.context(
|
serde_json::Value::Null
|
||||||
"Unexpected - Failed to get the ABI for a contract compiled with resolc",
|
| 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")?
|
||||||
|
};
|
||||||
map.insert(contract_name, (bytecode.object, abi));
|
map.insert(contract_name, (bytecode.object, abi));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,73 +232,15 @@ impl SolidityCompiler for Resolc {
|
|||||||
Ok(compiler_output)
|
Ok(compiler_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(resolc_path: PathBuf) -> Self {
|
fn new(config: &Arguments) -> Self {
|
||||||
Resolc { resolc_path }
|
Resolc {
|
||||||
|
resolc_path: config.resolc.clone(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_compiler_executable(
|
fn supports_mode(_optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool {
|
||||||
config: &Arguments,
|
// We only support the Y (IE compile via Yul IR) mode here. We must always compile
|
||||||
_version: impl Into<VersionOrRequirement>,
|
// via Yul IR as resolc needs this to translate to LLVM IR and then RISCV.
|
||||||
) -> anyhow::Result<PathBuf> {
|
|
||||||
if !config.resolc.as_os_str().is_empty() {
|
|
||||||
return Ok(config.resolc.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(PathBuf::from("resolc"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn version(&self) -> anyhow::Result<semver::Version> {
|
|
||||||
// Logic for parsing the resolc version from the following string:
|
|
||||||
// Solidity frontend for the revive compiler version 0.3.0+commit.b238913.llvm-18.1.8
|
|
||||||
|
|
||||||
let output = Command::new(self.resolc_path.as_path())
|
|
||||||
.arg("--version")
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn()?
|
|
||||||
.wait_with_output()?
|
|
||||||
.stdout;
|
|
||||||
let output = String::from_utf8_lossy(&output);
|
|
||||||
let version_string = output
|
|
||||||
.split("version ")
|
|
||||||
.nth(1)
|
|
||||||
.context("Version parsing failed")?
|
|
||||||
.split("+")
|
|
||||||
.next()
|
|
||||||
.context("Version parsing failed")?;
|
|
||||||
|
|
||||||
Version::parse(version_string).map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supports_mode(
|
|
||||||
compiler_version: &Version,
|
|
||||||
_optimize_setting: ModeOptimizerSetting,
|
|
||||||
pipeline: ModePipeline,
|
|
||||||
) -> bool {
|
|
||||||
// We only support the Y (IE compile via Yul IR) mode here, which also means that we can
|
|
||||||
// only use solc version 0.8.13 and above. We must always compile via Yul IR as resolc
|
|
||||||
// needs this to translate to LLVM IR and then RISCV.
|
|
||||||
pipeline == ModePipeline::ViaYulIR
|
pipeline == ModePipeline::ViaYulIR
|
||||||
&& compiler_version >= &SOLC_VERSION_SUPPORTING_VIA_YUL_IR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn compiler_version_can_be_obtained() {
|
|
||||||
// Arrange
|
|
||||||
let args = Arguments::default();
|
|
||||||
let path = Resolc::get_compiler_executable(&args, Version::new(0, 7, 6))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let compiler = Resolc::new(path);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
let version = compiler.version();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
let _ = version.expect("Failed to get version");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-116
@@ -1,18 +1,8 @@
|
|||||||
//! Implements the [SolidityCompiler] trait with solc for
|
//! Implements the [SolidityCompiler] trait with solc for
|
||||||
//! compiling contracts to EVM bytecode.
|
//! compiling contracts to EVM bytecode.
|
||||||
|
|
||||||
use std::{
|
use super::utils;
|
||||||
path::PathBuf,
|
|
||||||
process::{Command, Stdio},
|
|
||||||
};
|
|
||||||
|
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
|
||||||
use revive_dt_config::Arguments;
|
|
||||||
use revive_dt_solc_binaries::download_solc;
|
|
||||||
|
|
||||||
use super::constants::SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
|
|
||||||
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
use crate::{CompilerInput, CompilerOutput, ModeOptimizerSetting, ModePipeline, SolidityCompiler};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use foundry_compilers_artifacts::{
|
use foundry_compilers_artifacts::{
|
||||||
output_selection::{
|
output_selection::{
|
||||||
@@ -21,13 +11,12 @@ use foundry_compilers_artifacts::{
|
|||||||
solc::CompilerOutput as SolcOutput,
|
solc::CompilerOutput as SolcOutput,
|
||||||
solc::*,
|
solc::*,
|
||||||
};
|
};
|
||||||
use semver::Version;
|
use revive_dt_config::Arguments;
|
||||||
|
use std::process::Stdio;
|
||||||
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Solc {
|
pub struct Solc {}
|
||||||
solc_path: PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SolidityCompiler for Solc {
|
impl SolidityCompiler for Solc {
|
||||||
type Options = ();
|
type Options = ();
|
||||||
@@ -38,6 +27,7 @@ impl SolidityCompiler for Solc {
|
|||||||
CompilerInput {
|
CompilerInput {
|
||||||
pipeline,
|
pipeline,
|
||||||
optimization,
|
optimization,
|
||||||
|
solc,
|
||||||
evm_version,
|
evm_version,
|
||||||
allow_paths,
|
allow_paths,
|
||||||
base_path,
|
base_path,
|
||||||
@@ -47,7 +37,9 @@ impl SolidityCompiler for Solc {
|
|||||||
}: CompilerInput,
|
}: CompilerInput,
|
||||||
_: Self::Options,
|
_: Self::Options,
|
||||||
) -> anyhow::Result<CompilerOutput> {
|
) -> anyhow::Result<CompilerOutput> {
|
||||||
let compiler_supports_via_ir = self.version()? >= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
|
let solc = solc.ok_or_else(|| anyhow::anyhow!("solc compiler not provided to resolc."))?;
|
||||||
|
let compiler_supports_via_ir =
|
||||||
|
utils::solc_versions_supporting_yul_ir().matches(&solc.version);
|
||||||
|
|
||||||
// Be careful to entirely omit the viaIR field if the compiler does not support it,
|
// Be careful to entirely omit the viaIR field if the compiler does not support it,
|
||||||
// as it will error if you provide fields it does not know about. Because
|
// as it will error if you provide fields it does not know about. Because
|
||||||
@@ -113,7 +105,7 @@ impl SolidityCompiler for Solc {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut command = AsyncCommand::new(&self.solc_path);
|
let mut command = AsyncCommand::new(&solc.path);
|
||||||
command
|
command
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
@@ -132,15 +124,25 @@ impl SolidityCompiler for Solc {
|
|||||||
.join(","),
|
.join(","),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let mut child = command.spawn()?;
|
let mut child = command
|
||||||
|
.spawn()
|
||||||
|
.with_context(|| format!("Failed to spawn solc at {}", solc.path.display()))?;
|
||||||
|
|
||||||
let stdin = child.stdin.as_mut().expect("should be piped");
|
let stdin = child.stdin.as_mut().expect("should be piped");
|
||||||
let serialized_input = serde_json::to_vec(&input)?;
|
let serialized_input = serde_json::to_vec(&input)
|
||||||
stdin.write_all(&serialized_input).await?;
|
.context("Failed to serialize Standard JSON input for solc")?;
|
||||||
let output = child.wait_with_output().await?;
|
stdin
|
||||||
|
.write_all(&serialized_input)
|
||||||
|
.await
|
||||||
|
.context("Failed to write Standard JSON to solc stdin")?;
|
||||||
|
let output = child
|
||||||
|
.wait_with_output()
|
||||||
|
.await
|
||||||
|
.context("Failed while waiting for solc process to finish")?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
let json_in = serde_json::to_string_pretty(&input)?;
|
let json_in = serde_json::to_string_pretty(&input)
|
||||||
|
.context("Failed to pretty-print Standard JSON input for logging")?;
|
||||||
let message = String::from_utf8_lossy(&output.stderr);
|
let message = String::from_utf8_lossy(&output.stderr);
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
status = %output.status,
|
status = %output.status,
|
||||||
@@ -151,12 +153,14 @@ impl SolidityCompiler for Solc {
|
|||||||
anyhow::bail!("Compilation failed with an error: {message}");
|
anyhow::bail!("Compilation failed with an error: {message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsed = serde_json::from_slice::<SolcOutput>(&output.stdout).map_err(|e| {
|
let parsed = serde_json::from_slice::<SolcOutput>(&output.stdout)
|
||||||
|
.map_err(|e| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
||||||
String::from_utf8_lossy(&output.stdout)
|
String::from_utf8_lossy(&output.stdout)
|
||||||
)
|
)
|
||||||
})?;
|
})
|
||||||
|
.context("Failed to parse solc standard JSON output")?;
|
||||||
|
|
||||||
// Detecting if the compiler output contained errors and reporting them through logs and
|
// Detecting if the compiler output contained errors and reporting them through logs and
|
||||||
// errors instead of returning the compiler output that might contain errors.
|
// errors instead of returning the compiler output that might contain errors.
|
||||||
@@ -176,7 +180,12 @@ impl SolidityCompiler for Solc {
|
|||||||
for (contract_path, contracts) in parsed.contracts {
|
for (contract_path, contracts) in parsed.contracts {
|
||||||
let map = compiler_output
|
let map = compiler_output
|
||||||
.contracts
|
.contracts
|
||||||
.entry(contract_path.canonicalize()?)
|
.entry(contract_path.canonicalize().with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to canonicalize contract path {}",
|
||||||
|
contract_path.display()
|
||||||
|
)
|
||||||
|
})?)
|
||||||
.or_default();
|
.or_default();
|
||||||
for (contract_name, contract_info) in contracts.into_iter() {
|
for (contract_name, contract_info) in contracts.into_iter() {
|
||||||
let source_code = contract_info
|
let source_code = contract_info
|
||||||
@@ -197,100 +206,13 @@ impl SolidityCompiler for Solc {
|
|||||||
Ok(compiler_output)
|
Ok(compiler_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(solc_path: PathBuf) -> Self {
|
fn new(_config: &Arguments) -> Self {
|
||||||
Self { solc_path }
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_compiler_executable(
|
fn supports_mode(_optimize_setting: ModeOptimizerSetting, pipeline: ModePipeline) -> bool {
|
||||||
config: &Arguments,
|
|
||||||
version: impl Into<VersionOrRequirement>,
|
|
||||||
) -> anyhow::Result<PathBuf> {
|
|
||||||
let path = download_solc(config.directory(), version, config.wasm).await?;
|
|
||||||
Ok(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn version(&self) -> anyhow::Result<semver::Version> {
|
|
||||||
// The following is the parsing code for the version from the solc version strings which
|
|
||||||
// look like the following:
|
|
||||||
// ```
|
|
||||||
// solc, the solidity compiler commandline interface
|
|
||||||
// Version: 0.8.30+commit.73712a01.Darwin.appleclang
|
|
||||||
// ```
|
|
||||||
|
|
||||||
let child = Command::new(self.solc_path.as_path())
|
|
||||||
.arg("--version")
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn()?;
|
|
||||||
let output = child.wait_with_output()?;
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let version_line = output
|
|
||||||
.split("Version: ")
|
|
||||||
.nth(1)
|
|
||||||
.context("Version parsing failed")?;
|
|
||||||
let version_string = version_line
|
|
||||||
.split("+")
|
|
||||||
.next()
|
|
||||||
.context("Version parsing failed")?;
|
|
||||||
|
|
||||||
Version::parse(version_string).map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supports_mode(
|
|
||||||
compiler_version: &Version,
|
|
||||||
_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
|
// 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.
|
// (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::ViaEVMAssembly || pipeline == ModePipeline::ViaYulIR
|
||||||
|| (pipeline == ModePipeline::ViaYulIR
|
|
||||||
&& compiler_version >= &SOLC_VERSION_SUPPORTING_VIA_YUL_IR)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn compiler_version_can_be_obtained() {
|
|
||||||
// Arrange
|
|
||||||
let args = Arguments::default();
|
|
||||||
println!("Getting compiler path");
|
|
||||||
let path = Solc::get_compiler_executable(&args, Version::new(0, 7, 6))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
println!("Got compiler path");
|
|
||||||
let compiler = Solc::new(path);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
let version = compiler.version();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assert_eq!(
|
|
||||||
version.expect("Failed to get version"),
|
|
||||||
Version::new(0, 7, 6)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn compiler_version_can_be_obtained1() {
|
|
||||||
// Arrange
|
|
||||||
let args = Arguments::default();
|
|
||||||
println!("Getting compiler path");
|
|
||||||
let path = Solc::get_compiler_executable(&args, Version::new(0, 4, 21))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
println!("Got compiler path");
|
|
||||||
let compiler = Solc::new(path);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
let version = compiler.version();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assert_eq!(
|
|
||||||
version.expect("Failed to get version"),
|
|
||||||
Version::new(0, 4, 21)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::{Command, Stdio},
|
||||||
|
sync::LazyLock,
|
||||||
|
};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
|
use dashmap::DashMap;
|
||||||
|
use revive_dt_common::types::{ModePipeline, VersionOrRequirement};
|
||||||
|
use semver::{Version, VersionReq};
|
||||||
|
|
||||||
|
/// Return the path and version of a suitable `solc` compiler given the requirements provided.
|
||||||
|
///
|
||||||
|
/// This caches any compiler binaries/paths that are downloaded as a result of calling this.
|
||||||
|
pub async fn solc_compiler(
|
||||||
|
cache_directory: &Path,
|
||||||
|
fallback_version: &Version,
|
||||||
|
required_version: Option<&VersionReq>,
|
||||||
|
pipeline: ModePipeline,
|
||||||
|
) -> anyhow::Result<SolcCompiler> {
|
||||||
|
// Require Yul compatible solc, or any if we don't care about compiling via Yul.
|
||||||
|
let mut version_req = if pipeline == ModePipeline::ViaYulIR {
|
||||||
|
solc_versions_supporting_yul_ir()
|
||||||
|
} else {
|
||||||
|
VersionReq::STAR
|
||||||
|
};
|
||||||
|
|
||||||
|
// Take into account the version requirements passed in, too.
|
||||||
|
if let Some(other_version_req) = required_version {
|
||||||
|
version_req
|
||||||
|
.comparators
|
||||||
|
.extend(other_version_req.comparators.iter().cloned());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no requirements yet then fall back to the fallback version.
|
||||||
|
let version_req = if version_req == VersionReq::STAR {
|
||||||
|
VersionOrRequirement::version_to_requirement(fallback_version)
|
||||||
|
} else {
|
||||||
|
version_req
|
||||||
|
};
|
||||||
|
|
||||||
|
// Download (or pull from cache) a suitable solc compiler given this.
|
||||||
|
let solc_path =
|
||||||
|
revive_dt_solc_binaries::download_solc(cache_directory, version_req, false).await?;
|
||||||
|
let solc_version = solc_version(&solc_path).await?;
|
||||||
|
|
||||||
|
Ok(SolcCompiler {
|
||||||
|
version: solc_version,
|
||||||
|
path: solc_path,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `solc` compiler, returned from [`solc_compiler`].
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SolcCompiler {
|
||||||
|
/// Version of the compiler.
|
||||||
|
pub version: Version,
|
||||||
|
/// Path to the compiler executable.
|
||||||
|
pub path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch the solc version given a path to the executable
|
||||||
|
async fn solc_version(solc_path: &Path) -> anyhow::Result<semver::Version> {
|
||||||
|
/// This is a cache of the path of the compiler to the version number of the compiler. We
|
||||||
|
/// choose to cache the version in this way rather than through a field on the struct since
|
||||||
|
/// compiler objects are being created all the time from the path and the compiler object is
|
||||||
|
/// not reused over time.
|
||||||
|
static VERSION_CACHE: LazyLock<DashMap<PathBuf, Version>> = LazyLock::new(Default::default);
|
||||||
|
|
||||||
|
match VERSION_CACHE.entry(solc_path.to_path_buf()) {
|
||||||
|
dashmap::Entry::Occupied(occupied_entry) => Ok(occupied_entry.get().clone()),
|
||||||
|
dashmap::Entry::Vacant(vacant_entry) => {
|
||||||
|
// The following is the parsing code for the version from the solc version strings
|
||||||
|
// which look like the following:
|
||||||
|
// ```
|
||||||
|
// solc, the solidity compiler commandline interface
|
||||||
|
// Version: 0.8.30+commit.73712a01.Darwin.appleclang
|
||||||
|
// ```
|
||||||
|
let child = Command::new(solc_path)
|
||||||
|
.arg("--version")
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()?;
|
||||||
|
let output = child.wait_with_output()?;
|
||||||
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let version_line = output
|
||||||
|
.split("Version: ")
|
||||||
|
.nth(1)
|
||||||
|
.context("Version parsing failed")?;
|
||||||
|
let version_string = version_line
|
||||||
|
.split("+")
|
||||||
|
.next()
|
||||||
|
.context("Version parsing failed")?;
|
||||||
|
|
||||||
|
let version = Version::parse(version_string)?;
|
||||||
|
|
||||||
|
vacant_entry.insert(version.clone());
|
||||||
|
|
||||||
|
Ok(version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This returns the solc versions which support Yul IR.
|
||||||
|
pub fn solc_versions_supporting_yul_ir() -> VersionReq {
|
||||||
|
use semver::{Comparator, Op, Prerelease, VersionReq};
|
||||||
|
VersionReq {
|
||||||
|
comparators: vec![Comparator {
|
||||||
|
op: Op::GreaterEq,
|
||||||
|
major: 0,
|
||||||
|
minor: Some(8),
|
||||||
|
patch: Some(13),
|
||||||
|
pre: Prerelease::EMPTY,
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn compiler_version_can_be_obtained() {
|
||||||
|
// Arrange
|
||||||
|
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||||
|
let solc_path =
|
||||||
|
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 7, 6), false)
|
||||||
|
.await
|
||||||
|
.expect("can download solc");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let version = solc_version(&solc_path).await;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assert_eq!(
|
||||||
|
version.expect("Failed to get version"),
|
||||||
|
Version::new(0, 7, 6)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn compiler_version_can_be_obtained1() {
|
||||||
|
// Arrange
|
||||||
|
let temp_dir = tempfile::tempdir().expect("can create tempdir");
|
||||||
|
let solc_path =
|
||||||
|
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 4, 21), false)
|
||||||
|
.await
|
||||||
|
.expect("can download solc");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let version = solc_version(&solc_path).await;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assert_eq!(
|
||||||
|
version.expect("Failed to get version"),
|
||||||
|
Version::new(0, 4, 21)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,12 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use revive_dt_compiler::{Compiler, SolidityCompiler, revive_resolc::Resolc, solc::Solc};
|
use revive_dt_compiler::{Compiler, revive_resolc::Resolc, solc::Solc};
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use semver::Version;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn contracts_can_be_compiled_with_solc() {
|
async fn contracts_can_be_compiled_with_solc() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let args = Arguments::default();
|
let args = Arguments::default();
|
||||||
let compiler_path = Solc::get_compiler_executable(&args, Version::new(0, 8, 30))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
println!("About to assert");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let output = Compiler::<Solc>::new()
|
let output = Compiler::<Solc>::new()
|
||||||
@@ -19,7 +14,7 @@ async fn contracts_can_be_compiled_with_solc() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.with_source("./tests/assets/array_one_element/main.sol")
|
.with_source("./tests/assets/array_one_element/main.sol")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_build(compiler_path)
|
.try_build(&args)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@@ -50,9 +45,6 @@ async fn contracts_can_be_compiled_with_solc() {
|
|||||||
async fn contracts_can_be_compiled_with_resolc() {
|
async fn contracts_can_be_compiled_with_resolc() {
|
||||||
// Arrange
|
// Arrange
|
||||||
let args = Arguments::default();
|
let args = Arguments::default();
|
||||||
let compiler_path = Resolc::get_compiler_executable(&args, Version::new(0, 8, 30))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let output = Compiler::<Resolc>::new()
|
let output = Compiler::<Resolc>::new()
|
||||||
@@ -60,7 +52,7 @@ async fn contracts_can_be_compiled_with_resolc() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.with_source("./tests/assets/array_one_element/main.sol")
|
.with_source("./tests/assets/array_one_element/main.sol")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.try_build(compiler_path)
|
.try_build(&args)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ rust-version.workspace = true
|
|||||||
alloy = { workspace = true }
|
alloy = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
temp-dir = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use alloy::{network::EthereumWallet, signers::local::PrivateKeySigner};
|
|||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use temp_dir::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[derive(Debug, Parser, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Parser, Clone, Serialize, Deserialize)]
|
||||||
#[command(name = "retester")]
|
#[command(name = "retester")]
|
||||||
@@ -115,6 +115,18 @@ pub struct Arguments {
|
|||||||
#[arg(short, long = "kitchensink", default_value = "substrate-node")]
|
#[arg(short, long = "kitchensink", default_value = "substrate-node")]
|
||||||
pub kitchensink: PathBuf,
|
pub kitchensink: PathBuf,
|
||||||
|
|
||||||
|
/// The path to the `revive-dev-node` executable.
|
||||||
|
///
|
||||||
|
/// By default it uses `revive-dev-node` binary found in `$PATH`.
|
||||||
|
#[arg(long = "revive-dev-node", default_value = "revive-dev-node")]
|
||||||
|
pub revive_dev_node: PathBuf,
|
||||||
|
|
||||||
|
/// By default the tool uses the revive-dev-node when it's running differential tests against
|
||||||
|
/// PolkaVM since the dev-node is much faster than kitchensink. This flag allows the caller to
|
||||||
|
/// configure the tool to use kitchensink rather than the dev-node.
|
||||||
|
#[arg(long)]
|
||||||
|
pub use_kitchensink_not_dev_node: bool,
|
||||||
|
|
||||||
/// The path to the `eth_proxy` executable.
|
/// The path to the `eth_proxy` executable.
|
||||||
///
|
///
|
||||||
/// By default it uses `eth-rpc` binary found in `$PATH`.
|
/// By default it uses `eth-rpc` binary found in `$PATH`.
|
||||||
@@ -124,6 +136,14 @@ pub struct Arguments {
|
|||||||
/// Controls if the compilation cache should be invalidated or not.
|
/// Controls if the compilation cache should be invalidated or not.
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub invalidate_compilation_cache: bool,
|
pub invalidate_compilation_cache: bool,
|
||||||
|
|
||||||
|
/// Controls if the compiler input is included in the final report.
|
||||||
|
#[clap(long = "report.include-compiler-input")]
|
||||||
|
pub report_include_compiler_input: bool,
|
||||||
|
|
||||||
|
/// Controls if the compiler output is included in the final report.
|
||||||
|
#[clap(long = "report.include-compiler-output")]
|
||||||
|
pub report_include_compiler_output: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arguments {
|
impl Arguments {
|
||||||
|
|||||||
@@ -31,9 +31,12 @@ indexmap = { workspace = true }
|
|||||||
once_cell = { workspace = true }
|
once_cell = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
tracing-appender = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
temp-dir = { workspace = true }
|
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use std::{
|
|||||||
|
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use revive_dt_common::iterators::FilesWithExtensionIterator;
|
use revive_dt_common::iterators::FilesWithExtensionIterator;
|
||||||
use revive_dt_compiler::{Compiler, CompilerOutput, Mode, SolidityCompiler};
|
use revive_dt_compiler::{Compiler, CompilerInput, CompilerOutput, Mode, SolcCompiler};
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
|
use revive_dt_format::metadata::{ContractIdent, ContractInstance, Metadata};
|
||||||
|
|
||||||
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
|
use alloy::{hex::ToHexExt, json_abi::JsonAbi, primitives::Address};
|
||||||
use anyhow::{Error, Result};
|
use anyhow::{Context as _, Error, Result};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -29,12 +29,16 @@ impl CachedCompiler {
|
|||||||
pub async fn new(path: impl AsRef<Path>, invalidate_cache: bool) -> Result<Self> {
|
pub async fn new(path: impl AsRef<Path>, invalidate_cache: bool) -> Result<Self> {
|
||||||
let mut cache = ArtifactsCache::new(path);
|
let mut cache = ArtifactsCache::new(path);
|
||||||
if invalidate_cache {
|
if invalidate_cache {
|
||||||
cache = cache.with_invalidated_cache().await?;
|
cache = cache
|
||||||
|
.with_invalidated_cache()
|
||||||
|
.await
|
||||||
|
.context("Failed to invalidate compilation cache directory")?;
|
||||||
}
|
}
|
||||||
Ok(Self(cache))
|
Ok(Self(cache))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compiles or gets the compilation artifacts from the cache.
|
/// Compiles or gets the compilation artifacts from the cache.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[instrument(
|
#[instrument(
|
||||||
level = "debug",
|
level = "debug",
|
||||||
skip_all,
|
skip_all,
|
||||||
@@ -49,37 +53,42 @@ impl CachedCompiler {
|
|||||||
&self,
|
&self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
metadata_file_path: impl AsRef<Path>,
|
metadata_file_path: impl AsRef<Path>,
|
||||||
|
solc: SolcCompiler,
|
||||||
mode: &Mode,
|
mode: &Mode,
|
||||||
config: &Arguments,
|
config: &Arguments,
|
||||||
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
||||||
) -> Result<(CompilerOutput, Version)> {
|
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput)
|
||||||
|
+ Clone,
|
||||||
|
compilation_failure_report_callback: impl Fn(Option<CompilerInput>, String),
|
||||||
|
) -> Result<CompilerOutput> {
|
||||||
static CACHE_KEY_LOCK: Lazy<RwLock<HashMap<CacheKey, Arc<Mutex<()>>>>> =
|
static CACHE_KEY_LOCK: Lazy<RwLock<HashMap<CacheKey, Arc<Mutex<()>>>>> =
|
||||||
Lazy::new(Default::default);
|
Lazy::new(Default::default);
|
||||||
|
|
||||||
let compiler_version_or_requirement = mode.compiler_version_to_use(config.solc.clone());
|
|
||||||
let compiler_path = <P::Compiler as SolidityCompiler>::get_compiler_executable(
|
|
||||||
config,
|
|
||||||
compiler_version_or_requirement,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let compiler_version =
|
|
||||||
<P::Compiler as SolidityCompiler>::new(compiler_path.clone()).version()?;
|
|
||||||
|
|
||||||
let cache_key = CacheKey {
|
let cache_key = CacheKey {
|
||||||
platform_key: P::config_id().to_string(),
|
platform_key: P::config_id().to_string(),
|
||||||
compiler_version: compiler_version.clone(),
|
compiler_version: solc.version.clone(),
|
||||||
metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
|
metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
|
||||||
solc_mode: mode.clone(),
|
solc_mode: mode.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let compilation_callback = || {
|
let compilation_callback = || {
|
||||||
|
// let compiler_path = compiler_path.clone();
|
||||||
|
// let compiler_version = compiler_version.clone();
|
||||||
|
let compilation_success_report_callback = compilation_success_report_callback.clone();
|
||||||
async move {
|
async move {
|
||||||
compile_contracts::<P>(
|
compile_contracts::<P>(
|
||||||
metadata.directory()?,
|
metadata
|
||||||
compiler_path,
|
.directory()
|
||||||
metadata.files_to_compile()?,
|
.context("Failed to get metadata directory while preparing compilation")?,
|
||||||
|
metadata
|
||||||
|
.files_to_compile()
|
||||||
|
.context("Failed to enumerate files to compile from metadata")?,
|
||||||
|
config,
|
||||||
|
solc,
|
||||||
mode,
|
mode,
|
||||||
deployed_libraries,
|
deployed_libraries,
|
||||||
|
compilation_success_report_callback,
|
||||||
|
compilation_failure_report_callback,
|
||||||
)
|
)
|
||||||
.map(|compilation_result| compilation_result.map(CacheValue::new))
|
.map(|compilation_result| compilation_result.map(CacheValue::new))
|
||||||
.await
|
.await
|
||||||
@@ -99,7 +108,10 @@ impl CachedCompiler {
|
|||||||
Some(_) => {
|
Some(_) => {
|
||||||
debug!("Deployed libraries defined, recompilation must take place");
|
debug!("Deployed libraries defined, recompilation must take place");
|
||||||
debug!("Cache miss");
|
debug!("Cache miss");
|
||||||
compilation_callback().await?.compiler_output
|
compilation_callback()
|
||||||
|
.await
|
||||||
|
.context("Compilation callback for deployed libraries failed")?
|
||||||
|
.compiler_output
|
||||||
}
|
}
|
||||||
// If no deployed libraries are specified then we can follow the cached flow and attempt
|
// If no deployed libraries are specified then we can follow the cached flow and attempt
|
||||||
// to lookup the compilation artifacts in the cache.
|
// to lookup the compilation artifacts in the cache.
|
||||||
@@ -124,30 +136,47 @@ impl CachedCompiler {
|
|||||||
};
|
};
|
||||||
let _guard = mutex.lock().await;
|
let _guard = mutex.lock().await;
|
||||||
|
|
||||||
self.0
|
match self.0.get(&cache_key).await {
|
||||||
.get_or_insert_with(&cache_key, compilation_callback)
|
Some(cache_value) => {
|
||||||
|
compilation_success_report_callback(
|
||||||
|
true,
|
||||||
|
None,
|
||||||
|
cache_value.compiler_output.clone(),
|
||||||
|
);
|
||||||
|
cache_value.compiler_output
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
compilation_callback()
|
||||||
.await
|
.await
|
||||||
.map(|value| value.compiler_output)?
|
.context("Compilation callback failed (cache miss path)")?
|
||||||
|
.compiler_output
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((compiled_contracts, compiler_version))
|
Ok(compiled_contracts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn compile_contracts<P: Platform>(
|
async fn compile_contracts<P: Platform>(
|
||||||
metadata_directory: impl AsRef<Path>,
|
metadata_directory: impl AsRef<Path>,
|
||||||
compiler_path: impl AsRef<Path>,
|
|
||||||
mut files_to_compile: impl Iterator<Item = PathBuf>,
|
mut files_to_compile: impl Iterator<Item = PathBuf>,
|
||||||
|
config: &Arguments,
|
||||||
|
solc: SolcCompiler,
|
||||||
mode: &Mode,
|
mode: &Mode,
|
||||||
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
deployed_libraries: Option<&HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>>,
|
||||||
|
compilation_success_report_callback: impl Fn(bool, Option<CompilerInput>, CompilerOutput),
|
||||||
|
compilation_failure_report_callback: impl Fn(Option<CompilerInput>, String),
|
||||||
) -> Result<CompilerOutput> {
|
) -> Result<CompilerOutput> {
|
||||||
let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref())
|
let all_sources_in_dir = FilesWithExtensionIterator::new(metadata_directory.as_ref())
|
||||||
.with_allowed_extension("sol")
|
.with_allowed_extension("sol")
|
||||||
.with_use_cached_fs(true)
|
.with_use_cached_fs(true)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Compiler::<P::Compiler>::new()
|
let compiler = Compiler::<P::Compiler>::new()
|
||||||
|
.with_solc(solc)
|
||||||
.with_allow_path(metadata_directory)
|
.with_allow_path(metadata_directory)
|
||||||
// Handling the modes
|
// Handling the modes
|
||||||
.with_optimization(mode.optimize_setting)
|
.with_optimization(mode.optimize_setting)
|
||||||
@@ -155,7 +184,8 @@ async fn compile_contracts<P: Platform>(
|
|||||||
// Adding the contract sources to the compiler.
|
// Adding the contract sources to the compiler.
|
||||||
.try_then(|compiler| {
|
.try_then(|compiler| {
|
||||||
files_to_compile.try_fold(compiler, |compiler, path| compiler.with_source(path))
|
files_to_compile.try_fold(compiler, |compiler, path| compiler.with_source(path))
|
||||||
})?
|
})
|
||||||
|
.inspect_err(|err| compilation_failure_report_callback(None, format!("{err:#}")))?
|
||||||
// Adding the deployed libraries to the compiler.
|
// Adding the deployed libraries to the compiler.
|
||||||
.then(|compiler| {
|
.then(|compiler| {
|
||||||
deployed_libraries
|
deployed_libraries
|
||||||
@@ -170,9 +200,19 @@ async fn compile_contracts<P: Platform>(
|
|||||||
.fold(compiler, |compiler, (ident, address, path)| {
|
.fold(compiler, |compiler, (ident, address, path)| {
|
||||||
compiler.with_library(path, ident.as_str(), *address)
|
compiler.with_library(path, ident.as_str(), *address)
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
.try_build(compiler_path)
|
|
||||||
|
let compiler_input = compiler.input();
|
||||||
|
let compiler_output = compiler
|
||||||
|
.try_build(config)
|
||||||
.await
|
.await
|
||||||
|
.inspect_err(|err| {
|
||||||
|
compilation_failure_report_callback(Some(compiler_input.clone()), format!("{err:#}"))
|
||||||
|
})
|
||||||
|
.context("Failed to configure compiler with sources and options")?;
|
||||||
|
|
||||||
|
compilation_success_report_callback(false, Some(compiler_input), compiler_output.clone());
|
||||||
|
Ok(compiler_output)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ArtifactsCache {
|
struct ArtifactsCache {
|
||||||
@@ -190,15 +230,20 @@ impl ArtifactsCache {
|
|||||||
pub async fn with_invalidated_cache(self) -> Result<Self> {
|
pub async fn with_invalidated_cache(self) -> Result<Self> {
|
||||||
cacache::clear(self.path.as_path())
|
cacache::clear(self.path.as_path())
|
||||||
.await
|
.await
|
||||||
.map_err(Into::<Error>::into)?;
|
.map_err(Into::<Error>::into)
|
||||||
|
.with_context(|| format!("Failed to clear cache at {}", self.path.display()))?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all, err)]
|
#[instrument(level = "debug", skip_all, err)]
|
||||||
pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> {
|
pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> {
|
||||||
let key = bson::to_vec(key)?;
|
let key = bson::to_vec(key).context("Failed to serialize cache key (bson)")?;
|
||||||
let value = bson::to_vec(value)?;
|
let value = bson::to_vec(value).context("Failed to serialize cache value (bson)")?;
|
||||||
cacache::write(self.path.as_path(), key.encode_hex(), value).await?;
|
cacache::write(self.path.as_path(), key.encode_hex(), value)
|
||||||
|
.await
|
||||||
|
.with_context(|| {
|
||||||
|
format!("Failed to write cache entry under {}", self.path.display())
|
||||||
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+129
-152
@@ -16,26 +16,25 @@ use alloy::rpc::types::trace::geth::{
|
|||||||
};
|
};
|
||||||
use alloy::{
|
use alloy::{
|
||||||
primitives::Address,
|
primitives::Address,
|
||||||
rpc::types::{
|
rpc::types::{TransactionRequest, trace::geth::DiffMode},
|
||||||
TransactionRequest,
|
|
||||||
trace::geth::{AccountState, DiffMode},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use futures::TryStreamExt;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use revive_dt_format::traits::{ResolutionContext, ResolverApi};
|
use revive_dt_format::traits::{ResolutionContext, ResolverApi};
|
||||||
|
use revive_dt_report::ExecutionSpecificReporter;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
use revive_dt_format::case::{Case, CaseIdx};
|
use revive_dt_format::case::Case;
|
||||||
use revive_dt_format::input::{
|
use revive_dt_format::input::{
|
||||||
BalanceAssertion, Calldata, EtherValue, Expected, ExpectedOutput, Input, Method,
|
BalanceAssertion, Calldata, EtherValue, Expected, ExpectedOutput, Input, Method, StepIdx,
|
||||||
StorageEmptyAssertion,
|
StorageEmptyAssertion,
|
||||||
};
|
};
|
||||||
use revive_dt_format::metadata::{ContractIdent, ContractInstance, ContractPathAndIdent};
|
use revive_dt_format::metadata::{ContractIdent, ContractInstance, ContractPathAndIdent};
|
||||||
use revive_dt_format::{input::Step, metadata::Metadata};
|
use revive_dt_format::{input::Step, metadata::Metadata};
|
||||||
use revive_dt_node::Node;
|
|
||||||
use revive_dt_node_interaction::EthereumNode;
|
use revive_dt_node_interaction::EthereumNode;
|
||||||
use tracing::Instrument;
|
use tokio::try_join;
|
||||||
|
use tracing::{Instrument, info, info_span, instrument};
|
||||||
|
|
||||||
use crate::Platform;
|
use crate::Platform;
|
||||||
|
|
||||||
@@ -53,6 +52,9 @@ pub struct CaseState<T: Platform> {
|
|||||||
/// Stores the version used for the current case.
|
/// Stores the version used for the current case.
|
||||||
compiler_version: Version,
|
compiler_version: Version,
|
||||||
|
|
||||||
|
/// The execution reporter.
|
||||||
|
execution_reporter: ExecutionSpecificReporter,
|
||||||
|
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,12 +66,14 @@ where
|
|||||||
compiler_version: Version,
|
compiler_version: Version,
|
||||||
compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>,
|
compiled_contracts: HashMap<PathBuf, HashMap<String, (String, JsonAbi)>>,
|
||||||
deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>,
|
deployed_contracts: HashMap<ContractInstance, (ContractIdent, Address, JsonAbi)>,
|
||||||
|
execution_reporter: ExecutionSpecificReporter,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
compiled_contracts,
|
compiled_contracts,
|
||||||
deployed_contracts,
|
deployed_contracts,
|
||||||
variables: Default::default(),
|
variables: Default::default(),
|
||||||
compiler_version,
|
compiler_version,
|
||||||
|
execution_reporter,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,85 +81,99 @@ where
|
|||||||
pub async fn handle_step(
|
pub async fn handle_step(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
case_idx: CaseIdx,
|
|
||||||
step: &Step,
|
step: &Step,
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<StepOutput> {
|
) -> anyhow::Result<StepOutput> {
|
||||||
match step {
|
match step {
|
||||||
Step::FunctionCall(input) => {
|
Step::FunctionCall(input) => {
|
||||||
let (receipt, geth_trace, diff_mode) =
|
let (receipt, geth_trace, diff_mode) = self
|
||||||
self.handle_input(metadata, case_idx, input, node).await?;
|
.handle_input(metadata, input, node)
|
||||||
|
.await
|
||||||
|
.context("Failed to handle function call step")?;
|
||||||
Ok(StepOutput::FunctionCall(receipt, geth_trace, diff_mode))
|
Ok(StepOutput::FunctionCall(receipt, geth_trace, diff_mode))
|
||||||
}
|
}
|
||||||
Step::BalanceAssertion(balance_assertion) => {
|
Step::BalanceAssertion(balance_assertion) => {
|
||||||
self.handle_balance_assertion(metadata, case_idx, balance_assertion, node)
|
self.handle_balance_assertion(metadata, balance_assertion, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to handle balance assertion step")?;
|
||||||
Ok(StepOutput::BalanceAssertion)
|
Ok(StepOutput::BalanceAssertion)
|
||||||
}
|
}
|
||||||
Step::StorageEmptyAssertion(storage_empty) => {
|
Step::StorageEmptyAssertion(storage_empty) => {
|
||||||
self.handle_storage_empty(metadata, case_idx, storage_empty, node)
|
self.handle_storage_empty(metadata, storage_empty, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to handle storage empty assertion step")?;
|
||||||
Ok(StepOutput::StorageEmptyAssertion)
|
Ok(StepOutput::StorageEmptyAssertion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.inspect(|_| info!("Step Succeeded"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", name = "Handling Input", skip_all)]
|
||||||
pub async fn handle_input(
|
pub async fn handle_input(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
case_idx: CaseIdx,
|
|
||||||
input: &Input,
|
input: &Input,
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
|
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
|
||||||
let deployment_receipts = self
|
let deployment_receipts = self
|
||||||
.handle_input_contract_deployment(metadata, case_idx, input, node)
|
.handle_input_contract_deployment(metadata, input, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed during contract deployment phase of input handling")?;
|
||||||
let execution_receipt = self
|
let execution_receipt = self
|
||||||
.handle_input_execution(input, deployment_receipts, node)
|
.handle_input_execution(input, deployment_receipts, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed during transaction execution phase of input handling")?;
|
||||||
let tracing_result = self
|
let tracing_result = self
|
||||||
.handle_input_call_frame_tracing(&execution_receipt, node)
|
.handle_input_call_frame_tracing(&execution_receipt, node)
|
||||||
.await?;
|
|
||||||
self.handle_input_variable_assignment(input, &tracing_result)?;
|
|
||||||
self.handle_input_expectations(input, &execution_receipt, node, &tracing_result)
|
|
||||||
.await?;
|
|
||||||
self.handle_input_diff(case_idx, execution_receipt, node)
|
|
||||||
.await
|
.await
|
||||||
|
.context("Failed during callframe tracing phase of input handling")?;
|
||||||
|
self.handle_input_variable_assignment(input, &tracing_result)
|
||||||
|
.context("Failed to assign variables from callframe output")?;
|
||||||
|
let (_, (geth_trace, diff_mode)) = try_join!(
|
||||||
|
self.handle_input_expectations(input, &execution_receipt, node, &tracing_result),
|
||||||
|
self.handle_input_diff(&execution_receipt, node)
|
||||||
|
)
|
||||||
|
.context("Failed while evaluating expectations and diffs in parallel")?;
|
||||||
|
Ok((execution_receipt, geth_trace, diff_mode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", name = "Handling Balance Assertion", skip_all)]
|
||||||
pub async fn handle_balance_assertion(
|
pub async fn handle_balance_assertion(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
_: CaseIdx,
|
|
||||||
balance_assertion: &BalanceAssertion,
|
balance_assertion: &BalanceAssertion,
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
self.handle_balance_assertion_contract_deployment(metadata, balance_assertion, node)
|
self.handle_balance_assertion_contract_deployment(metadata, balance_assertion, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to deploy contract for balance assertion")?;
|
||||||
self.handle_balance_assertion_execution(balance_assertion, node)
|
self.handle_balance_assertion_execution(balance_assertion, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to execute balance assertion")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", name = "Handling Storage Assertion", skip_all)]
|
||||||
pub async fn handle_storage_empty(
|
pub async fn handle_storage_empty(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
_: CaseIdx,
|
|
||||||
storage_empty: &StorageEmptyAssertion,
|
storage_empty: &StorageEmptyAssertion,
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
self.handle_storage_empty_assertion_contract_deployment(metadata, storage_empty, node)
|
self.handle_storage_empty_assertion_contract_deployment(metadata, storage_empty, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to deploy contract for storage empty assertion")?;
|
||||||
self.handle_storage_empty_assertion_execution(storage_empty, node)
|
self.handle_storage_empty_assertion_execution(storage_empty, node)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to execute storage empty assertion")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the contract deployment for a given input performing it if it needs to be performed.
|
/// Handles the contract deployment for a given input performing it if it needs to be performed.
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_contract_deployment(
|
async fn handle_input_contract_deployment(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
_: CaseIdx,
|
|
||||||
input: &Input,
|
input: &Input,
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<HashMap<ContractInstance, TransactionReceipt>> {
|
) -> anyhow::Result<HashMap<ContractInstance, TransactionReceipt>> {
|
||||||
@@ -170,11 +188,6 @@ where
|
|||||||
instances_we_must_deploy.insert(input.instance.clone(), true);
|
instances_we_must_deploy.insert(input.instance.clone(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::debug!(
|
|
||||||
instances_to_deploy = instances_we_must_deploy.len(),
|
|
||||||
"Computed the number of required deployments for input"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut receipts = HashMap::new();
|
let mut receipts = HashMap::new();
|
||||||
for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() {
|
for (instance, deploy_with_constructor_arguments) in instances_we_must_deploy.into_iter() {
|
||||||
let calldata = deploy_with_constructor_arguments.then_some(&input.calldata);
|
let calldata = deploy_with_constructor_arguments.then_some(&input.calldata);
|
||||||
@@ -191,7 +204,8 @@ where
|
|||||||
value,
|
value,
|
||||||
node,
|
node,
|
||||||
)
|
)
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get or deploy contract instance during input execution")?
|
||||||
{
|
{
|
||||||
receipts.insert(instance.clone(), receipt);
|
receipts.insert(instance.clone(), receipt);
|
||||||
}
|
}
|
||||||
@@ -201,6 +215,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the execution of the input in terms of the calls that need to be made.
|
/// Handles the execution of the input in terms of the calls that need to be made.
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_execution(
|
async fn handle_input_execution(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &Input,
|
input: &Input,
|
||||||
@@ -212,39 +227,27 @@ where
|
|||||||
// lookup the transaction receipt in this case and continue on.
|
// lookup the transaction receipt in this case and continue on.
|
||||||
Method::Deployer => deployment_receipts
|
Method::Deployer => deployment_receipts
|
||||||
.remove(&input.instance)
|
.remove(&input.instance)
|
||||||
.context("Failed to find deployment receipt"),
|
.context("Failed to find deployment receipt for constructor call"),
|
||||||
Method::Fallback | Method::FunctionName(_) => {
|
Method::Fallback | Method::FunctionName(_) => {
|
||||||
let tx = match input
|
let tx = match input
|
||||||
.legacy_transaction(node, self.default_resolution_context())
|
.legacy_transaction(node, self.default_resolution_context())
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(tx) => {
|
Ok(tx) => tx,
|
||||||
tracing::debug!("Legacy transaction data: {tx:#?}");
|
|
||||||
tx
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Failed to construct legacy transaction: {err:?}");
|
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::trace!("Executing transaction for input: {input:?}");
|
|
||||||
|
|
||||||
match node.execute_transaction(tx).await {
|
match node.execute_transaction(tx).await {
|
||||||
Ok(receipt) => Ok(receipt),
|
Ok(receipt) => Ok(receipt),
|
||||||
Err(err) => {
|
Err(err) => Err(err),
|
||||||
tracing::error!(
|
|
||||||
"Failed to execute transaction when executing the contract: {}, {:?}",
|
|
||||||
&*input.instance,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_call_frame_tracing(
|
async fn handle_input_call_frame_tracing(
|
||||||
&self,
|
&self,
|
||||||
execution_receipt: &TransactionReceipt,
|
execution_receipt: &TransactionReceipt,
|
||||||
@@ -259,7 +262,10 @@ where
|
|||||||
tracer_config: GethDebugTracerConfig(serde_json::json! {{
|
tracer_config: GethDebugTracerConfig(serde_json::json! {{
|
||||||
"onlyTopCall": true,
|
"onlyTopCall": true,
|
||||||
"withLog": false,
|
"withLog": false,
|
||||||
"withReturnData": false
|
"withStorage": false,
|
||||||
|
"withMemory": false,
|
||||||
|
"withStack": false,
|
||||||
|
"withReturnData": true
|
||||||
}}),
|
}}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
@@ -272,6 +278,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
fn handle_input_variable_assignment(
|
fn handle_input_variable_assignment(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &Input,
|
input: &Input,
|
||||||
@@ -302,8 +309,9 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_expectations(
|
async fn handle_input_expectations(
|
||||||
&mut self,
|
&self,
|
||||||
input: &Input,
|
input: &Input,
|
||||||
execution_receipt: &TransactionReceipt,
|
execution_receipt: &TransactionReceipt,
|
||||||
resolver: &impl ResolverApi,
|
resolver: &impl ResolverApi,
|
||||||
@@ -337,24 +345,25 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for expectation in expectations.iter() {
|
futures::stream::iter(expectations.into_iter().map(Ok))
|
||||||
|
.try_for_each_concurrent(None, |expectation| async move {
|
||||||
self.handle_input_expectation_item(
|
self.handle_input_expectation_item(
|
||||||
execution_receipt,
|
execution_receipt,
|
||||||
resolver,
|
resolver,
|
||||||
expectation,
|
expectation,
|
||||||
tracing_result,
|
tracing_result,
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
}
|
})
|
||||||
|
.await
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_expectation_item(
|
async fn handle_input_expectation_item(
|
||||||
&mut self,
|
&self,
|
||||||
execution_receipt: &TransactionReceipt,
|
execution_receipt: &TransactionReceipt,
|
||||||
resolver: &impl ResolverApi,
|
resolver: &impl ResolverApi,
|
||||||
expectation: &ExpectedOutput,
|
expectation: ExpectedOutput,
|
||||||
tracing_result: &CallFrame,
|
tracing_result: &CallFrame,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if let Some(ref version_requirement) = expectation.compiler_version {
|
if let Some(ref version_requirement) = expectation.compiler_version {
|
||||||
@@ -390,7 +399,8 @@ where
|
|||||||
let actual = &tracing_result.output.as_ref().unwrap_or_default();
|
let actual = &tracing_result.output.as_ref().unwrap_or_default();
|
||||||
if !expected
|
if !expected
|
||||||
.is_equivalent(actual, resolver, resolution_context)
|
.is_equivalent(actual, resolver, resolution_context)
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to resolve calldata equivalence for return data assertion")?
|
||||||
{
|
{
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
?execution_receipt,
|
?execution_receipt,
|
||||||
@@ -453,7 +463,8 @@ where
|
|||||||
let expected = Calldata::new_compound([expected]);
|
let expected = Calldata::new_compound([expected]);
|
||||||
if !expected
|
if !expected
|
||||||
.is_equivalent(&actual.0, resolver, resolution_context)
|
.is_equivalent(&actual.0, resolver, resolution_context)
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to resolve event topic equivalence")?
|
||||||
{
|
{
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
event_idx,
|
event_idx,
|
||||||
@@ -473,7 +484,8 @@ where
|
|||||||
let actual = &actual_event.data().data;
|
let actual = &actual_event.data().data;
|
||||||
if !expected
|
if !expected
|
||||||
.is_equivalent(&actual.0, resolver, resolution_context)
|
.is_equivalent(&actual.0, resolver, resolution_context)
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to resolve event value equivalence")?
|
||||||
{
|
{
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
event_idx,
|
event_idx,
|
||||||
@@ -492,12 +504,12 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
async fn handle_input_diff(
|
async fn handle_input_diff(
|
||||||
&mut self,
|
&self,
|
||||||
_: CaseIdx,
|
execution_receipt: &TransactionReceipt,
|
||||||
execution_receipt: TransactionReceipt,
|
|
||||||
node: &T::Blockchain,
|
node: &T::Blockchain,
|
||||||
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
|
) -> anyhow::Result<(GethTrace, DiffMode)> {
|
||||||
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
||||||
diff_mode: Some(true),
|
diff_mode: Some(true),
|
||||||
disable_code: None,
|
disable_code: None,
|
||||||
@@ -505,13 +517,18 @@ where
|
|||||||
});
|
});
|
||||||
|
|
||||||
let trace = node
|
let trace = node
|
||||||
.trace_transaction(&execution_receipt, trace_options)
|
.trace_transaction(execution_receipt, trace_options)
|
||||||
.await?;
|
.await
|
||||||
let diff = node.state_diff(&execution_receipt).await?;
|
.context("Failed to obtain geth prestate tracer output")?;
|
||||||
|
let diff = node
|
||||||
|
.state_diff(execution_receipt)
|
||||||
|
.await
|
||||||
|
.context("Failed to obtain state diff for transaction")?;
|
||||||
|
|
||||||
Ok((execution_receipt, trace, diff))
|
Ok((trace, diff))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
pub async fn handle_balance_assertion_contract_deployment(
|
pub async fn handle_balance_assertion_contract_deployment(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
@@ -537,6 +554,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
pub async fn handle_balance_assertion_execution(
|
pub async fn handle_balance_assertion_execution(
|
||||||
&mut self,
|
&mut self,
|
||||||
BalanceAssertion {
|
BalanceAssertion {
|
||||||
@@ -572,6 +590,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
pub async fn handle_storage_empty_assertion_contract_deployment(
|
pub async fn handle_storage_empty_assertion_contract_deployment(
|
||||||
&mut self,
|
&mut self,
|
||||||
metadata: &Metadata,
|
metadata: &Metadata,
|
||||||
@@ -597,6 +616,7 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all)]
|
||||||
pub async fn handle_storage_empty_assertion_execution(
|
pub async fn handle_storage_empty_assertion_execution(
|
||||||
&mut self,
|
&mut self,
|
||||||
StorageEmptyAssertion {
|
StorageEmptyAssertion {
|
||||||
@@ -658,7 +678,6 @@ where
|
|||||||
contract_ident,
|
contract_ident,
|
||||||
}) = metadata.contract_sources()?.remove(contract_instance)
|
}) = metadata.contract_sources()?.remove(contract_instance)
|
||||||
else {
|
else {
|
||||||
tracing::error!("Contract source not found for instance");
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Contract source not found for instance {:?}",
|
"Contract source not found for instance {:?}",
|
||||||
contract_instance
|
contract_instance
|
||||||
@@ -671,11 +690,6 @@ where
|
|||||||
.and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref()))
|
.and_then(|source_file_contracts| source_file_contracts.get(contract_ident.as_ref()))
|
||||||
.cloned()
|
.cloned()
|
||||||
else {
|
else {
|
||||||
tracing::error!(
|
|
||||||
contract_source_path = contract_source_path.display().to_string(),
|
|
||||||
contract_ident = contract_ident.as_ref(),
|
|
||||||
"Failed to find information for contract"
|
|
||||||
);
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"Failed to find information for contract {:?}",
|
"Failed to find information for contract {:?}",
|
||||||
contract_instance
|
contract_instance
|
||||||
@@ -724,7 +738,6 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let Some(address) = receipt.contract_address else {
|
let Some(address) = receipt.contract_address else {
|
||||||
tracing::error!("Contract deployment transaction didn't return an address");
|
|
||||||
anyhow::bail!("Contract deployment didn't return an address");
|
anyhow::bail!("Contract deployment didn't return an address");
|
||||||
};
|
};
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
@@ -732,6 +745,8 @@ where
|
|||||||
instance_address = ?address,
|
instance_address = ?address,
|
||||||
"Deployed contract"
|
"Deployed contract"
|
||||||
);
|
);
|
||||||
|
self.execution_reporter
|
||||||
|
.report_contract_deployed_event(contract_instance.clone(), address)?;
|
||||||
|
|
||||||
self.deployed_contracts.insert(
|
self.deployed_contracts.insert(
|
||||||
contract_instance.clone(),
|
contract_instance.clone(),
|
||||||
@@ -751,7 +766,6 @@ where
|
|||||||
pub struct CaseDriver<'a, Leader: Platform, Follower: Platform> {
|
pub struct CaseDriver<'a, Leader: Platform, Follower: Platform> {
|
||||||
metadata: &'a Metadata,
|
metadata: &'a Metadata,
|
||||||
case: &'a Case,
|
case: &'a Case,
|
||||||
case_idx: CaseIdx,
|
|
||||||
leader_node: &'a Leader::Blockchain,
|
leader_node: &'a Leader::Blockchain,
|
||||||
follower_node: &'a Follower::Blockchain,
|
follower_node: &'a Follower::Blockchain,
|
||||||
leader_state: CaseState<Leader>,
|
leader_state: CaseState<Leader>,
|
||||||
@@ -767,7 +781,6 @@ where
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
metadata: &'a Metadata,
|
metadata: &'a Metadata,
|
||||||
case: &'a Case,
|
case: &'a Case,
|
||||||
case_idx: impl Into<CaseIdx>,
|
|
||||||
leader_node: &'a L::Blockchain,
|
leader_node: &'a L::Blockchain,
|
||||||
follower_node: &'a F::Blockchain,
|
follower_node: &'a F::Blockchain,
|
||||||
leader_state: CaseState<L>,
|
leader_state: CaseState<L>,
|
||||||
@@ -776,7 +789,6 @@ where
|
|||||||
Self {
|
Self {
|
||||||
metadata,
|
metadata,
|
||||||
case,
|
case,
|
||||||
case_idx: case_idx.into(),
|
|
||||||
leader_node,
|
leader_node,
|
||||||
follower_node,
|
follower_node,
|
||||||
leader_state,
|
leader_state,
|
||||||
@@ -784,79 +796,44 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trace_diff_mode(label: &str, diff: &DiffMode) {
|
#[instrument(level = "info", name = "Executing Case", skip_all)]
|
||||||
tracing::trace!("{label} - PRE STATE:");
|
|
||||||
for (addr, state) in &diff.pre {
|
|
||||||
Self::trace_account_state(" [pre]", addr, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
tracing::trace!("{label} - POST STATE:");
|
|
||||||
for (addr, state) in &diff.post {
|
|
||||||
Self::trace_account_state(" [post]", addr, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn trace_account_state(prefix: &str, addr: &Address, state: &AccountState) {
|
|
||||||
tracing::trace!("{prefix} 0x{addr:x}");
|
|
||||||
|
|
||||||
if let Some(balance) = &state.balance {
|
|
||||||
tracing::trace!("{prefix} balance: {balance}");
|
|
||||||
}
|
|
||||||
if let Some(nonce) = &state.nonce {
|
|
||||||
tracing::trace!("{prefix} nonce: {nonce}");
|
|
||||||
}
|
|
||||||
if let Some(code) = &state.code {
|
|
||||||
tracing::trace!("{prefix} code: {code}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&mut self) -> anyhow::Result<usize> {
|
pub async fn execute(&mut self) -> anyhow::Result<usize> {
|
||||||
if !self
|
|
||||||
.leader_node
|
|
||||||
.matches_target(self.metadata.targets.as_deref())
|
|
||||||
|| !self
|
|
||||||
.follower_node
|
|
||||||
.matches_target(self.metadata.targets.as_deref())
|
|
||||||
{
|
|
||||||
tracing::warn!(
|
|
||||||
targets = ?self.metadata.targets,
|
|
||||||
"Either the leader or follower node do not support the targets of the file"
|
|
||||||
);
|
|
||||||
return Ok(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut steps_executed = 0;
|
let mut steps_executed = 0;
|
||||||
for (step_idx, step) in self.case.steps_iterator().enumerate() {
|
for (step_idx, step) in self
|
||||||
let tracing_span = tracing::info_span!("Handling input", step_idx);
|
.case
|
||||||
|
.steps_iterator()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(idx, v)| (StepIdx::new(idx), v))
|
||||||
|
{
|
||||||
|
let (leader_step_output, follower_step_output) = try_join!(
|
||||||
|
self.leader_state
|
||||||
|
.handle_step(self.metadata, &step, self.leader_node)
|
||||||
|
.instrument(info_span!(
|
||||||
|
"Handling Step",
|
||||||
|
%step_idx,
|
||||||
|
target = "Leader",
|
||||||
|
)),
|
||||||
|
self.follower_state
|
||||||
|
.handle_step(self.metadata, &step, self.follower_node)
|
||||||
|
.instrument(info_span!(
|
||||||
|
"Handling Step",
|
||||||
|
%step_idx,
|
||||||
|
target = "Follower",
|
||||||
|
))
|
||||||
|
)?;
|
||||||
|
|
||||||
let leader_step_output = self
|
|
||||||
.leader_state
|
|
||||||
.handle_step(self.metadata, self.case_idx, &step, self.leader_node)
|
|
||||||
.instrument(tracing_span.clone())
|
|
||||||
.await?;
|
|
||||||
let follower_step_output = self
|
|
||||||
.follower_state
|
|
||||||
.handle_step(self.metadata, self.case_idx, &step, self.follower_node)
|
|
||||||
.instrument(tracing_span)
|
|
||||||
.await?;
|
|
||||||
match (leader_step_output, follower_step_output) {
|
match (leader_step_output, follower_step_output) {
|
||||||
(
|
(StepOutput::FunctionCall(..), StepOutput::FunctionCall(..)) => {
|
||||||
StepOutput::FunctionCall(leader_receipt, _, leader_diff),
|
// TODO: We need to actually work out how/if we will compare the diff between
|
||||||
StepOutput::FunctionCall(follower_receipt, _, follower_diff),
|
// the leader and the follower. The diffs are almost guaranteed to be different
|
||||||
) => {
|
// from leader and follower and therefore without an actual strategy for this
|
||||||
if leader_diff == follower_diff {
|
// we have something that's guaranteed to fail. Even a simple call to some
|
||||||
tracing::debug!("State diffs match between leader and follower.");
|
// contract will produce two non-equal diffs because on the leader the contract
|
||||||
} else {
|
// has address X and on the follower it has address Y. On the leader contract X
|
||||||
tracing::debug!("State diffs mismatch between leader and follower.");
|
// contains address A in the state and on the follower it contains address B. So
|
||||||
Self::trace_diff_mode("Leader", &leader_diff);
|
// this isn't exactly a straightforward thing to do and I'm not even sure that
|
||||||
Self::trace_diff_mode("Follower", &follower_diff);
|
// it's possible to do. Once we have an actual strategy for doing the diffs we
|
||||||
}
|
// will implement it here. Until then, this remains empty.
|
||||||
|
|
||||||
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::BalanceAssertion, StepOutput::BalanceAssertion) => {}
|
||||||
(StepOutput::StorageEmptyAssertion, StepOutput::StorageEmptyAssertion) => {}
|
(StepOutput::StorageEmptyAssertion, StepOutput::StorageEmptyAssertion) => {}
|
||||||
|
|||||||
+623
-301
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ alloy = { workspace = true }
|
|||||||
alloy-primitives = { workspace = true }
|
alloy-primitives = { workspace = true }
|
||||||
alloy-sol-types = { workspace = true }
|
alloy-sol-types = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
futures = { workspace = true }
|
||||||
regex = { workspace = true }
|
regex = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
@@ -25,3 +26,6 @@ serde_json = { workspace = true }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use revive_dt_common::macros::define_wrapper_type;
|
use revive_dt_common::{macros::define_wrapper_type, types::Mode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
input::{Expected, Step},
|
input::{Expected, Step},
|
||||||
@@ -60,16 +60,18 @@ impl Case {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn solc_modes(&self) -> Vec<Mode> {
|
||||||
|
match &self.modes {
|
||||||
|
Some(modes) => ParsedMode::many_to_modes(modes.iter()).collect(),
|
||||||
|
None => Mode::all().collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define_wrapper_type!(
|
define_wrapper_type!(
|
||||||
/// A wrapper type for the index of test cases found in metadata file.
|
/// A wrapper type for the index of test cases found in metadata file.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
pub struct CaseIdx(usize);
|
#[serde(transparent)]
|
||||||
|
pub struct CaseIdx(usize) impl Display, FromStr;
|
||||||
);
|
);
|
||||||
|
|
||||||
impl std::fmt::Display for CaseIdx {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+70
-69
@@ -3,10 +3,12 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use revive_dt_common::cached_fs::read_dir;
|
use revive_dt_common::iterators::FilesWithExtensionIterator;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::metadata::MetadataFile;
|
use crate::metadata::{Metadata, MetadataFile};
|
||||||
|
use anyhow::Context as _;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
@@ -18,34 +20,77 @@ pub enum Corpus {
|
|||||||
impl Corpus {
|
impl Corpus {
|
||||||
pub fn try_from_path(file_path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
pub fn try_from_path(file_path: impl AsRef<Path>) -> anyhow::Result<Self> {
|
||||||
let mut corpus = File::open(file_path.as_ref())
|
let mut corpus = File::open(file_path.as_ref())
|
||||||
.map_err(Into::<anyhow::Error>::into)
|
.map_err(anyhow::Error::from)
|
||||||
.and_then(|file| serde_json::from_reader::<_, Corpus>(file).map_err(Into::into))?;
|
.and_then(|file| serde_json::from_reader::<_, Corpus>(file).map_err(Into::into))
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to open and deserialize corpus file at {}",
|
||||||
|
file_path.as_ref().display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let corpus_directory = file_path
|
||||||
|
.as_ref()
|
||||||
|
.canonicalize()
|
||||||
|
.context("Failed to canonicalize the path to the corpus file")?
|
||||||
|
.parent()
|
||||||
|
.context("Corpus file has no parent")?
|
||||||
|
.to_path_buf();
|
||||||
|
|
||||||
for path in corpus.paths_iter_mut() {
|
for path in corpus.paths_iter_mut() {
|
||||||
*path = file_path
|
*path = corpus_directory.join(path.as_path())
|
||||||
.as_ref()
|
|
||||||
.parent()
|
|
||||||
.ok_or_else(|| {
|
|
||||||
anyhow::anyhow!("Corpus path '{}' does not point to a file", path.display())
|
|
||||||
})?
|
|
||||||
.canonicalize()
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"Failed to canonicalize path to corpus '{}': {error}",
|
|
||||||
path.display()
|
|
||||||
)
|
|
||||||
})?
|
|
||||||
.join(path.as_path())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(corpus)
|
Ok(corpus)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enumerate_tests(&self) -> Vec<MetadataFile> {
|
pub fn enumerate_tests(&self) -> Vec<MetadataFile> {
|
||||||
let mut tests = Vec::new();
|
let mut tests = self
|
||||||
for path in self.paths_iter() {
|
.paths_iter()
|
||||||
collect_metadata(path, &mut tests);
|
.flat_map(|root_path| {
|
||||||
|
if !root_path.is_dir() {
|
||||||
|
Box::new(std::iter::once(root_path.to_path_buf()))
|
||||||
|
as Box<dyn Iterator<Item = _>>
|
||||||
|
} else {
|
||||||
|
Box::new(
|
||||||
|
FilesWithExtensionIterator::new(root_path)
|
||||||
|
.with_use_cached_fs(true)
|
||||||
|
.with_allowed_extension("sol")
|
||||||
|
.with_allowed_extension("json"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
.map(move |metadata_file_path| (root_path, metadata_file_path))
|
||||||
|
})
|
||||||
|
.filter_map(|(root_path, metadata_file_path)| {
|
||||||
|
Metadata::try_from_file(&metadata_file_path)
|
||||||
|
.or_else(|| {
|
||||||
|
debug!(
|
||||||
|
discovered_from = %root_path.display(),
|
||||||
|
metadata_file_path = %metadata_file_path.display(),
|
||||||
|
"Skipping file since it doesn't contain valid metadata"
|
||||||
|
);
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.map(|metadata| MetadataFile {
|
||||||
|
metadata_file_path,
|
||||||
|
corpus_file_path: root_path.to_path_buf(),
|
||||||
|
content: metadata,
|
||||||
|
})
|
||||||
|
.inspect(|metadata_file| {
|
||||||
|
debug!(
|
||||||
|
metadata_file_path = %metadata_file.relative_path().display(),
|
||||||
|
"Loaded metadata file"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
tests.sort_by(|a, b| a.metadata_file_path.cmp(&b.metadata_file_path));
|
||||||
|
tests.dedup_by(|a, b| a.metadata_file_path == b.metadata_file_path);
|
||||||
|
info!(
|
||||||
|
len = tests.len(),
|
||||||
|
corpus_name = self.name(),
|
||||||
|
"Found tests in Corpus"
|
||||||
|
);
|
||||||
tests
|
tests
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,55 +121,11 @@ impl Corpus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Recursively walks `path` and parses any JSON or Solidity file into a test
|
pub fn path_count(&self) -> usize {
|
||||||
/// definition [Metadata].
|
match self {
|
||||||
///
|
Corpus::SinglePath { .. } => 1,
|
||||||
/// Found tests are inserted into `tests`.
|
Corpus::MultiplePaths { paths, .. } => paths.len(),
|
||||||
///
|
|
||||||
/// `path` is expected to be a directory.
|
|
||||||
pub fn collect_metadata(path: &Path, tests: &mut Vec<MetadataFile>) {
|
|
||||||
if path.is_dir() {
|
|
||||||
let dir_entry = match read_dir(path) {
|
|
||||||
Ok(dir_entry) => dir_entry,
|
|
||||||
Err(error) => {
|
|
||||||
tracing::error!("failed to read dir '{}': {error}", path.display());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for path in dir_entry {
|
|
||||||
let path = match path {
|
|
||||||
Ok(entry) => entry,
|
|
||||||
Err(error) => {
|
|
||||||
tracing::error!("error reading dir entry: {error}");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if path.is_dir() {
|
|
||||||
collect_metadata(&path, tests);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.is_file() {
|
|
||||||
if let Some(metadata) = MetadataFile::try_from_file(&path) {
|
|
||||||
tests.push(metadata)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let Some(extension) = path.extension() else {
|
|
||||||
tracing::error!("Failed to get file extension");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if extension.eq_ignore_ascii_case("sol") || extension.eq_ignore_ascii_case("json") {
|
|
||||||
if let Some(metadata) = MetadataFile::try_from_file(path) {
|
|
||||||
tests.push(metadata)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tracing::error!(?extension, "Unsupported file extension");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-53
@@ -2,7 +2,6 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use alloy::{
|
use alloy::{
|
||||||
eips::BlockNumberOrTag,
|
eips::BlockNumberOrTag,
|
||||||
hex::ToHexExt,
|
|
||||||
json_abi::Function,
|
json_abi::Function,
|
||||||
network::TransactionBuilder,
|
network::TransactionBuilder,
|
||||||
primitives::{Address, Bytes, U256},
|
primitives::{Address, Bytes, U256},
|
||||||
@@ -10,10 +9,12 @@ use alloy::{
|
|||||||
};
|
};
|
||||||
use alloy_primitives::{FixedBytes, utils::parse_units};
|
use alloy_primitives::{FixedBytes, utils::parse_units};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream};
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use revive_dt_common::macros::define_wrapper_type;
|
use revive_dt_common::macros::define_wrapper_type;
|
||||||
|
use tracing::{Instrument, info_span, instrument};
|
||||||
|
|
||||||
use crate::traits::ResolverApi;
|
use crate::traits::ResolverApi;
|
||||||
use crate::{metadata::ContractInstance, traits::ResolutionContext};
|
use crate::{metadata::ContractInstance, traits::ResolutionContext};
|
||||||
@@ -33,6 +34,11 @@ pub enum Step {
|
|||||||
StorageEmptyAssertion(Box<StorageEmptyAssertion>),
|
StorageEmptyAssertion(Box<StorageEmptyAssertion>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define_wrapper_type!(
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct StepIdx(usize) impl Display;
|
||||||
|
);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
#[serde(default = "Input::default_caller")]
|
#[serde(default = "Input::default_caller")]
|
||||||
@@ -188,7 +194,7 @@ define_wrapper_type! {
|
|||||||
/// This represents an item in the [`Calldata::Compound`] variant.
|
/// This represents an item in the [`Calldata::Compound`] variant.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct CalldataItem(String);
|
pub struct CalldataItem(String) impl Display;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
@@ -233,7 +239,7 @@ pub enum Method {
|
|||||||
|
|
||||||
define_wrapper_type!(
|
define_wrapper_type!(
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct EtherValue(U256);
|
pub struct EtherValue(U256) impl Display;
|
||||||
);
|
);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||||
@@ -262,28 +268,27 @@ impl Input {
|
|||||||
) -> anyhow::Result<Bytes> {
|
) -> anyhow::Result<Bytes> {
|
||||||
match self.method {
|
match self.method {
|
||||||
Method::Deployer | Method::Fallback => {
|
Method::Deployer | Method::Fallback => {
|
||||||
let calldata = self.calldata.calldata(resolver, context).await?;
|
let calldata = self
|
||||||
|
.calldata
|
||||||
|
.calldata(resolver, context)
|
||||||
|
.await
|
||||||
|
.context("Failed to produce calldata for deployer/fallback method")?;
|
||||||
|
|
||||||
Ok(calldata.into())
|
Ok(calldata.into())
|
||||||
}
|
}
|
||||||
Method::FunctionName(ref function_name) => {
|
Method::FunctionName(ref function_name) => {
|
||||||
let Some(abi) = context.deployed_contract_abi(&self.instance) else {
|
let Some(abi) = context.deployed_contract_abi(&self.instance) else {
|
||||||
tracing::error!(
|
|
||||||
contract_name = self.instance.as_ref(),
|
|
||||||
"Attempted to lookup ABI of contract but it wasn't found"
|
|
||||||
);
|
|
||||||
anyhow::bail!("ABI for instance '{}' not found", self.instance.as_ref());
|
anyhow::bail!("ABI for instance '{}' not found", self.instance.as_ref());
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::trace!("ABI found for instance: {}", &self.instance.as_ref());
|
|
||||||
|
|
||||||
// We follow the same logic that's implemented in the matter-labs-tester where they resolve
|
// We follow the same logic that's implemented in the matter-labs-tester where they resolve
|
||||||
// the function name into a function selector and they assume that he function doesn't have
|
// the function name into a function selector and they assume that he function doesn't have
|
||||||
// any existing overloads.
|
// any existing overloads.
|
||||||
// Overloads are handled by providing the full function signature in the "function
|
// Overloads are handled by providing the full function signature in the "function
|
||||||
// name".
|
// name".
|
||||||
// https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190
|
// https://github.com/matter-labs/era-compiler-tester/blob/1dfa7d07cba0734ca97e24704f12dd57f6990c2c/compiler_tester/src/test/case/input/mod.rs#L158-L190
|
||||||
let selector = if function_name.contains('(') && function_name.contains(')') {
|
let selector =
|
||||||
|
if function_name.contains('(') && function_name.contains(')') {
|
||||||
Function::parse(function_name)
|
Function::parse(function_name)
|
||||||
.context(
|
.context(
|
||||||
"Failed to parse the provided function name into a function signature",
|
"Failed to parse the provided function name into a function signature",
|
||||||
@@ -298,17 +303,14 @@ impl Input {
|
|||||||
function_name,
|
function_name,
|
||||||
&self.instance
|
&self.instance
|
||||||
)
|
)
|
||||||
})?
|
})
|
||||||
|
.with_context(|| format!(
|
||||||
|
"Failed to resolve function selector for {:?} on instance {:?}",
|
||||||
|
function_name, &self.instance
|
||||||
|
))?
|
||||||
.selector()
|
.selector()
|
||||||
};
|
};
|
||||||
|
|
||||||
tracing::trace!("Functions found for instance: {}", self.instance.as_ref());
|
|
||||||
|
|
||||||
tracing::trace!(
|
|
||||||
"Starting encoding ABI's parameters for instance: {}",
|
|
||||||
self.instance.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Allocating a vector that we will be using for the calldata. The vector size will be:
|
// Allocating a vector that we will be using for the calldata. The vector size will be:
|
||||||
// 4 bytes for the function selector.
|
// 4 bytes for the function selector.
|
||||||
// function.inputs.len() * 32 bytes for the arguments (each argument is a U256).
|
// function.inputs.len() * 32 bytes for the arguments (each argument is a U256).
|
||||||
@@ -319,7 +321,8 @@ impl Input {
|
|||||||
calldata.extend(selector.0);
|
calldata.extend(selector.0);
|
||||||
self.calldata
|
self.calldata
|
||||||
.calldata_into_slice(&mut calldata, resolver, context)
|
.calldata_into_slice(&mut calldata, resolver, context)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to append encoded argument to calldata buffer")?;
|
||||||
|
|
||||||
Ok(calldata.into())
|
Ok(calldata.into())
|
||||||
}
|
}
|
||||||
@@ -332,7 +335,10 @@ impl Input {
|
|||||||
resolver: &impl ResolverApi,
|
resolver: &impl ResolverApi,
|
||||||
context: ResolutionContext<'_>,
|
context: ResolutionContext<'_>,
|
||||||
) -> anyhow::Result<TransactionRequest> {
|
) -> anyhow::Result<TransactionRequest> {
|
||||||
let input_data = self.encoded_input(resolver, context).await?;
|
let input_data = self
|
||||||
|
.encoded_input(resolver, context)
|
||||||
|
.await
|
||||||
|
.context("Failed to encode input bytes for transaction request")?;
|
||||||
let transaction_request = TransactionRequest::default().from(self.caller).value(
|
let transaction_request = TransactionRequest::default().from(self.caller).value(
|
||||||
self.value
|
self.value
|
||||||
.map(|value| value.into_inner())
|
.map(|value| value.into_inner())
|
||||||
@@ -435,17 +441,19 @@ impl Calldata {
|
|||||||
buffer.extend_from_slice(bytes);
|
buffer.extend_from_slice(bytes);
|
||||||
}
|
}
|
||||||
Calldata::Compound(items) => {
|
Calldata::Compound(items) => {
|
||||||
for (arg_idx, arg) in items.iter().enumerate() {
|
let resolved = stream::iter(items.iter().enumerate())
|
||||||
match arg.resolve(resolver, context).await {
|
.map(|(arg_idx, arg)| async move {
|
||||||
Ok(resolved) => {
|
arg.resolve(resolver, context)
|
||||||
buffer.extend(resolved.to_be_bytes::<32>());
|
.instrument(info_span!("Resolving argument", %arg, arg_idx))
|
||||||
}
|
.map_ok(|value| value.to_be_bytes::<32>())
|
||||||
Err(error) => {
|
.await
|
||||||
tracing::error!(?arg, arg_idx, ?error, "Failed to resolve argument");
|
})
|
||||||
return Err(error);
|
.buffered(0xFF)
|
||||||
}
|
.try_collect::<Vec<_>>()
|
||||||
};
|
.await
|
||||||
}
|
.context("Failed to resolve one or more calldata arguments")?;
|
||||||
|
|
||||||
|
buffer.extend(resolved.into_iter().flatten());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -468,13 +476,12 @@ impl Calldata {
|
|||||||
match self {
|
match self {
|
||||||
Calldata::Single(calldata) => Ok(calldata == other),
|
Calldata::Single(calldata) => Ok(calldata == other),
|
||||||
Calldata::Compound(items) => {
|
Calldata::Compound(items) => {
|
||||||
// Chunking the "other" calldata into 32 byte chunks since each
|
stream::iter(items.iter().zip(other.chunks(32)))
|
||||||
// one of the items in the compound calldata represents 32 bytes
|
.map(|(this, other)| async move {
|
||||||
for (this, other) in items.iter().zip(other.chunks(32)) {
|
|
||||||
// The matterlabs format supports wildcards and therefore we
|
// The matterlabs format supports wildcards and therefore we
|
||||||
// also need to support them.
|
// also need to support them.
|
||||||
if this.as_ref() == "*" {
|
if this.as_ref() == "*" {
|
||||||
continue;
|
return Ok::<_, anyhow::Error>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let other = if other.len() < 32 {
|
let other = if other.len() < 32 {
|
||||||
@@ -485,19 +492,24 @@ impl Calldata {
|
|||||||
std::borrow::Cow::Borrowed(other)
|
std::borrow::Cow::Borrowed(other)
|
||||||
};
|
};
|
||||||
|
|
||||||
let this = this.resolve(resolver, context).await?;
|
let this = this
|
||||||
|
.resolve(resolver, context)
|
||||||
|
.await
|
||||||
|
.context("Failed to resolve calldata item during equivalence check")?;
|
||||||
let other = U256::from_be_slice(&other);
|
let other = U256::from_be_slice(&other);
|
||||||
if this != other {
|
Ok(this == other)
|
||||||
return Ok(false);
|
})
|
||||||
}
|
.buffered(0xFF)
|
||||||
}
|
.all(|v| async move { v.is_ok_and(|v| v) })
|
||||||
Ok(true)
|
.map(Ok)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CalldataItem {
|
impl CalldataItem {
|
||||||
|
#[instrument(level = "info", skip_all, err)]
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
&self,
|
&self,
|
||||||
resolver: &impl ResolverApi,
|
resolver: &impl ResolverApi,
|
||||||
@@ -548,14 +560,7 @@ impl CalldataItem {
|
|||||||
match stack.as_slice() {
|
match stack.as_slice() {
|
||||||
// Empty stack means that we got an empty compound calldata which we resolve to zero.
|
// Empty stack means that we got an empty compound calldata which we resolve to zero.
|
||||||
[] => Ok(U256::ZERO),
|
[] => Ok(U256::ZERO),
|
||||||
[CalldataToken::Item(item)] => {
|
[CalldataToken::Item(item)] => Ok(*item),
|
||||||
tracing::debug!(
|
|
||||||
original = self.0,
|
|
||||||
resolved = item.to_be_bytes::<32>().encode_hex(),
|
|
||||||
"Resolved a Calldata item"
|
|
||||||
);
|
|
||||||
Ok(*item)
|
|
||||||
}
|
|
||||||
_ => Err(anyhow::anyhow!(
|
_ => Err(anyhow::anyhow!(
|
||||||
"Invalid calldata arithmetic operation - Invalid stack"
|
"Invalid calldata arithmetic operation - Invalid stack"
|
||||||
)),
|
)),
|
||||||
@@ -676,17 +681,24 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
|||||||
|
|
||||||
let current_block_number = match context.tip_block_number() {
|
let current_block_number = match context.tip_block_number() {
|
||||||
Some(block_number) => *block_number,
|
Some(block_number) => *block_number,
|
||||||
None => resolver.last_block_number().await?,
|
None => resolver.last_block_number().await.context(
|
||||||
|
"Failed to query last block number while resolving $BLOCK_HASH",
|
||||||
|
)?,
|
||||||
};
|
};
|
||||||
let desired_block_number = current_block_number.saturating_sub(offset);
|
let desired_block_number = current_block_number.saturating_sub(offset);
|
||||||
|
|
||||||
let block_hash = resolver.block_hash(desired_block_number.into()).await?;
|
let block_hash = resolver
|
||||||
|
.block_hash(desired_block_number.into())
|
||||||
|
.await
|
||||||
|
.context("Failed to resolve block hash for desired block number")?;
|
||||||
|
|
||||||
Ok(U256::from_be_bytes(block_hash.0))
|
Ok(U256::from_be_bytes(block_hash.0))
|
||||||
} else if item == Self::BLOCK_NUMBER_VARIABLE {
|
} else if item == Self::BLOCK_NUMBER_VARIABLE {
|
||||||
let current_block_number = match context.tip_block_number() {
|
let current_block_number = match context.tip_block_number() {
|
||||||
Some(block_number) => *block_number,
|
Some(block_number) => *block_number,
|
||||||
None => resolver.last_block_number().await?,
|
None => resolver.last_block_number().await.context(
|
||||||
|
"Failed to query last block number while resolving $BLOCK_NUMBER",
|
||||||
|
)?,
|
||||||
};
|
};
|
||||||
Ok(U256::from(current_block_number))
|
Ok(U256::from(current_block_number))
|
||||||
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
|
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use revive_dt_common::{
|
|||||||
cached_fs::read_to_string, iterators::FilesWithExtensionIterator, macros::define_wrapper_type,
|
cached_fs::read_to_string, iterators::FilesWithExtensionIterator, macros::define_wrapper_type,
|
||||||
types::Mode,
|
types::Mode,
|
||||||
};
|
};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{case::Case, mode::ParsedMode};
|
use crate::{case::Case, mode::ParsedMode};
|
||||||
|
|
||||||
@@ -24,16 +25,26 @@ pub const SOLIDITY_CASE_COMMENT_MARKER: &str = "//!";
|
|||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
|
#[derive(Debug, Default, Deserialize, Clone, Eq, PartialEq)]
|
||||||
pub struct MetadataFile {
|
pub struct MetadataFile {
|
||||||
pub path: PathBuf,
|
/// The path of the metadata file. This will either be a JSON or solidity file.
|
||||||
|
pub metadata_file_path: PathBuf,
|
||||||
|
|
||||||
|
/// This is the path contained within the corpus file. This could either be the path of some dir
|
||||||
|
/// or could be the actual metadata file path.
|
||||||
|
pub corpus_file_path: PathBuf,
|
||||||
|
|
||||||
|
/// The metadata contained within the file.
|
||||||
pub content: Metadata,
|
pub content: Metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetadataFile {
|
impl MetadataFile {
|
||||||
pub fn try_from_file(path: &Path) -> Option<Self> {
|
pub fn relative_path(&self) -> &Path {
|
||||||
Metadata::try_from_file(path).map(|metadata| Self {
|
if self.corpus_file_path.is_file() {
|
||||||
path: path.to_owned(),
|
&self.corpus_file_path
|
||||||
content: metadata,
|
} else {
|
||||||
})
|
self.metadata_file_path
|
||||||
|
.strip_prefix(&self.corpus_file_path)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +132,15 @@ impl Metadata {
|
|||||||
) in contracts
|
) in contracts
|
||||||
{
|
{
|
||||||
let alias = alias.clone();
|
let alias = alias.clone();
|
||||||
let absolute_path = directory.join(contract_source_path).canonicalize()?;
|
let absolute_path = directory
|
||||||
|
.join(contract_source_path)
|
||||||
|
.canonicalize()
|
||||||
|
.map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"Failed to canonicalize contract source path '{}': {error}",
|
||||||
|
directory.join(contract_source_path).display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
let contract_ident = contract_ident.clone();
|
let contract_ident = contract_ident.clone();
|
||||||
|
|
||||||
sources.insert(
|
sources.insert(
|
||||||
@@ -145,10 +164,7 @@ impl Metadata {
|
|||||||
pub fn try_from_file(path: &Path) -> Option<Self> {
|
pub fn try_from_file(path: &Path) -> Option<Self> {
|
||||||
assert!(path.is_file(), "not a file: {}", path.display());
|
assert!(path.is_file(), "not a file: {}", path.display());
|
||||||
|
|
||||||
let Some(file_extension) = path.extension() else {
|
let file_extension = path.extension()?;
|
||||||
tracing::debug!("skipping corpus file: {}", path.display());
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
if file_extension == METADATA_FILE_EXTENSION {
|
if file_extension == METADATA_FILE_EXTENSION {
|
||||||
return Self::try_from_json(path);
|
return Self::try_from_json(path);
|
||||||
@@ -158,18 +174,12 @@ impl Metadata {
|
|||||||
return Self::try_from_solidity(path);
|
return Self::try_from_solidity(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::debug!("ignoring invalid corpus file: {}", path.display());
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_from_json(path: &Path) -> Option<Self> {
|
fn try_from_json(path: &Path) -> Option<Self> {
|
||||||
let file = File::open(path)
|
let file = File::open(path)
|
||||||
.inspect_err(|error| {
|
.inspect_err(|err| error!(path = %path.display(), %err, "Failed to open file"))
|
||||||
tracing::error!(
|
|
||||||
"opening JSON test metadata file '{}' error: {error}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
match serde_json::from_reader::<_, Metadata>(file) {
|
match serde_json::from_reader::<_, Metadata>(file) {
|
||||||
@@ -177,11 +187,8 @@ impl Metadata {
|
|||||||
metadata.file_path = Some(path.to_path_buf());
|
metadata.file_path = Some(path.to_path_buf());
|
||||||
Some(metadata)
|
Some(metadata)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(err) => {
|
||||||
tracing::error!(
|
error!(path = %path.display(), %err, "Deserialization of metadata failed");
|
||||||
"parsing JSON test metadata file '{}' error: {error}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,12 +196,7 @@ impl Metadata {
|
|||||||
|
|
||||||
fn try_from_solidity(path: &Path) -> Option<Self> {
|
fn try_from_solidity(path: &Path) -> Option<Self> {
|
||||||
let spec = read_to_string(path)
|
let spec = read_to_string(path)
|
||||||
.inspect_err(|error| {
|
.inspect_err(|err| error!(path = %path.display(), %err, "Failed to read file content"))
|
||||||
tracing::error!(
|
|
||||||
"opening JSON test metadata file '{}' error: {error}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.ok()?
|
.ok()?
|
||||||
.lines()
|
.lines()
|
||||||
.filter_map(|line| line.strip_prefix(SOLIDITY_CASE_COMMENT_MARKER))
|
.filter_map(|line| line.strip_prefix(SOLIDITY_CASE_COMMENT_MARKER))
|
||||||
@@ -222,11 +224,8 @@ impl Metadata {
|
|||||||
);
|
);
|
||||||
Some(metadata)
|
Some(metadata)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(err) => {
|
||||||
tracing::error!(
|
error!(path = %path.display(), %err, "Failed to deserialize metadata");
|
||||||
"parsing Solidity test metadata file '{}' error: '{error}' from data: {spec}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +265,7 @@ define_wrapper_type!(
|
|||||||
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
||||||
)]
|
)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct ContractInstance(String);
|
pub struct ContractInstance(String) impl Display;
|
||||||
);
|
);
|
||||||
|
|
||||||
define_wrapper_type!(
|
define_wrapper_type!(
|
||||||
@@ -277,7 +276,7 @@ define_wrapper_type!(
|
|||||||
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
|
||||||
)]
|
)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct ContractIdent(String);
|
pub struct ContractIdent(String) impl Display;
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Represents an identifier used for contracts.
|
/// Represents an identifier used for contracts.
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use anyhow::Context;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
use revive_dt_common::types::{Mode, ModeOptimizerSetting, ModePipeline};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -44,21 +45,34 @@ impl FromStr for ParsedMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let pipeline = match caps.name("pipeline") {
|
let pipeline = match caps.name("pipeline") {
|
||||||
Some(m) => Some(ModePipeline::from_str(m.as_str())?),
|
Some(m) => Some(
|
||||||
|
ModePipeline::from_str(m.as_str())
|
||||||
|
.context("Failed to parse mode pipeline from string")?,
|
||||||
|
),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let optimize_flag = caps.name("optimize_flag").map(|m| m.as_str() == "+");
|
let optimize_flag = caps.name("optimize_flag").map(|m| m.as_str() == "+");
|
||||||
|
|
||||||
let optimize_setting = match caps.name("optimize_setting") {
|
let optimize_setting = match caps.name("optimize_setting") {
|
||||||
Some(m) => Some(ModeOptimizerSetting::from_str(m.as_str())?),
|
Some(m) => Some(
|
||||||
|
ModeOptimizerSetting::from_str(m.as_str())
|
||||||
|
.context("Failed to parse optimizer setting from string")?,
|
||||||
|
),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let version = match caps.name("version") {
|
let version = match caps.name("version") {
|
||||||
Some(m) => Some(semver::VersionReq::parse(m.as_str()).map_err(|e| {
|
Some(m) => Some(
|
||||||
anyhow::anyhow!("Cannot parse the version requirement '{}': {e}", m.as_str())
|
semver::VersionReq::parse(m.as_str())
|
||||||
})?),
|
.map_err(|e| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"Cannot parse the version requirement '{}': {e}",
|
||||||
|
m.as_str()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.context("Failed to parse semver requirement from mode string")?,
|
||||||
|
),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -223,7 +237,7 @@ mod tests {
|
|||||||
|
|
||||||
for (actual, expected) in strings {
|
for (actual, expected) in strings {
|
||||||
let parsed = ParsedMode::from_str(actual)
|
let parsed = ParsedMode::from_str(actual)
|
||||||
.expect(format!("Failed to parse mode string '{actual}'").as_str());
|
.unwrap_or_else(|_| panic!("Failed to parse mode string '{actual}'"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected,
|
expected,
|
||||||
parsed.to_string(),
|
parsed.to_string(),
|
||||||
@@ -249,7 +263,7 @@ mod tests {
|
|||||||
|
|
||||||
for (actual, expected) in strings {
|
for (actual, expected) in strings {
|
||||||
let parsed = ParsedMode::from_str(actual)
|
let parsed = ParsedMode::from_str(actual)
|
||||||
.expect(format!("Failed to parse mode string '{actual}'").as_str());
|
.unwrap_or_else(|_| panic!("Failed to parse mode string '{actual}'"));
|
||||||
let expected_set: HashSet<_> = expected.into_iter().map(|s| s.to_owned()).collect();
|
let expected_set: HashSet<_> = expected.into_iter().map(|s| s.to_owned()).collect();
|
||||||
let actual_set: HashSet<_> = parsed.to_modes().map(|m| m.to_string()).collect();
|
let actual_set: HashSet<_> = parsed.to_modes().map(|m| m.to_string()).collect();
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,6 @@ rust-version.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
alloy = { workspace = true }
|
alloy = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -27,5 +27,8 @@ sp-core = { workspace = true }
|
|||||||
sp-runtime = { workspace = true }
|
sp-runtime = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
temp-dir = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
+177
-113
@@ -33,9 +33,12 @@ use alloy::{
|
|||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use revive_common::EVMVersion;
|
use revive_common::EVMVersion;
|
||||||
use tracing::{Instrument, Level};
|
use tracing::{Instrument, instrument};
|
||||||
|
|
||||||
use revive_dt_common::{fs::clear_directory, futures::poll};
|
use revive_dt_common::{
|
||||||
|
fs::clear_directory,
|
||||||
|
futures::{PollingWaitBehavior, poll},
|
||||||
|
};
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_dt_format::traits::ResolverApi;
|
use revive_dt_format::traits::ResolverApi;
|
||||||
use revive_dt_node_interaction::EthereumNode;
|
use revive_dt_node_interaction::EthereumNode;
|
||||||
@@ -52,6 +55,7 @@ static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
|||||||
///
|
///
|
||||||
/// Prunes the child process and the base directory on drop.
|
/// Prunes the child process and the base directory on drop.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
pub struct GethNode {
|
pub struct GethNode {
|
||||||
connection_string: String,
|
connection_string: String,
|
||||||
base_directory: PathBuf,
|
base_directory: PathBuf,
|
||||||
@@ -61,8 +65,9 @@ pub struct GethNode {
|
|||||||
id: u32,
|
id: u32,
|
||||||
handle: Option<Child>,
|
handle: Option<Child>,
|
||||||
start_timeout: u64,
|
start_timeout: u64,
|
||||||
wallet: EthereumWallet,
|
wallet: Arc<EthereumWallet>,
|
||||||
nonce_manager: CachedNonceManager,
|
nonce_manager: CachedNonceManager,
|
||||||
|
chain_id_filler: ChainIdFiller,
|
||||||
/// This vector stores [`File`] objects that we use for logging which we want to flush when the
|
/// This vector stores [`File`] objects that we use for logging which we want to flush when the
|
||||||
/// node object is dropped. We do not store them in a structured fashion at the moment (in
|
/// node object is dropped. We do not store them in a structured fashion at the moment (in
|
||||||
/// separate fields) as the logic that we need to apply to them is all the same regardless of
|
/// separate fields) as the logic that we need to apply to them is all the same regardless of
|
||||||
@@ -91,15 +96,18 @@ impl GethNode {
|
|||||||
const TRACE_POLLING_DURATION: Duration = Duration::from_secs(60);
|
const TRACE_POLLING_DURATION: Duration = Duration::from_secs(60);
|
||||||
|
|
||||||
/// Create the node directory and call `geth init` to configure the genesis.
|
/// Create the node directory and call `geth init` to configure the genesis.
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn init(&mut self, genesis: String) -> anyhow::Result<&mut Self> {
|
fn init(&mut self, genesis: String) -> anyhow::Result<&mut Self> {
|
||||||
let _ = clear_directory(&self.base_directory);
|
let _ = clear_directory(&self.base_directory);
|
||||||
let _ = clear_directory(&self.logs_directory);
|
let _ = clear_directory(&self.logs_directory);
|
||||||
|
|
||||||
create_dir_all(&self.base_directory)?;
|
create_dir_all(&self.base_directory)
|
||||||
create_dir_all(&self.logs_directory)?;
|
.context("Failed to create base directory for geth node")?;
|
||||||
|
create_dir_all(&self.logs_directory)
|
||||||
|
.context("Failed to create logs directory for geth node")?;
|
||||||
|
|
||||||
let mut genesis = serde_json::from_str::<Genesis>(&genesis)?;
|
let mut genesis = serde_json::from_str::<Genesis>(&genesis)
|
||||||
|
.context("Failed to deserialize geth genesis JSON")?;
|
||||||
for signer_address in
|
for signer_address in
|
||||||
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
|
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
|
||||||
{
|
{
|
||||||
@@ -111,7 +119,11 @@ impl GethNode {
|
|||||||
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
|
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
|
||||||
}
|
}
|
||||||
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
|
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
|
||||||
serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
|
serde_json::to_writer(
|
||||||
|
File::create(&genesis_path).context("Failed to create geth genesis file")?,
|
||||||
|
&genesis,
|
||||||
|
)
|
||||||
|
.context("Failed to serialize geth genesis JSON to file")?;
|
||||||
|
|
||||||
let mut child = Command::new(&self.geth)
|
let mut child = Command::new(&self.geth)
|
||||||
.arg("--state.scheme")
|
.arg("--state.scheme")
|
||||||
@@ -122,16 +134,22 @@ impl GethNode {
|
|||||||
.arg(genesis_path)
|
.arg(genesis_path)
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.spawn()?;
|
.spawn()
|
||||||
|
.context("Failed to spawn geth --init process")?;
|
||||||
|
|
||||||
let mut stderr = String::new();
|
let mut stderr = String::new();
|
||||||
child
|
child
|
||||||
.stderr
|
.stderr
|
||||||
.take()
|
.take()
|
||||||
.expect("should be piped")
|
.expect("should be piped")
|
||||||
.read_to_string(&mut stderr)?;
|
.read_to_string(&mut stderr)
|
||||||
|
.context("Failed to read geth --init stderr")?;
|
||||||
|
|
||||||
if !child.wait()?.success() {
|
if !child
|
||||||
|
.wait()
|
||||||
|
.context("Failed waiting for geth --init process to finish")?
|
||||||
|
.success()
|
||||||
|
{
|
||||||
anyhow::bail!("failed to initialize geth node #{:?}: {stderr}", &self.id);
|
anyhow::bail!("failed to initialize geth node #{:?}: {stderr}", &self.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +159,7 @@ impl GethNode {
|
|||||||
/// Spawn the go-ethereum node child process.
|
/// Spawn the go-ethereum node child process.
|
||||||
///
|
///
|
||||||
/// [Instance::init] must be called prior.
|
/// [Instance::init] must be called prior.
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn spawn_process(&mut self) -> anyhow::Result<&mut Self> {
|
fn spawn_process(&mut self) -> anyhow::Result<&mut Self> {
|
||||||
// This is the `OpenOptions` that we wish to use for all of the log files that we will be
|
// This is the `OpenOptions` that we wish to use for all of the log files that we will be
|
||||||
// opening in this method. We need to construct it in this way to:
|
// opening in this method. We need to construct it in this way to:
|
||||||
@@ -156,8 +174,11 @@ impl GethNode {
|
|||||||
|
|
||||||
let stdout_logs_file = open_options
|
let stdout_logs_file = open_options
|
||||||
.clone()
|
.clone()
|
||||||
.open(self.geth_stdout_log_file_path())?;
|
.open(self.geth_stdout_log_file_path())
|
||||||
let stderr_logs_file = open_options.open(self.geth_stderr_log_file_path())?;
|
.context("Failed to open geth stdout logs file")?;
|
||||||
|
let stderr_logs_file = open_options
|
||||||
|
.open(self.geth_stderr_log_file_path())
|
||||||
|
.context("Failed to open geth stderr logs file")?;
|
||||||
self.handle = Command::new(&self.geth)
|
self.handle = Command::new(&self.geth)
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
.arg("--datadir")
|
.arg("--datadir")
|
||||||
@@ -177,14 +198,24 @@ impl GethNode {
|
|||||||
.arg("full")
|
.arg("full")
|
||||||
.arg("--gcmode")
|
.arg("--gcmode")
|
||||||
.arg("archive")
|
.arg("archive")
|
||||||
.stderr(stderr_logs_file.try_clone()?)
|
.stderr(
|
||||||
.stdout(stdout_logs_file.try_clone()?)
|
stderr_logs_file
|
||||||
.spawn()?
|
.try_clone()
|
||||||
|
.context("Failed to clone geth stderr log file handle")?,
|
||||||
|
)
|
||||||
|
.stdout(
|
||||||
|
stdout_logs_file
|
||||||
|
.try_clone()
|
||||||
|
.context("Failed to clone geth stdout log file handle")?,
|
||||||
|
)
|
||||||
|
.spawn()
|
||||||
|
.context("Failed to spawn geth node process")?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if let Err(error) = self.wait_ready() {
|
if let Err(error) = self.wait_ready() {
|
||||||
tracing::error!(?error, "Failed to start geth, shutting down gracefully");
|
tracing::error!(?error, "Failed to start geth, shutting down gracefully");
|
||||||
self.shutdown()?;
|
self.shutdown()
|
||||||
|
.context("Failed to gracefully shutdown after geth start error")?;
|
||||||
return Err(error);
|
return Err(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +228,7 @@ impl GethNode {
|
|||||||
/// Wait for the g-ethereum node child process getting ready.
|
/// Wait for the g-ethereum node child process getting ready.
|
||||||
///
|
///
|
||||||
/// [Instance::spawn_process] must be called priorly.
|
/// [Instance::spawn_process] must be called priorly.
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn wait_ready(&mut self) -> anyhow::Result<&mut Self> {
|
fn wait_ready(&mut self) -> anyhow::Result<&mut Self> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
@@ -206,7 +237,8 @@ impl GethNode {
|
|||||||
.write(false)
|
.write(false)
|
||||||
.append(false)
|
.append(false)
|
||||||
.truncate(false)
|
.truncate(false)
|
||||||
.open(self.geth_stderr_log_file_path())?;
|
.open(self.geth_stderr_log_file_path())
|
||||||
|
.context("Failed to open geth stderr logs file for readiness check")?;
|
||||||
|
|
||||||
let maximum_wait_time = Duration::from_millis(self.start_timeout);
|
let maximum_wait_time = Duration::from_millis(self.start_timeout);
|
||||||
let mut stderr = BufReader::new(logs_file).lines();
|
let mut stderr = BufReader::new(logs_file).lines();
|
||||||
@@ -231,33 +263,20 @@ impl GethNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id), level = Level::TRACE)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn geth_stdout_log_file_path(&self) -> PathBuf {
|
fn geth_stdout_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory.join(Self::GETH_STDOUT_LOG_FILE_NAME)
|
self.logs_directory.join(Self::GETH_STDOUT_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id), level = Level::TRACE)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn geth_stderr_log_file_path(&self) -> PathBuf {
|
fn geth_stderr_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory.join(Self::GETH_STDERR_LOG_FILE_NAME)
|
self.logs_directory.join(Self::GETH_STDERR_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn provider(
|
async fn provider(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Future<
|
) -> anyhow::Result<FillProvider<impl TxFiller<Ethereum>, impl Provider<Ethereum>, Ethereum>>
|
||||||
Output = anyhow::Result<
|
{
|
||||||
FillProvider<impl TxFiller<Ethereum>, impl Provider<Ethereum>, Ethereum>,
|
|
||||||
>,
|
|
||||||
> + 'static {
|
|
||||||
let connection_string = self.connection_string();
|
|
||||||
let wallet = self.wallet.clone();
|
|
||||||
|
|
||||||
// Note: We would like all providers to make use of the same nonce manager so that we have
|
|
||||||
// monotonically increasing nonces that are cached. The cached nonce manager uses Arc's in
|
|
||||||
// its implementation and therefore it means that when we clone it then it still references
|
|
||||||
// the same state.
|
|
||||||
let nonce_manager = self.nonce_manager.clone();
|
|
||||||
|
|
||||||
Box::pin(async move {
|
|
||||||
ProviderBuilder::new()
|
ProviderBuilder::new()
|
||||||
.disable_recommended_fillers()
|
.disable_recommended_fillers()
|
||||||
.filler(FallbackGasFiller::new(
|
.filler(FallbackGasFiller::new(
|
||||||
@@ -265,46 +284,61 @@ impl GethNode {
|
|||||||
1_000_000_000,
|
1_000_000_000,
|
||||||
1_000_000_000,
|
1_000_000_000,
|
||||||
))
|
))
|
||||||
.filler(ChainIdFiller::default())
|
.filler(self.chain_id_filler.clone())
|
||||||
.filler(NonceFiller::new(nonce_manager))
|
.filler(NonceFiller::new(self.nonce_manager.clone()))
|
||||||
.wallet(wallet)
|
.wallet(self.wallet.clone())
|
||||||
.connect(&connection_string)
|
.connect(&self.connection_string)
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthereumNode for GethNode {
|
impl EthereumNode for GethNode {
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(
|
||||||
|
level = "info",
|
||||||
|
skip_all,
|
||||||
|
fields(geth_node_id = self.id, connection_string = self.connection_string),
|
||||||
|
err,
|
||||||
|
)]
|
||||||
async fn execute_transaction(
|
async fn execute_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: TransactionRequest,
|
transaction: TransactionRequest,
|
||||||
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
|
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
|
||||||
let provider = Arc::new(self.provider().await?);
|
let provider = self
|
||||||
let transaction_hash = *provider.send_transaction(transaction).await?.tx_hash();
|
.provider()
|
||||||
|
.await
|
||||||
|
.context("Failed to create provider for transaction submission")?;
|
||||||
|
|
||||||
// The following is a fix for the "transaction indexing is in progress" error that we
|
let pending_transaction = provider
|
||||||
// used to get. You can find more information on this in the following GH issue in geth
|
.send_transaction(transaction)
|
||||||
|
.await
|
||||||
|
.inspect_err(
|
||||||
|
|err| tracing::error!(%err, "Encountered an error when submitting the transaction"),
|
||||||
|
)
|
||||||
|
.context("Failed to submit transaction to geth node")?;
|
||||||
|
let transaction_hash = *pending_transaction.tx_hash();
|
||||||
|
|
||||||
|
// The following is a fix for the "transaction indexing is in progress" error that we used
|
||||||
|
// to get. You can find more information on this in the following GH issue in geth
|
||||||
// https://github.com/ethereum/go-ethereum/issues/28877. To summarize what's going on,
|
// https://github.com/ethereum/go-ethereum/issues/28877. To summarize what's going on,
|
||||||
// before we can get the receipt of the transaction it needs to have been indexed by the
|
// before we can get the receipt of the transaction it needs to have been indexed by the
|
||||||
// node's indexer. Just because the transaction has been confirmed it doesn't mean that
|
// node's indexer. Just because the transaction has been confirmed it doesn't mean that it
|
||||||
// it has been indexed. When we call alloy's `get_receipt` it checks if the transaction
|
// has been indexed. When we call alloy's `get_receipt` it checks if the transaction was
|
||||||
// was confirmed. If it has been, then it will call `eth_getTransactionReceipt` method
|
// confirmed. If it has been, then it will call `eth_getTransactionReceipt` method which
|
||||||
// which _might_ return the above error if the tx has not yet been indexed yet. So, we
|
// _might_ return the above error if the tx has not yet been indexed yet. So, we need to
|
||||||
// need to implement a retry mechanism for the receipt to keep retrying to get it until
|
// implement a retry mechanism for the receipt to keep retrying to get it until it
|
||||||
// it eventually works, but we only do that if the error we get back is the "transaction
|
// eventually works, but we only do that if the error we get back is the "transaction
|
||||||
// indexing is in progress" error or if the receipt is None.
|
// indexing is in progress" error or if the receipt is None.
|
||||||
//
|
//
|
||||||
// Getting the transaction indexed and taking a receipt can take a long time especially
|
// Getting the transaction indexed and taking a receipt can take a long time especially when
|
||||||
// when a lot of transactions are being submitted to the node. Thus, while initially we
|
// a lot of transactions are being submitted to the node. Thus, while initially we only
|
||||||
// only allowed for 60 seconds of waiting with a 1 second delay in polling, we need to
|
// allowed for 60 seconds of waiting with a 1 second delay in polling, we need to allow for
|
||||||
// allow for a larger wait time. Therefore, in here we allow for 5 minutes of waiting
|
// a larger wait time. Therefore, in here we allow for 5 minutes of waiting with exponential
|
||||||
// with exponential backoff each time we attempt to get the receipt and find that it's
|
// backoff each time we attempt to get the receipt and find that it's not available.
|
||||||
// not available.
|
let provider = Arc::new(provider);
|
||||||
poll(
|
poll(
|
||||||
Self::RECEIPT_POLLING_DURATION,
|
Self::RECEIPT_POLLING_DURATION,
|
||||||
Default::default(),
|
PollingWaitBehavior::Constant(Duration::from_millis(200)),
|
||||||
move || {
|
move || {
|
||||||
let provider = provider.clone();
|
let provider = provider.clone();
|
||||||
async move {
|
async move {
|
||||||
@@ -329,16 +363,20 @@ impl EthereumNode for GethNode {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn trace_transaction(
|
async fn trace_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: &TransactionReceipt,
|
transaction: &TransactionReceipt,
|
||||||
trace_options: GethDebugTracingOptions,
|
trace_options: GethDebugTracingOptions,
|
||||||
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
||||||
let provider = Arc::new(self.provider().await?);
|
let provider = Arc::new(
|
||||||
|
self.provider()
|
||||||
|
.await
|
||||||
|
.context("Failed to create provider for tracing")?,
|
||||||
|
);
|
||||||
poll(
|
poll(
|
||||||
Self::TRACE_POLLING_DURATION,
|
Self::TRACE_POLLING_DURATION,
|
||||||
Default::default(),
|
PollingWaitBehavior::Constant(Duration::from_millis(200)),
|
||||||
move || {
|
move || {
|
||||||
let provider = provider.clone();
|
let provider = provider.clone();
|
||||||
let trace_options = trace_options.clone();
|
let trace_options = trace_options.clone();
|
||||||
@@ -362,7 +400,7 @@ impl EthereumNode for GethNode {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> {
|
async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> {
|
||||||
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
||||||
diff_mode: Some(true),
|
diff_mode: Some(true),
|
||||||
@@ -371,31 +409,35 @@ impl EthereumNode for GethNode {
|
|||||||
});
|
});
|
||||||
match self
|
match self
|
||||||
.trace_transaction(transaction, trace_options)
|
.trace_transaction(transaction, trace_options)
|
||||||
.await?
|
.await
|
||||||
.try_into_pre_state_frame()?
|
.context("Failed to trace transaction for prestate diff")?
|
||||||
|
.try_into_pre_state_frame()
|
||||||
|
.context("Failed to convert trace into pre-state frame")?
|
||||||
{
|
{
|
||||||
PreStateFrame::Diff(diff) => Ok(diff),
|
PreStateFrame::Diff(diff) => Ok(diff),
|
||||||
_ => anyhow::bail!("expected a diff mode trace"),
|
_ => anyhow::bail!("expected a diff mode trace"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_balance(address)
|
.get_balance(address)
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn latest_state_proof(
|
async fn latest_state_proof(
|
||||||
&self,
|
&self,
|
||||||
address: Address,
|
address: Address,
|
||||||
keys: Vec<StorageKey>,
|
keys: Vec<StorageKey>,
|
||||||
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_proof(address, keys)
|
.get_proof(address, keys)
|
||||||
.latest()
|
.latest()
|
||||||
.await
|
.await
|
||||||
@@ -404,62 +446,72 @@ impl EthereumNode for GethNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ResolverApi for GethNode {
|
impl ResolverApi for GethNode {
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
|
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_chain_id()
|
.get_chain_id()
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
|
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_transaction_receipt(*tx_hash)
|
.get_transaction_receipt(*tx_hash)
|
||||||
.await?
|
.await?
|
||||||
.context("Failed to get the transaction receipt")
|
.context("Failed to get the transaction receipt")
|
||||||
.map(|receipt| receipt.effective_gas_price)
|
.map(|receipt| receipt.effective_gas_price)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.map(|block| block.header.gas_limit as _)
|
.map(|block| block.header.gas_limit as _)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.map(|block| block.header.beneficiary)
|
.map(|block| block.header.beneficiary)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.map(|block| U256::from_be_bytes(block.header.mix_hash.0))
|
.map(|block| U256::from_be_bytes(block.header.mix_hash.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
|
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.and_then(|block| {
|
.and_then(|block| {
|
||||||
block
|
block
|
||||||
.header
|
.header
|
||||||
@@ -468,30 +520,35 @@ impl ResolverApi for GethNode {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.map(|block| block.header.hash)
|
.map(|block| block.header.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the geth block")?
|
||||||
|
.context("Failed to get the Geth block, perhaps there are no blocks?")
|
||||||
.map(|block| block.header.timestamp)
|
.map(|block| block.header.timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
|
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Geth provider")?
|
||||||
.get_block_number()
|
.get_block_number()
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
@@ -522,20 +579,26 @@ impl Node for GethNode {
|
|||||||
id,
|
id,
|
||||||
handle: None,
|
handle: None,
|
||||||
start_timeout: config.geth_start_timeout,
|
start_timeout: config.geth_start_timeout,
|
||||||
wallet,
|
wallet: Arc::new(wallet),
|
||||||
|
chain_id_filler: Default::default(),
|
||||||
|
nonce_manager: Default::default(),
|
||||||
// We know that we only need to be storing 2 files so we can specify that when creating
|
// We know that we only need to be storing 2 files so we can specify that when creating
|
||||||
// the vector. It's the stdout and stderr of the geth node.
|
// the vector. It's the stdout and stderr of the geth node.
|
||||||
logs_file_to_flush: Vec::with_capacity(2),
|
logs_file_to_flush: Vec::with_capacity(2),
|
||||||
nonce_manager: Default::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
|
fn id(&self) -> usize {
|
||||||
|
self.id as _
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn connection_string(&self) -> String {
|
fn connection_string(&self) -> String {
|
||||||
self.connection_string.clone()
|
self.connection_string.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn shutdown(&mut self) -> anyhow::Result<()> {
|
fn shutdown(&mut self) -> anyhow::Result<()> {
|
||||||
// Terminate the processes in a graceful manner to allow for the output to be flushed.
|
// Terminate the processes in a graceful manner to allow for the output to be flushed.
|
||||||
if let Some(mut child) = self.handle.take() {
|
if let Some(mut child) = self.handle.take() {
|
||||||
@@ -557,27 +620,28 @@ impl Node for GethNode {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn spawn(&mut self, genesis: String) -> anyhow::Result<()> {
|
fn spawn(&mut self, genesis: String) -> anyhow::Result<()> {
|
||||||
self.init(genesis)?.spawn_process()?;
|
self.init(genesis)?.spawn_process()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id), err)]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn version(&self) -> anyhow::Result<String> {
|
fn version(&self) -> anyhow::Result<String> {
|
||||||
let output = Command::new(&self.geth)
|
let output = Command::new(&self.geth)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.spawn()?
|
.spawn()
|
||||||
.wait_with_output()?
|
.context("Failed to spawn geth --version process")?
|
||||||
|
.wait_with_output()
|
||||||
|
.context("Failed to wait for geth --version output")?
|
||||||
.stdout;
|
.stdout;
|
||||||
Ok(String::from_utf8_lossy(&output).into())
|
Ok(String::from_utf8_lossy(&output).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
fn matches_target(targets: Option<&[String]>) -> bool {
|
||||||
fn matches_target(&self, targets: Option<&[String]>) -> bool {
|
|
||||||
match targets {
|
match targets {
|
||||||
None => true,
|
None => true,
|
||||||
Some(targets) => targets.iter().any(|str| str.as_str() == "evm"),
|
Some(targets) => targets.iter().any(|str| str.as_str() == "evm"),
|
||||||
@@ -590,7 +654,7 @@ impl Node for GethNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for GethNode {
|
impl Drop for GethNode {
|
||||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
#[instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.shutdown().expect("Failed to shutdown")
|
self.shutdown().expect("Failed to shutdown")
|
||||||
}
|
}
|
||||||
@@ -600,7 +664,7 @@ impl Drop for GethNode {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
|
|
||||||
use temp_dir::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
use crate::{GENESIS_JSON, Node};
|
use crate::{GENESIS_JSON, Node};
|
||||||
|
|
||||||
|
|||||||
+155
-115
@@ -3,7 +3,10 @@ use std::{
|
|||||||
io::{BufRead, Write},
|
io::{BufRead, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Child, Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
sync::atomic::{AtomicU32, Ordering},
|
sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{AtomicU32, Ordering},
|
||||||
|
},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,7 +42,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::{Value as JsonValue, json};
|
use serde_json::{Value as JsonValue, json};
|
||||||
use sp_core::crypto::Ss58Codec;
|
use sp_core::crypto::Ss58Codec;
|
||||||
use sp_runtime::AccountId32;
|
use sp_runtime::AccountId32;
|
||||||
use tracing::Level;
|
|
||||||
|
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
use revive_dt_node_interaction::EthereumNode;
|
use revive_dt_node_interaction::EthereumNode;
|
||||||
@@ -52,14 +54,17 @@ static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
|||||||
pub struct KitchensinkNode {
|
pub struct KitchensinkNode {
|
||||||
id: u32,
|
id: u32,
|
||||||
substrate_binary: PathBuf,
|
substrate_binary: PathBuf,
|
||||||
|
dev_node_binary: PathBuf,
|
||||||
eth_proxy_binary: PathBuf,
|
eth_proxy_binary: PathBuf,
|
||||||
rpc_url: String,
|
rpc_url: String,
|
||||||
wallet: EthereumWallet,
|
|
||||||
base_directory: PathBuf,
|
base_directory: PathBuf,
|
||||||
logs_directory: PathBuf,
|
logs_directory: PathBuf,
|
||||||
process_substrate: Option<Child>,
|
process_substrate: Option<Child>,
|
||||||
process_proxy: Option<Child>,
|
process_proxy: Option<Child>,
|
||||||
|
wallet: Arc<EthereumWallet>,
|
||||||
nonce_manager: CachedNonceManager,
|
nonce_manager: CachedNonceManager,
|
||||||
|
chain_id_filler: ChainIdFiller,
|
||||||
|
use_kitchensink_not_dev_node: bool,
|
||||||
/// This vector stores [`File`] objects that we use for logging which we want to flush when the
|
/// This vector stores [`File`] objects that we use for logging which we want to flush when the
|
||||||
/// node object is dropped. We do not store them in a structured fashion at the moment (in
|
/// node object is dropped. We do not store them in a structured fashion at the moment (in
|
||||||
/// separate fields) as the logic that we need to apply to them is all the same regardless of
|
/// separate fields) as the logic that we need to apply to them is all the same regardless of
|
||||||
@@ -87,23 +92,34 @@ impl KitchensinkNode {
|
|||||||
const PROXY_STDOUT_LOG_FILE_NAME: &str = "proxy_stdout.log";
|
const PROXY_STDOUT_LOG_FILE_NAME: &str = "proxy_stdout.log";
|
||||||
const PROXY_STDERR_LOG_FILE_NAME: &str = "proxy_stderr.log";
|
const PROXY_STDERR_LOG_FILE_NAME: &str = "proxy_stderr.log";
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
|
||||||
fn init(&mut self, genesis: &str) -> anyhow::Result<&mut Self> {
|
fn init(&mut self, genesis: &str) -> anyhow::Result<&mut Self> {
|
||||||
let _ = clear_directory(&self.base_directory);
|
let _ = clear_directory(&self.base_directory);
|
||||||
let _ = clear_directory(&self.logs_directory);
|
let _ = clear_directory(&self.logs_directory);
|
||||||
|
|
||||||
create_dir_all(&self.base_directory)?;
|
create_dir_all(&self.base_directory)
|
||||||
create_dir_all(&self.logs_directory)?;
|
.context("Failed to create base directory for kitchensink node")?;
|
||||||
|
create_dir_all(&self.logs_directory)
|
||||||
|
.context("Failed to create logs directory for kitchensink node")?;
|
||||||
|
|
||||||
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
|
||||||
|
|
||||||
// Note: we do not pipe the logs of this process to a separate file since this is just a
|
// Note: we do not pipe the logs of this process to a separate file since this is just a
|
||||||
// once-off export of the default chain spec and not part of the long-running node process.
|
// once-off export of the default chain spec and not part of the long-running node process.
|
||||||
let output = Command::new(&self.substrate_binary)
|
let output = if self.use_kitchensink_not_dev_node {
|
||||||
|
Command::new(&self.substrate_binary)
|
||||||
.arg("export-chain-spec")
|
.arg("export-chain-spec")
|
||||||
.arg("--chain")
|
.arg("--chain")
|
||||||
.arg("dev")
|
.arg("dev")
|
||||||
.output()?;
|
.output()
|
||||||
|
.context("Failed to export the chain-spec")?
|
||||||
|
} else {
|
||||||
|
Command::new(&self.dev_node_binary)
|
||||||
|
.arg("build-spec")
|
||||||
|
.arg("--chain")
|
||||||
|
.arg("dev")
|
||||||
|
.output()
|
||||||
|
.context("Failed to export the chain-spec")?
|
||||||
|
};
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
@@ -112,8 +128,10 @@ impl KitchensinkNode {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = String::from_utf8(output.stdout)?;
|
let content = String::from_utf8(output.stdout)
|
||||||
let mut chainspec_json: JsonValue = serde_json::from_str(&content)?;
|
.context("Failed to decode substrate export-chain-spec output as UTF-8")?;
|
||||||
|
let mut chainspec_json: JsonValue =
|
||||||
|
serde_json::from_str(&content).context("Failed to parse substrate chain spec JSON")?;
|
||||||
|
|
||||||
let existing_chainspec_balances =
|
let existing_chainspec_balances =
|
||||||
chainspec_json["genesis"]["runtimeGenesis"]["patch"]["balances"]["balances"]
|
chainspec_json["genesis"]["runtimeGenesis"]["patch"]["balances"]["balances"]
|
||||||
@@ -135,7 +153,8 @@ impl KitchensinkNode {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut eth_balances = {
|
let mut eth_balances = {
|
||||||
let mut genesis = serde_json::from_str::<Genesis>(genesis)?;
|
let mut genesis = serde_json::from_str::<Genesis>(genesis)
|
||||||
|
.context("Failed to deserialize EVM genesis JSON for kitchensink")?;
|
||||||
for signer_address in
|
for signer_address in
|
||||||
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
|
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
|
||||||
{
|
{
|
||||||
@@ -146,7 +165,8 @@ impl KitchensinkNode {
|
|||||||
.entry(signer_address)
|
.entry(signer_address)
|
||||||
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
|
.or_insert(GenesisAccount::default().with_balance(U256::from(INITIAL_BALANCE)));
|
||||||
}
|
}
|
||||||
self.extract_balance_from_genesis_file(&genesis)?
|
self.extract_balance_from_genesis_file(&genesis)
|
||||||
|
.context("Failed to extract balances from EVM genesis JSON")?
|
||||||
};
|
};
|
||||||
merged_balances.append(&mut eth_balances);
|
merged_balances.append(&mut eth_balances);
|
||||||
|
|
||||||
@@ -154,13 +174,14 @@ impl KitchensinkNode {
|
|||||||
json!(merged_balances);
|
json!(merged_balances);
|
||||||
|
|
||||||
serde_json::to_writer_pretty(
|
serde_json::to_writer_pretty(
|
||||||
std::fs::File::create(&template_chainspec_path)?,
|
std::fs::File::create(&template_chainspec_path)
|
||||||
|
.context("Failed to create kitchensink template chainspec file")?,
|
||||||
&chainspec_json,
|
&chainspec_json,
|
||||||
)?;
|
)
|
||||||
|
.context("Failed to write kitchensink template chainspec JSON")?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
fn spawn_process(&mut self) -> anyhow::Result<()> {
|
fn spawn_process(&mut self) -> anyhow::Result<()> {
|
||||||
let substrate_rpc_port = Self::BASE_SUBSTRATE_RPC_PORT + self.id as u16;
|
let substrate_rpc_port = Self::BASE_SUBSTRATE_RPC_PORT + self.id as u16;
|
||||||
let proxy_rpc_port = Self::BASE_PROXY_RPC_PORT + self.id as u16;
|
let proxy_rpc_port = Self::BASE_PROXY_RPC_PORT + self.id as u16;
|
||||||
@@ -183,11 +204,18 @@ impl KitchensinkNode {
|
|||||||
// Start Substrate node
|
// Start Substrate node
|
||||||
let kitchensink_stdout_logs_file = open_options
|
let kitchensink_stdout_logs_file = open_options
|
||||||
.clone()
|
.clone()
|
||||||
.open(self.kitchensink_stdout_log_file_path())?;
|
.open(self.kitchensink_stdout_log_file_path())
|
||||||
|
.context("Failed to open kitchensink stdout logs file")?;
|
||||||
let kitchensink_stderr_logs_file = open_options
|
let kitchensink_stderr_logs_file = open_options
|
||||||
.clone()
|
.clone()
|
||||||
.open(self.kitchensink_stderr_log_file_path())?;
|
.open(self.kitchensink_stderr_log_file_path())
|
||||||
self.process_substrate = Command::new(&self.substrate_binary)
|
.context("Failed to open kitchensink stderr logs file")?;
|
||||||
|
let node_binary_path = if self.use_kitchensink_not_dev_node {
|
||||||
|
self.substrate_binary.as_path()
|
||||||
|
} else {
|
||||||
|
self.dev_node_binary.as_path()
|
||||||
|
};
|
||||||
|
self.process_substrate = Command::new(node_binary_path)
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
.arg("--chain")
|
.arg("--chain")
|
||||||
.arg(chainspec_path)
|
.arg(chainspec_path)
|
||||||
@@ -202,10 +230,21 @@ impl KitchensinkNode {
|
|||||||
.arg("Unsafe")
|
.arg("Unsafe")
|
||||||
.arg("--rpc-cors")
|
.arg("--rpc-cors")
|
||||||
.arg("all")
|
.arg("all")
|
||||||
|
.arg("--rpc-max-connections")
|
||||||
|
.arg(u32::MAX.to_string())
|
||||||
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
|
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
|
||||||
.stdout(kitchensink_stdout_logs_file.try_clone()?)
|
.stdout(
|
||||||
.stderr(kitchensink_stderr_logs_file.try_clone()?)
|
kitchensink_stdout_logs_file
|
||||||
.spawn()?
|
.try_clone()
|
||||||
|
.context("Failed to clone kitchensink stdout log file handle")?,
|
||||||
|
)
|
||||||
|
.stderr(
|
||||||
|
kitchensink_stderr_logs_file
|
||||||
|
.try_clone()
|
||||||
|
.context("Failed to clone kitchensink stderr log file handle")?,
|
||||||
|
)
|
||||||
|
.spawn()
|
||||||
|
.context("Failed to spawn substrate node process")?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
// Give the node a moment to boot
|
// Give the node a moment to boot
|
||||||
@@ -214,28 +253,39 @@ impl KitchensinkNode {
|
|||||||
Self::SUBSTRATE_READY_MARKER,
|
Self::SUBSTRATE_READY_MARKER,
|
||||||
Duration::from_secs(60),
|
Duration::from_secs(60),
|
||||||
) {
|
) {
|
||||||
tracing::error!(
|
self.shutdown()
|
||||||
?error,
|
.context("Failed to gracefully shutdown after substrate start error")?;
|
||||||
"Failed to start substrate, shutting down gracefully"
|
|
||||||
);
|
|
||||||
self.shutdown()?;
|
|
||||||
return Err(error);
|
return Err(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
let eth_proxy_stdout_logs_file = open_options
|
let eth_proxy_stdout_logs_file = open_options
|
||||||
.clone()
|
.clone()
|
||||||
.open(self.proxy_stdout_log_file_path())?;
|
.open(self.proxy_stdout_log_file_path())
|
||||||
let eth_proxy_stderr_logs_file = open_options.open(self.proxy_stderr_log_file_path())?;
|
.context("Failed to open eth-proxy stdout logs file")?;
|
||||||
|
let eth_proxy_stderr_logs_file = open_options
|
||||||
|
.open(self.proxy_stderr_log_file_path())
|
||||||
|
.context("Failed to open eth-proxy stderr logs file")?;
|
||||||
self.process_proxy = Command::new(&self.eth_proxy_binary)
|
self.process_proxy = Command::new(&self.eth_proxy_binary)
|
||||||
.arg("--dev")
|
.arg("--dev")
|
||||||
.arg("--rpc-port")
|
.arg("--rpc-port")
|
||||||
.arg(proxy_rpc_port.to_string())
|
.arg(proxy_rpc_port.to_string())
|
||||||
.arg("--node-rpc-url")
|
.arg("--node-rpc-url")
|
||||||
.arg(format!("ws://127.0.0.1:{substrate_rpc_port}"))
|
.arg(format!("ws://127.0.0.1:{substrate_rpc_port}"))
|
||||||
|
.arg("--rpc-max-connections")
|
||||||
|
.arg(u32::MAX.to_string())
|
||||||
.env("RUST_LOG", Self::PROXY_LOG_ENV)
|
.env("RUST_LOG", Self::PROXY_LOG_ENV)
|
||||||
.stdout(eth_proxy_stdout_logs_file.try_clone()?)
|
.stdout(
|
||||||
.stderr(eth_proxy_stderr_logs_file.try_clone()?)
|
eth_proxy_stdout_logs_file
|
||||||
.spawn()?
|
.try_clone()
|
||||||
|
.context("Failed to clone eth-proxy stdout log file handle")?,
|
||||||
|
)
|
||||||
|
.stderr(
|
||||||
|
eth_proxy_stderr_logs_file
|
||||||
|
.try_clone()
|
||||||
|
.context("Failed to clone eth-proxy stderr log file handle")?,
|
||||||
|
)
|
||||||
|
.spawn()
|
||||||
|
.context("Failed to spawn eth-proxy process")?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if let Err(error) = Self::wait_ready(
|
if let Err(error) = Self::wait_ready(
|
||||||
@@ -243,8 +293,8 @@ impl KitchensinkNode {
|
|||||||
Self::ETH_PROXY_READY_MARKER,
|
Self::ETH_PROXY_READY_MARKER,
|
||||||
Duration::from_secs(60),
|
Duration::from_secs(60),
|
||||||
) {
|
) {
|
||||||
tracing::error!(?error, "Failed to start proxy, shutting down gracefully");
|
self.shutdown()
|
||||||
self.shutdown()?;
|
.context("Failed to gracefully shutdown after eth-proxy start error")?;
|
||||||
return Err(error);
|
return Err(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -258,7 +308,6 @@ impl KitchensinkNode {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
fn extract_balance_from_genesis_file(
|
fn extract_balance_from_genesis_file(
|
||||||
&self,
|
&self,
|
||||||
genesis: &Genesis,
|
genesis: &Genesis,
|
||||||
@@ -307,7 +356,6 @@ impl KitchensinkNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
pub fn eth_rpc_version(&self) -> anyhow::Result<String> {
|
pub fn eth_rpc_version(&self) -> anyhow::Result<String> {
|
||||||
let output = Command::new(&self.eth_proxy_binary)
|
let output = Command::new(&self.eth_proxy_binary)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
@@ -320,49 +368,33 @@ impl KitchensinkNode {
|
|||||||
Ok(String::from_utf8_lossy(&output).trim().to_string())
|
Ok(String::from_utf8_lossy(&output).trim().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
|
||||||
fn kitchensink_stdout_log_file_path(&self) -> PathBuf {
|
fn kitchensink_stdout_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory
|
self.logs_directory
|
||||||
.join(Self::KITCHENSINK_STDOUT_LOG_FILE_NAME)
|
.join(Self::KITCHENSINK_STDOUT_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
|
||||||
fn kitchensink_stderr_log_file_path(&self) -> PathBuf {
|
fn kitchensink_stderr_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory
|
self.logs_directory
|
||||||
.join(Self::KITCHENSINK_STDERR_LOG_FILE_NAME)
|
.join(Self::KITCHENSINK_STDERR_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
|
||||||
fn proxy_stdout_log_file_path(&self) -> PathBuf {
|
fn proxy_stdout_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory.join(Self::PROXY_STDOUT_LOG_FILE_NAME)
|
self.logs_directory.join(Self::PROXY_STDOUT_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), level = Level::TRACE)]
|
|
||||||
fn proxy_stderr_log_file_path(&self) -> PathBuf {
|
fn proxy_stderr_log_file_path(&self) -> PathBuf {
|
||||||
self.logs_directory.join(Self::PROXY_STDERR_LOG_FILE_NAME)
|
self.logs_directory.join(Self::PROXY_STDERR_LOG_FILE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn provider(
|
async fn provider(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Future<
|
) -> anyhow::Result<
|
||||||
Output = anyhow::Result<
|
|
||||||
FillProvider<
|
FillProvider<
|
||||||
impl TxFiller<KitchenSinkNetwork>,
|
impl TxFiller<KitchenSinkNetwork>,
|
||||||
impl Provider<KitchenSinkNetwork>,
|
impl Provider<KitchenSinkNetwork>,
|
||||||
KitchenSinkNetwork,
|
KitchenSinkNetwork,
|
||||||
>,
|
>,
|
||||||
>,
|
> {
|
||||||
> + 'static {
|
|
||||||
let connection_string = self.connection_string();
|
|
||||||
let wallet = self.wallet.clone();
|
|
||||||
|
|
||||||
// Note: We would like all providers to make use of the same nonce manager so that we have
|
|
||||||
// monotonically increasing nonces that are cached. The cached nonce manager uses Arc's in
|
|
||||||
// its implementation and therefore it means that when we clone it then it still references
|
|
||||||
// the same state.
|
|
||||||
let nonce_manager = self.nonce_manager.clone();
|
|
||||||
|
|
||||||
Box::pin(async move {
|
|
||||||
ProviderBuilder::new()
|
ProviderBuilder::new()
|
||||||
.disable_recommended_fillers()
|
.disable_recommended_fillers()
|
||||||
.network::<KitchenSinkNetwork>()
|
.network::<KitchenSinkNetwork>()
|
||||||
@@ -371,49 +403,47 @@ impl KitchensinkNode {
|
|||||||
1_000_000_000,
|
1_000_000_000,
|
||||||
1_000_000_000,
|
1_000_000_000,
|
||||||
))
|
))
|
||||||
.filler(ChainIdFiller::default())
|
.filler(self.chain_id_filler.clone())
|
||||||
.filler(NonceFiller::new(nonce_manager))
|
.filler(NonceFiller::new(self.nonce_manager.clone()))
|
||||||
.wallet(wallet)
|
.wallet(self.wallet.clone())
|
||||||
.connect(&connection_string)
|
.connect(&self.rpc_url)
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EthereumNode for KitchensinkNode {
|
impl EthereumNode for KitchensinkNode {
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn execute_transaction(
|
async fn execute_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: alloy::rpc::types::TransactionRequest,
|
transaction: alloy::rpc::types::TransactionRequest,
|
||||||
) -> anyhow::Result<TransactionReceipt> {
|
) -> anyhow::Result<TransactionReceipt> {
|
||||||
tracing::debug!(?transaction, "Submitting transaction");
|
|
||||||
let receipt = self
|
let receipt = self
|
||||||
.provider()
|
.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to create provider for transaction submission")?
|
||||||
.send_transaction(transaction)
|
.send_transaction(transaction)
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to submit transaction to kitchensink proxy")?
|
||||||
.get_receipt()
|
.get_receipt()
|
||||||
.await?;
|
.await
|
||||||
tracing::info!(?receipt, "Submitted tx to kitchensink");
|
.context("Failed to fetch transaction receipt from kitchensink proxy")?;
|
||||||
Ok(receipt)
|
Ok(receipt)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn trace_transaction(
|
async fn trace_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: &TransactionReceipt,
|
transaction: &TransactionReceipt,
|
||||||
trace_options: GethDebugTracingOptions,
|
trace_options: GethDebugTracingOptions,
|
||||||
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
||||||
let tx_hash = transaction.transaction_hash;
|
let tx_hash = transaction.transaction_hash;
|
||||||
Ok(self
|
self.provider()
|
||||||
.provider()
|
.await
|
||||||
.await?
|
.context("Failed to create provider for debug tracing")?
|
||||||
.debug_trace_transaction(tx_hash, trace_options)
|
.debug_trace_transaction(tx_hash, trace_options)
|
||||||
.await?)
|
.await
|
||||||
|
.context("Failed to obtain debug trace from kitchensink proxy")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> {
|
async fn state_diff(&self, transaction: &TransactionReceipt) -> anyhow::Result<DiffMode> {
|
||||||
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
||||||
diff_mode: Some(true),
|
diff_mode: Some(true),
|
||||||
@@ -430,23 +460,23 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_balance(address)
|
.get_balance(address)
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn latest_state_proof(
|
async fn latest_state_proof(
|
||||||
&self,
|
&self,
|
||||||
address: Address,
|
address: Address,
|
||||||
keys: Vec<StorageKey>,
|
keys: Vec<StorageKey>,
|
||||||
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
) -> anyhow::Result<EIP1186AccountProofResponse> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_proof(address, keys)
|
.get_proof(address, keys)
|
||||||
.latest()
|
.latest()
|
||||||
.await
|
.await
|
||||||
@@ -455,62 +485,66 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ResolverApi for KitchensinkNode {
|
impl ResolverApi for KitchensinkNode {
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
|
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_chain_id()
|
.get_chain_id()
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
|
async fn transaction_gas_price(&self, tx_hash: &TxHash) -> anyhow::Result<u128> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_transaction_receipt(*tx_hash)
|
.get_transaction_receipt(*tx_hash)
|
||||||
.await?
|
.await?
|
||||||
.context("Failed to get the transaction receipt")
|
.context("Failed to get the transaction receipt")
|
||||||
.map(|receipt| receipt.effective_gas_price)
|
.map(|receipt| receipt.effective_gas_price)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.map(|block| block.header.gas_limit as _)
|
.map(|block| block.header.gas_limit as _)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.map(|block| block.header.beneficiary)
|
.map(|block| block.header.beneficiary)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.map(|block| U256::from_be_bytes(block.header.mix_hash.0))
|
.map(|block| U256::from_be_bytes(block.header.mix_hash.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
|
async fn block_base_fee(&self, number: BlockNumberOrTag) -> anyhow::Result<u64> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.and_then(|block| {
|
.and_then(|block| {
|
||||||
block
|
block
|
||||||
.header
|
.header
|
||||||
@@ -519,30 +553,32 @@ impl ResolverApi for KitchensinkNode {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
async fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockHash> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.map(|block| block.header.hash)
|
.map(|block| block.header.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
async fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result<BlockTimestamp> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_by_number(number)
|
.get_block_by_number(number)
|
||||||
.await?
|
.await
|
||||||
.ok_or(anyhow::Error::msg("Blockchain has no blocks"))
|
.context("Failed to get the kitchensink block")?
|
||||||
|
.context("Failed to get the Kitchensink block, perhaps the chain has no blocks?")
|
||||||
.map(|block| block.header.timestamp)
|
.map(|block| block.header.timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
|
async fn last_block_number(&self) -> anyhow::Result<BlockNumber> {
|
||||||
self.provider()
|
self.provider()
|
||||||
.await?
|
.await
|
||||||
|
.context("Failed to get the Kitchensink provider")?
|
||||||
.get_block_number()
|
.get_block_number()
|
||||||
.await
|
.await
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
@@ -568,26 +604,31 @@ impl Node for KitchensinkNode {
|
|||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
substrate_binary: config.kitchensink.clone(),
|
substrate_binary: config.kitchensink.clone(),
|
||||||
|
dev_node_binary: config.revive_dev_node.clone(),
|
||||||
eth_proxy_binary: config.eth_proxy.clone(),
|
eth_proxy_binary: config.eth_proxy.clone(),
|
||||||
rpc_url: String::new(),
|
rpc_url: String::new(),
|
||||||
wallet,
|
|
||||||
base_directory,
|
base_directory,
|
||||||
logs_directory,
|
logs_directory,
|
||||||
process_substrate: None,
|
process_substrate: None,
|
||||||
process_proxy: None,
|
process_proxy: None,
|
||||||
|
wallet: Arc::new(wallet),
|
||||||
|
chain_id_filler: Default::default(),
|
||||||
nonce_manager: Default::default(),
|
nonce_manager: Default::default(),
|
||||||
|
use_kitchensink_not_dev_node: config.use_kitchensink_not_dev_node,
|
||||||
// We know that we only need to be storing 4 files so we can specify that when creating
|
// We know that we only need to be storing 4 files so we can specify that when creating
|
||||||
// the vector. It's the stdout and stderr of the substrate-node and the eth-rpc.
|
// the vector. It's the stdout and stderr of the substrate-node and the eth-rpc.
|
||||||
logs_file_to_flush: Vec::with_capacity(4),
|
logs_file_to_flush: Vec::with_capacity(4),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
fn id(&self) -> usize {
|
||||||
|
self.id as _
|
||||||
|
}
|
||||||
|
|
||||||
fn connection_string(&self) -> String {
|
fn connection_string(&self) -> String {
|
||||||
self.rpc_url.clone()
|
self.rpc_url.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
fn shutdown(&mut self) -> anyhow::Result<()> {
|
fn shutdown(&mut self) -> anyhow::Result<()> {
|
||||||
// Terminate the processes in a graceful manner to allow for the output to be flushed.
|
// Terminate the processes in a graceful manner to allow for the output to be flushed.
|
||||||
if let Some(mut child) = self.process_proxy.take() {
|
if let Some(mut child) = self.process_proxy.take() {
|
||||||
@@ -614,26 +655,25 @@ impl Node for KitchensinkNode {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
fn spawn(&mut self, genesis: String) -> anyhow::Result<()> {
|
fn spawn(&mut self, genesis: String) -> anyhow::Result<()> {
|
||||||
self.init(&genesis)?.spawn_process()
|
self.init(&genesis)?.spawn_process()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id), err)]
|
|
||||||
fn version(&self) -> anyhow::Result<String> {
|
fn version(&self) -> anyhow::Result<String> {
|
||||||
let output = Command::new(&self.substrate_binary)
|
let output = Command::new(&self.substrate_binary)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.spawn()?
|
.spawn()
|
||||||
.wait_with_output()?
|
.context("Failed to spawn kitchensink --version")?
|
||||||
|
.wait_with_output()
|
||||||
|
.context("Failed to wait for kitchensink --version")?
|
||||||
.stdout;
|
.stdout;
|
||||||
Ok(String::from_utf8_lossy(&output).into())
|
Ok(String::from_utf8_lossy(&output).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
fn matches_target(targets: Option<&[String]>) -> bool {
|
||||||
fn matches_target(&self, targets: Option<&[String]>) -> bool {
|
|
||||||
match targets {
|
match targets {
|
||||||
None => true,
|
None => true,
|
||||||
Some(targets) => targets.iter().any(|str| str.as_str() == "pvm"),
|
Some(targets) => targets.iter().any(|str| str.as_str() == "pvm"),
|
||||||
@@ -646,7 +686,6 @@ impl Node for KitchensinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for KitchensinkNode {
|
impl Drop for KitchensinkNode {
|
||||||
#[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))]
|
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.shutdown().expect("Failed to shutdown")
|
self.shutdown().expect("Failed to shutdown")
|
||||||
}
|
}
|
||||||
@@ -1095,6 +1134,7 @@ mod tests {
|
|||||||
Arguments {
|
Arguments {
|
||||||
kitchensink: PathBuf::from("substrate-node"),
|
kitchensink: PathBuf::from("substrate-node"),
|
||||||
eth_proxy: PathBuf::from("eth-rpc"),
|
eth_proxy: PathBuf::from("eth-rpc"),
|
||||||
|
use_kitchensink_not_dev_node: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ pub trait Node: EthereumNode {
|
|||||||
/// Create a new uninitialized instance.
|
/// Create a new uninitialized instance.
|
||||||
fn new(config: &Arguments) -> Self;
|
fn new(config: &Arguments) -> Self;
|
||||||
|
|
||||||
|
/// Returns the identifier of the node.
|
||||||
|
fn id(&self) -> usize;
|
||||||
|
|
||||||
/// Spawns a node configured according to the genesis json.
|
/// Spawns a node configured according to the genesis json.
|
||||||
///
|
///
|
||||||
/// Blocking until it's ready to accept transactions.
|
/// Blocking until it's ready to accept transactions.
|
||||||
@@ -36,7 +39,7 @@ pub trait Node: EthereumNode {
|
|||||||
|
|
||||||
/// Given a list of targets from the metadata file, this function determines if the metadata
|
/// Given a list of targets from the metadata file, this function determines if the metadata
|
||||||
/// file can be ran on this node or not.
|
/// file can be ran on this node or not.
|
||||||
fn matches_target(&self, targets: Option<&[String]>) -> bool;
|
fn matches_target(targets: Option<&[String]>) -> bool;
|
||||||
|
|
||||||
/// Returns the EVM version of the node.
|
/// Returns the EVM version of the node.
|
||||||
fn evm_version() -> EVMVersion;
|
fn evm_version() -> EVMVersion;
|
||||||
|
|||||||
+17
-4
@@ -9,6 +9,7 @@ use revive_dt_common::cached_fs::read_to_string;
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use revive_dt_config::Arguments;
|
use revive_dt_config::Arguments;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
|
|
||||||
@@ -43,8 +44,10 @@ where
|
|||||||
nodes.push(
|
nodes.push(
|
||||||
handle
|
handle
|
||||||
.join()
|
.join()
|
||||||
.map_err(|error| anyhow::anyhow!("failed to spawn node: {:?}", error))?
|
.map_err(|error| anyhow::anyhow!("failed to spawn node: {:?}", error))
|
||||||
.map_err(|error| anyhow::anyhow!("node failed to spawn: {error}"))?,
|
.context("Failed to join node spawn thread")?
|
||||||
|
.map_err(|error| anyhow::anyhow!("node failed to spawn: {error}"))
|
||||||
|
.context("Node failed to spawn")?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +66,17 @@ where
|
|||||||
|
|
||||||
fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Result<T> {
|
fn spawn_node<T: Node + Send>(args: &Arguments, genesis: String) -> anyhow::Result<T> {
|
||||||
let mut node = T::new(args);
|
let mut node = T::new(args);
|
||||||
tracing::info!("starting node: {}", node.connection_string());
|
info!(
|
||||||
node.spawn(genesis)?;
|
id = node.id(),
|
||||||
|
connection_string = node.connection_string(),
|
||||||
|
"Spawning node"
|
||||||
|
);
|
||||||
|
node.spawn(genesis)
|
||||||
|
.context("Failed to spawn node process")?;
|
||||||
|
info!(
|
||||||
|
id = node.id(),
|
||||||
|
connection_string = node.connection_string(),
|
||||||
|
"Spawned node"
|
||||||
|
);
|
||||||
Ok(node)
|
Ok(node)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,15 @@ revive-dt-config = { workspace = true }
|
|||||||
revive-dt-format = { workspace = true }
|
revive-dt-format = { workspace = true }
|
||||||
revive-dt-compiler = { workspace = true }
|
revive-dt-compiler = { workspace = true }
|
||||||
|
|
||||||
|
alloy-primitives = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
tracing = { workspace = true }
|
paste = { workspace = true }
|
||||||
|
indexmap = { workspace = true, features = ["serde"] }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
serde_with = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
tracing = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -0,0 +1,549 @@
|
|||||||
|
//! Implementation of the report aggregator task which consumes the events sent by the various
|
||||||
|
//! reporters and combines them into a single unified report.
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||||
|
fs::OpenOptions,
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
|
use alloy_primitives::Address;
|
||||||
|
use anyhow::{Context as _, Result};
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode, SolcCompiler};
|
||||||
|
use revive_dt_config::{Arguments, TestingPlatform};
|
||||||
|
use revive_dt_format::{case::CaseIdx, corpus::Corpus, metadata::ContractInstance};
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde_with::{DisplayFromStr, serde_as};
|
||||||
|
use tokio::sync::{
|
||||||
|
broadcast::{Sender, channel},
|
||||||
|
mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
|
||||||
|
};
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
pub struct ReportAggregator {
|
||||||
|
/* Internal Report State */
|
||||||
|
report: Report,
|
||||||
|
remaining_cases: HashMap<MetadataFilePath, HashMap<Mode, HashSet<CaseIdx>>>,
|
||||||
|
/* Channels */
|
||||||
|
runner_tx: Option<UnboundedSender<RunnerEvent>>,
|
||||||
|
runner_rx: UnboundedReceiver<RunnerEvent>,
|
||||||
|
listener_tx: Sender<ReporterEvent>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportAggregator {
|
||||||
|
pub fn new(config: Arguments) -> Self {
|
||||||
|
let (runner_tx, runner_rx) = unbounded_channel::<RunnerEvent>();
|
||||||
|
let (listener_tx, _) = channel::<ReporterEvent>(1024);
|
||||||
|
Self {
|
||||||
|
report: Report::new(config),
|
||||||
|
remaining_cases: Default::default(),
|
||||||
|
runner_tx: Some(runner_tx),
|
||||||
|
runner_rx,
|
||||||
|
listener_tx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_task(mut self) -> (Reporter, impl Future<Output = Result<()>>) {
|
||||||
|
let reporter = self
|
||||||
|
.runner_tx
|
||||||
|
.take()
|
||||||
|
.map(Into::into)
|
||||||
|
.expect("Can't fail since this can only be called once");
|
||||||
|
(reporter, async move { self.aggregate().await })
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn aggregate(mut self) -> Result<()> {
|
||||||
|
debug!("Starting to aggregate report");
|
||||||
|
|
||||||
|
while let Some(event) = self.runner_rx.recv().await {
|
||||||
|
debug!(?event, "Received Event");
|
||||||
|
match event {
|
||||||
|
RunnerEvent::SubscribeToEvents(event) => {
|
||||||
|
self.handle_subscribe_to_events_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::CorpusFileDiscovery(event) => {
|
||||||
|
self.handle_corpus_file_discovered_event(*event)
|
||||||
|
}
|
||||||
|
RunnerEvent::MetadataFileDiscovery(event) => {
|
||||||
|
self.handle_metadata_file_discovery_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::TestCaseDiscovery(event) => {
|
||||||
|
self.handle_test_case_discovery(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::TestSucceeded(event) => {
|
||||||
|
self.handle_test_succeeded_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::TestFailed(event) => {
|
||||||
|
self.handle_test_failed_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::TestIgnored(event) => {
|
||||||
|
self.handle_test_ignored_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::LeaderNodeAssigned(event) => {
|
||||||
|
self.handle_leader_node_assigned_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::FollowerNodeAssigned(event) => {
|
||||||
|
self.handle_follower_node_assigned_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::PreLinkContractsCompilationSucceeded(event) => {
|
||||||
|
self.handle_pre_link_contracts_compilation_succeeded_event(*event)
|
||||||
|
}
|
||||||
|
RunnerEvent::PostLinkContractsCompilationSucceeded(event) => {
|
||||||
|
self.handle_post_link_contracts_compilation_succeeded_event(*event)
|
||||||
|
}
|
||||||
|
RunnerEvent::PreLinkContractsCompilationFailed(event) => {
|
||||||
|
self.handle_pre_link_contracts_compilation_failed_event(*event)
|
||||||
|
}
|
||||||
|
RunnerEvent::PostLinkContractsCompilationFailed(event) => {
|
||||||
|
self.handle_post_link_contracts_compilation_failed_event(*event)
|
||||||
|
}
|
||||||
|
RunnerEvent::LibrariesDeployed(event) => {
|
||||||
|
self.handle_libraries_deployed_event(*event);
|
||||||
|
}
|
||||||
|
RunnerEvent::ContractDeployed(event) => {
|
||||||
|
self.handle_contract_deployed_event(*event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("Report aggregation completed");
|
||||||
|
|
||||||
|
let file_name = {
|
||||||
|
let current_timestamp = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.context("System clock is before UNIX_EPOCH; cannot compute report timestamp")?
|
||||||
|
.as_secs();
|
||||||
|
let mut file_name = current_timestamp.to_string();
|
||||||
|
file_name.push_str(".json");
|
||||||
|
file_name
|
||||||
|
};
|
||||||
|
let file_path = self.report.config.directory().join(file_name);
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.read(false)
|
||||||
|
.open(&file_path)
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to open report file for writing: {}",
|
||||||
|
file_path.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
serde_json::to_writer_pretty(&file, &self.report).with_context(|| {
|
||||||
|
format!("Failed to serialize report JSON to {}", file_path.display())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_subscribe_to_events_event(&self, event: SubscribeToEventsEvent) {
|
||||||
|
let _ = event.tx.send(self.listener_tx.subscribe());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_corpus_file_discovered_event(&mut self, event: CorpusFileDiscoveryEvent) {
|
||||||
|
self.report.corpora.push(event.corpus);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_metadata_file_discovery_event(&mut self, event: MetadataFileDiscoveryEvent) {
|
||||||
|
self.report.metadata_files.insert(event.path.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_test_case_discovery(&mut self, event: TestCaseDiscoveryEvent) {
|
||||||
|
self.remaining_cases
|
||||||
|
.entry(event.test_specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(event.test_specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.insert(event.test_specifier.case_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_test_succeeded_event(&mut self, event: TestSucceededEvent) {
|
||||||
|
// Remove this from the set of cases we're tracking since it has completed.
|
||||||
|
self.remaining_cases
|
||||||
|
.entry(event.test_specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(event.test_specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.remove(&event.test_specifier.case_idx);
|
||||||
|
|
||||||
|
// Add information on the fact that the case was ignored to the report.
|
||||||
|
let test_case_report = self.test_case_report(&event.test_specifier);
|
||||||
|
test_case_report.status = Some(TestCaseStatus::Succeeded {
|
||||||
|
steps_executed: event.steps_executed,
|
||||||
|
});
|
||||||
|
self.handle_post_test_case_status_update(&event.test_specifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_test_failed_event(&mut self, event: TestFailedEvent) {
|
||||||
|
// Remove this from the set of cases we're tracking since it has completed.
|
||||||
|
self.remaining_cases
|
||||||
|
.entry(event.test_specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(event.test_specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.remove(&event.test_specifier.case_idx);
|
||||||
|
|
||||||
|
// Add information on the fact that the case was ignored to the report.
|
||||||
|
let test_case_report = self.test_case_report(&event.test_specifier);
|
||||||
|
test_case_report.status = Some(TestCaseStatus::Failed {
|
||||||
|
reason: event.reason,
|
||||||
|
});
|
||||||
|
self.handle_post_test_case_status_update(&event.test_specifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_test_ignored_event(&mut self, event: TestIgnoredEvent) {
|
||||||
|
// Remove this from the set of cases we're tracking since it has completed.
|
||||||
|
self.remaining_cases
|
||||||
|
.entry(event.test_specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(event.test_specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.remove(&event.test_specifier.case_idx);
|
||||||
|
|
||||||
|
// Add information on the fact that the case was ignored to the report.
|
||||||
|
let test_case_report = self.test_case_report(&event.test_specifier);
|
||||||
|
test_case_report.status = Some(TestCaseStatus::Ignored {
|
||||||
|
reason: event.reason,
|
||||||
|
additional_fields: event.additional_fields,
|
||||||
|
});
|
||||||
|
self.handle_post_test_case_status_update(&event.test_specifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_post_test_case_status_update(&mut self, specifier: &TestSpecifier) {
|
||||||
|
let remaining_cases = self
|
||||||
|
.remaining_cases
|
||||||
|
.entry(specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(specifier.solc_mode.clone())
|
||||||
|
.or_default();
|
||||||
|
if !remaining_cases.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let case_status = self
|
||||||
|
.report
|
||||||
|
.test_case_information
|
||||||
|
.entry(specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.iter()
|
||||||
|
.map(|(case_idx, case_report)| {
|
||||||
|
(
|
||||||
|
*case_idx,
|
||||||
|
case_report.status.clone().expect("Can't be uninitialized"),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<BTreeMap<_, _>>();
|
||||||
|
let event = ReporterEvent::MetadataFileSolcModeCombinationExecutionCompleted {
|
||||||
|
metadata_file_path: specifier.metadata_file_path.clone().into(),
|
||||||
|
mode: specifier.solc_mode.clone(),
|
||||||
|
case_status,
|
||||||
|
};
|
||||||
|
|
||||||
|
// According to the documentation on send, the sending fails if there are no more receiver
|
||||||
|
// handles. Therefore, this isn't an error that we want to bubble up or anything. If we fail
|
||||||
|
// to send then we ignore the error.
|
||||||
|
let _ = self.listener_tx.send(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_leader_node_assigned_event(&mut self, event: LeaderNodeAssignedEvent) {
|
||||||
|
let execution_information = self.execution_information(&ExecutionSpecifier {
|
||||||
|
test_specifier: event.test_specifier,
|
||||||
|
node_id: event.id,
|
||||||
|
node_designation: NodeDesignation::Leader,
|
||||||
|
});
|
||||||
|
execution_information.node = Some(TestCaseNodeInformation {
|
||||||
|
id: event.id,
|
||||||
|
platform: event.platform,
|
||||||
|
connection_string: event.connection_string,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_follower_node_assigned_event(&mut self, event: FollowerNodeAssignedEvent) {
|
||||||
|
let execution_information = self.execution_information(&ExecutionSpecifier {
|
||||||
|
test_specifier: event.test_specifier,
|
||||||
|
node_id: event.id,
|
||||||
|
node_designation: NodeDesignation::Follower,
|
||||||
|
});
|
||||||
|
execution_information.node = Some(TestCaseNodeInformation {
|
||||||
|
id: event.id,
|
||||||
|
platform: event.platform,
|
||||||
|
connection_string: event.connection_string,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_pre_link_contracts_compilation_succeeded_event(
|
||||||
|
&mut self,
|
||||||
|
event: PreLinkContractsCompilationSucceededEvent,
|
||||||
|
) {
|
||||||
|
let include_input = self.report.config.report_include_compiler_input;
|
||||||
|
let include_output = self.report.config.report_include_compiler_output;
|
||||||
|
|
||||||
|
let execution_information = self.execution_information(&event.execution_specifier);
|
||||||
|
|
||||||
|
let compiler_input = if include_input {
|
||||||
|
event.compiler_input
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let compiler_output = if include_output {
|
||||||
|
Some(event.compiler_output)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
execution_information.pre_link_compilation_status = Some(CompilationStatus::Success {
|
||||||
|
is_cached: event.is_cached,
|
||||||
|
solc_info: event.solc_info,
|
||||||
|
compiler_input,
|
||||||
|
compiler_output,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_post_link_contracts_compilation_succeeded_event(
|
||||||
|
&mut self,
|
||||||
|
event: PostLinkContractsCompilationSucceededEvent,
|
||||||
|
) {
|
||||||
|
let include_input = self.report.config.report_include_compiler_input;
|
||||||
|
let include_output = self.report.config.report_include_compiler_output;
|
||||||
|
|
||||||
|
let execution_information = self.execution_information(&event.execution_specifier);
|
||||||
|
|
||||||
|
let compiler_input = if include_input {
|
||||||
|
event.compiler_input
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let compiler_output = if include_output {
|
||||||
|
Some(event.compiler_output)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
execution_information.post_link_compilation_status = Some(CompilationStatus::Success {
|
||||||
|
is_cached: event.is_cached,
|
||||||
|
solc_info: event.solc_info,
|
||||||
|
compiler_input,
|
||||||
|
compiler_output,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_pre_link_contracts_compilation_failed_event(
|
||||||
|
&mut self,
|
||||||
|
event: PreLinkContractsCompilationFailedEvent,
|
||||||
|
) {
|
||||||
|
let include_input = self.report.config.report_include_compiler_input;
|
||||||
|
|
||||||
|
let execution_information = self.execution_information(&event.execution_specifier);
|
||||||
|
|
||||||
|
let compiler_input = if include_input {
|
||||||
|
event.compiler_input
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
execution_information.pre_link_compilation_status = Some(CompilationStatus::Failure {
|
||||||
|
reason: event.reason,
|
||||||
|
solc_info: event.solc_info,
|
||||||
|
compiler_input,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_post_link_contracts_compilation_failed_event(
|
||||||
|
&mut self,
|
||||||
|
event: PostLinkContractsCompilationFailedEvent,
|
||||||
|
) {
|
||||||
|
let include_input = self.report.config.report_include_compiler_input;
|
||||||
|
|
||||||
|
let execution_information = self.execution_information(&event.execution_specifier);
|
||||||
|
|
||||||
|
let compiler_input = if include_input {
|
||||||
|
event.compiler_input
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
execution_information.post_link_compilation_status = Some(CompilationStatus::Failure {
|
||||||
|
reason: event.reason,
|
||||||
|
solc_info: event.solc_info,
|
||||||
|
compiler_input,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_libraries_deployed_event(&mut self, event: LibrariesDeployedEvent) {
|
||||||
|
self.execution_information(&event.execution_specifier)
|
||||||
|
.deployed_libraries = Some(event.libraries);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_contract_deployed_event(&mut self, event: ContractDeployedEvent) {
|
||||||
|
self.execution_information(&event.execution_specifier)
|
||||||
|
.deployed_contracts
|
||||||
|
.get_or_insert_default()
|
||||||
|
.insert(event.contract_instance, event.address);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut TestCaseReport {
|
||||||
|
self.report
|
||||||
|
.test_case_information
|
||||||
|
.entry(specifier.metadata_file_path.clone().into())
|
||||||
|
.or_default()
|
||||||
|
.entry(specifier.solc_mode.clone())
|
||||||
|
.or_default()
|
||||||
|
.entry(specifier.case_idx)
|
||||||
|
.or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execution_information(
|
||||||
|
&mut self,
|
||||||
|
specifier: &ExecutionSpecifier,
|
||||||
|
) -> &mut ExecutionInformation {
|
||||||
|
let test_case_report = self.test_case_report(&specifier.test_specifier);
|
||||||
|
match specifier.node_designation {
|
||||||
|
NodeDesignation::Leader => test_case_report
|
||||||
|
.leader_execution_information
|
||||||
|
.get_or_insert_default(),
|
||||||
|
NodeDesignation::Follower => test_case_report
|
||||||
|
.follower_execution_information
|
||||||
|
.get_or_insert_default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[serde_as]
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
pub struct Report {
|
||||||
|
/// The configuration that the tool was started up with.
|
||||||
|
pub config: Arguments,
|
||||||
|
/// The platform of the leader chain.
|
||||||
|
pub leader_platform: TestingPlatform,
|
||||||
|
/// The platform of the follower chain.
|
||||||
|
pub follower_platform: TestingPlatform,
|
||||||
|
/// The list of corpus files that the tool found.
|
||||||
|
pub corpora: Vec<Corpus>,
|
||||||
|
/// The list of metadata files that were found by the tool.
|
||||||
|
pub metadata_files: BTreeSet<MetadataFilePath>,
|
||||||
|
/// Information relating to each test case.
|
||||||
|
#[serde_as(as = "BTreeMap<_, HashMap<DisplayFromStr, BTreeMap<DisplayFromStr, _>>>")]
|
||||||
|
pub test_case_information:
|
||||||
|
BTreeMap<MetadataFilePath, HashMap<Mode, BTreeMap<CaseIdx, TestCaseReport>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Report {
|
||||||
|
pub fn new(config: Arguments) -> Self {
|
||||||
|
Self {
|
||||||
|
leader_platform: config.leader,
|
||||||
|
follower_platform: config.follower,
|
||||||
|
config,
|
||||||
|
corpora: Default::default(),
|
||||||
|
metadata_files: Default::default(),
|
||||||
|
test_case_information: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Default)]
|
||||||
|
pub struct TestCaseReport {
|
||||||
|
/// Information on the status of the test case and whether it succeeded, failed, or was ignored.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub status: Option<TestCaseStatus>,
|
||||||
|
/// Information related to the execution on the leader.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub leader_execution_information: Option<ExecutionInformation>,
|
||||||
|
/// Information related to the execution on the follower.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub follower_execution_information: Option<ExecutionInformation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information related to the status of the test. Could be that the test succeeded, failed, or that
|
||||||
|
/// it was ignored.
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
#[serde(tag = "status")]
|
||||||
|
pub enum TestCaseStatus {
|
||||||
|
/// The test case succeeded.
|
||||||
|
Succeeded {
|
||||||
|
/// The number of steps of the case that were executed.
|
||||||
|
steps_executed: usize,
|
||||||
|
},
|
||||||
|
/// The test case failed.
|
||||||
|
Failed {
|
||||||
|
/// The reason for the failure of the test case.
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
/// The test case was ignored. This variant carries information related to why it was ignored.
|
||||||
|
Ignored {
|
||||||
|
/// The reason behind the test case being ignored.
|
||||||
|
reason: String,
|
||||||
|
/// Additional fields that describe more information on why the test case is ignored.
|
||||||
|
#[serde(flatten)]
|
||||||
|
additional_fields: IndexMap<String, serde_json::Value>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information related to the leader or follower node that's being used to execute the step.
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
pub struct TestCaseNodeInformation {
|
||||||
|
/// The ID of the node that this case is being executed on.
|
||||||
|
pub id: usize,
|
||||||
|
/// The platform of the node.
|
||||||
|
pub platform: TestingPlatform,
|
||||||
|
/// The connection string of the node.
|
||||||
|
pub connection_string: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Execution information tied to the leader or the follower.
|
||||||
|
#[derive(Clone, Debug, Default, Serialize)]
|
||||||
|
pub struct ExecutionInformation {
|
||||||
|
/// Information related to the node assigned to this test case.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub node: Option<TestCaseNodeInformation>,
|
||||||
|
/// Information on the pre-link compiled contracts.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub pre_link_compilation_status: Option<CompilationStatus>,
|
||||||
|
/// Information on the post-link compiled contracts.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub post_link_compilation_status: Option<CompilationStatus>,
|
||||||
|
/// Information on the deployed libraries.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub deployed_libraries: Option<BTreeMap<ContractInstance, Address>>,
|
||||||
|
/// Information on the deployed contracts.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub deployed_contracts: Option<BTreeMap<ContractInstance, Address>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information related to compilation
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
#[serde(tag = "status")]
|
||||||
|
pub enum CompilationStatus {
|
||||||
|
/// The compilation was successful.
|
||||||
|
Success {
|
||||||
|
/// A flag with information on whether the compilation artifacts were cached or not.
|
||||||
|
is_cached: bool,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler to compile the contracts. This is only included if
|
||||||
|
/// the appropriate flag is set in the CLI configuration and if the contracts were not
|
||||||
|
/// cached and the compiler was invoked.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
/// The output of the compiler. This is only included if the appropriate flag is set in the
|
||||||
|
/// CLI configurations.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
compiler_output: Option<CompilerOutput>,
|
||||||
|
},
|
||||||
|
/// The compilation failed.
|
||||||
|
Failure {
|
||||||
|
/// The failure reason.
|
||||||
|
reason: String,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler to compile the contracts. This is only included if
|
||||||
|
/// the appropriate flag is set in the CLI configuration and if the contracts were not
|
||||||
|
/// cached and the compiler was invoked.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
//! The report analyzer enriches the raw report data.
|
|
||||||
|
|
||||||
use revive_dt_compiler::CompilerOutput;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::reporter::CompilationTask;
|
|
||||||
|
|
||||||
/// Provides insights into how well the compilers perform.
|
|
||||||
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, PartialOrd)]
|
|
||||||
pub struct CompilerStatistics {
|
|
||||||
/// The sum of contracts observed.
|
|
||||||
pub n_contracts: usize,
|
|
||||||
/// The mean size of compiled contracts.
|
|
||||||
pub mean_code_size: usize,
|
|
||||||
/// The mean size of the optimized YUL IR.
|
|
||||||
pub mean_yul_size: usize,
|
|
||||||
/// Is a proxy because the YUL also contains a lot of comments.
|
|
||||||
pub yul_to_bytecode_size_ratio: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CompilerStatistics {
|
|
||||||
/// Cumulatively update the statistics with the next compiler task.
|
|
||||||
pub fn sample(&mut self, compilation_task: &CompilationTask) {
|
|
||||||
let Some(CompilerOutput { contracts }) = &compilation_task.json_output else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
for (_solidity, contracts) in contracts.iter() {
|
|
||||||
for (_name, (bytecode, _)) in contracts.iter() {
|
|
||||||
// The EVM bytecode can be unlinked and thus is not necessarily a decodable hex
|
|
||||||
// string; for our statistics this is a good enough approximation.
|
|
||||||
let bytecode_size = bytecode.len() / 2;
|
|
||||||
|
|
||||||
// TODO: for the time being we set the yul_size to be zero. We need to change this
|
|
||||||
// when we overhaul the reporting.
|
|
||||||
|
|
||||||
self.update_sizes(bytecode_size, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates the size statistics cumulatively.
|
|
||||||
fn update_sizes(&mut self, bytecode_size: usize, yul_size: usize) {
|
|
||||||
let n_previous = self.n_contracts;
|
|
||||||
let n_current = self.n_contracts + 1;
|
|
||||||
|
|
||||||
self.n_contracts = n_current;
|
|
||||||
|
|
||||||
self.mean_code_size = (n_previous * self.mean_code_size + bytecode_size) / n_current;
|
|
||||||
self.mean_yul_size = (n_previous * self.mean_yul_size + yul_size) / n_current;
|
|
||||||
|
|
||||||
if self.mean_code_size > 0 {
|
|
||||||
self.yul_to_bytecode_size_ratio =
|
|
||||||
self.mean_yul_size as f32 / self.mean_code_size as f32;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::CompilerStatistics;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn compiler_statistics() {
|
|
||||||
let mut received = CompilerStatistics::default();
|
|
||||||
received.update_sizes(0, 0);
|
|
||||||
received.update_sizes(3, 37);
|
|
||||||
received.update_sizes(123, 456);
|
|
||||||
|
|
||||||
let mean_code_size = 41; // rounding error from integer truncation
|
|
||||||
let mean_yul_size = 164;
|
|
||||||
let expected = CompilerStatistics {
|
|
||||||
n_contracts: 3,
|
|
||||||
mean_code_size,
|
|
||||||
mean_yul_size,
|
|
||||||
yul_to_bytecode_size_ratio: mean_yul_size as f32 / mean_code_size as f32,
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(received, expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
//! Common types and functions used throughout the crate.
|
||||||
|
|
||||||
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
|
use revive_dt_common::define_wrapper_type;
|
||||||
|
use revive_dt_compiler::Mode;
|
||||||
|
use revive_dt_format::{case::CaseIdx, input::StepIdx};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
define_wrapper_type!(
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
pub struct MetadataFilePath(PathBuf);
|
||||||
|
);
|
||||||
|
|
||||||
|
/// An absolute specifier for a test.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct TestSpecifier {
|
||||||
|
pub solc_mode: Mode,
|
||||||
|
pub metadata_file_path: PathBuf,
|
||||||
|
pub case_idx: CaseIdx,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An absolute path for a test that also includes information about the node that it's assigned to
|
||||||
|
/// and whether it's the leader or follower.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct ExecutionSpecifier {
|
||||||
|
pub test_specifier: Arc<TestSpecifier>,
|
||||||
|
pub node_id: usize,
|
||||||
|
pub node_designation: NodeDesignation,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub enum NodeDesignation {
|
||||||
|
Leader,
|
||||||
|
Follower,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct StepExecutionSpecifier {
|
||||||
|
pub execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
pub step_idx: StepIdx,
|
||||||
|
}
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
//! The revive differential tests reporting facility.
|
//! This crate implements the reporting infrastructure for the differential testing tool.
|
||||||
|
|
||||||
pub mod analyzer;
|
mod aggregator;
|
||||||
pub mod reporter;
|
mod common;
|
||||||
|
mod reporter_event;
|
||||||
|
mod runner_event;
|
||||||
|
|
||||||
|
pub use aggregator::*;
|
||||||
|
pub use common::*;
|
||||||
|
pub use reporter_event::*;
|
||||||
|
pub use runner_event::*;
|
||||||
|
|||||||
@@ -1,236 +0,0 @@
|
|||||||
//! The reporter is the central place observing test execution by collecting data.
|
|
||||||
//!
|
|
||||||
//! The data collected gives useful insights into the outcome of the test run
|
|
||||||
//! and helps identifying and reproducing failing cases.
|
|
||||||
|
|
||||||
use std::{
|
|
||||||
collections::HashMap,
|
|
||||||
fs::{self, File, create_dir_all},
|
|
||||||
path::PathBuf,
|
|
||||||
sync::{Mutex, OnceLock},
|
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use revive_dt_common::types::Mode;
|
|
||||||
use revive_dt_compiler::{CompilerInput, CompilerOutput};
|
|
||||||
use revive_dt_config::{Arguments, TestingPlatform};
|
|
||||||
use revive_dt_format::corpus::Corpus;
|
|
||||||
|
|
||||||
use crate::analyzer::CompilerStatistics;
|
|
||||||
|
|
||||||
pub(crate) static REPORTER: OnceLock<Mutex<Report>> = OnceLock::new();
|
|
||||||
|
|
||||||
/// The `Report` datastructure stores all relevant inforamtion required for generating reports.
|
|
||||||
#[derive(Clone, Debug, Default, Serialize)]
|
|
||||||
pub struct Report {
|
|
||||||
/// The configuration used during the test.
|
|
||||||
pub config: Arguments,
|
|
||||||
/// The observed test corpora.
|
|
||||||
pub corpora: Vec<Corpus>,
|
|
||||||
/// The observed test definitions.
|
|
||||||
pub metadata_files: Vec<PathBuf>,
|
|
||||||
/// The observed compilation results.
|
|
||||||
pub compiler_results: HashMap<TestingPlatform, Vec<CompilationResult>>,
|
|
||||||
/// The observed compilation statistics.
|
|
||||||
pub compiler_statistics: HashMap<TestingPlatform, CompilerStatistics>,
|
|
||||||
/// The file name this is serialized to.
|
|
||||||
#[serde(skip)]
|
|
||||||
directory: PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Contains a compiled contract.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
pub struct CompilationTask {
|
|
||||||
/// The observed compiler input.
|
|
||||||
pub json_input: CompilerInput,
|
|
||||||
/// The observed compiler output.
|
|
||||||
pub json_output: Option<CompilerOutput>,
|
|
||||||
/// The observed compiler mode.
|
|
||||||
pub mode: Mode,
|
|
||||||
/// The observed compiler version.
|
|
||||||
pub compiler_version: String,
|
|
||||||
/// The observed error, if any.
|
|
||||||
pub error: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents a report about a compilation task.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
pub struct CompilationResult {
|
|
||||||
/// The observed compilation task.
|
|
||||||
pub compilation_task: CompilationTask,
|
|
||||||
/// The linked span.
|
|
||||||
pub span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The [Span] struct indicates the context of what is being reported.
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize)]
|
|
||||||
pub struct Span {
|
|
||||||
/// The corpus index this belongs to.
|
|
||||||
corpus: usize,
|
|
||||||
/// The metadata file this belongs to.
|
|
||||||
metadata_file: usize,
|
|
||||||
/// The index of the case definition this belongs to.
|
|
||||||
case: usize,
|
|
||||||
/// The index of the case input this belongs to.
|
|
||||||
input: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Report {
|
|
||||||
/// The file name where this report will be written to.
|
|
||||||
pub const FILE_NAME: &str = "report.json";
|
|
||||||
|
|
||||||
/// The [Span] is expected to initialize the reporter by providing the config.
|
|
||||||
const INITIALIZED_VIA_SPAN: &str = "requires a Span which initializes the reporter";
|
|
||||||
|
|
||||||
/// Create a new [Report].
|
|
||||||
fn new(config: Arguments) -> anyhow::Result<Self> {
|
|
||||||
let now = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_millis();
|
|
||||||
|
|
||||||
let directory = config.directory().join("report").join(format!("{now}"));
|
|
||||||
if !directory.exists() {
|
|
||||||
create_dir_all(&directory)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
config,
|
|
||||||
directory,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a compilation task to the report.
|
|
||||||
pub fn compilation(span: Span, platform: TestingPlatform, compilation_task: CompilationTask) {
|
|
||||||
let mut report = REPORTER
|
|
||||||
.get()
|
|
||||||
.expect(Report::INITIALIZED_VIA_SPAN)
|
|
||||||
.lock()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
report
|
|
||||||
.compiler_statistics
|
|
||||||
.entry(platform)
|
|
||||||
.or_default()
|
|
||||||
.sample(&compilation_task);
|
|
||||||
|
|
||||||
report
|
|
||||||
.compiler_results
|
|
||||||
.entry(platform)
|
|
||||||
.or_default()
|
|
||||||
.push(CompilationResult {
|
|
||||||
compilation_task,
|
|
||||||
span,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write the report to disk.
|
|
||||||
pub fn save() -> anyhow::Result<()> {
|
|
||||||
let Some(reporter) = REPORTER.get() else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
let report = reporter.lock().unwrap();
|
|
||||||
|
|
||||||
if let Err(error) = report.write_to_file() {
|
|
||||||
anyhow::bail!("can not write report: {error}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if report.config.extract_problems {
|
|
||||||
if let Err(error) = report.save_compiler_problems() {
|
|
||||||
anyhow::bail!("can not write compiler problems: {error}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write compiler problems to disk for later debugging.
|
|
||||||
pub fn save_compiler_problems(&self) -> anyhow::Result<()> {
|
|
||||||
for (platform, results) in self.compiler_results.iter() {
|
|
||||||
for result in results {
|
|
||||||
// ignore if there were no errors
|
|
||||||
if result.compilation_task.error.is_none() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = &self.metadata_files[result.span.metadata_file]
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.join(format!("{platform}_errors"));
|
|
||||||
if !path.exists() {
|
|
||||||
create_dir_all(path)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(error) = result.compilation_task.error.as_ref() {
|
|
||||||
fs::write(path.join("compiler_error.txt"), error)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(errors) = result.compilation_task.json_output.as_ref() {
|
|
||||||
let file = File::create(path.join("compiler_output.txt"))?;
|
|
||||||
serde_json::to_writer_pretty(file, &errors)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_to_file(&self) -> anyhow::Result<()> {
|
|
||||||
let path = self.directory.join(Self::FILE_NAME);
|
|
||||||
|
|
||||||
let file = File::create(&path).context(path.display().to_string())?;
|
|
||||||
serde_json::to_writer_pretty(file, &self)?;
|
|
||||||
|
|
||||||
tracing::info!("report written to: {}", path.display());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Span {
|
|
||||||
/// Create a new [Span] with case and input index at 0.
|
|
||||||
///
|
|
||||||
/// Initializes the reporting facility on the first call.
|
|
||||||
pub fn new(corpus: Corpus, config: Arguments) -> anyhow::Result<Self> {
|
|
||||||
let report = Mutex::new(Report::new(config)?);
|
|
||||||
let mut reporter = REPORTER.get_or_init(|| report).lock().unwrap();
|
|
||||||
reporter.corpora.push(corpus);
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
corpus: reporter.corpora.len() - 1,
|
|
||||||
metadata_file: 0,
|
|
||||||
case: 0,
|
|
||||||
input: 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advance to the next metadata file: Resets the case input index to 0.
|
|
||||||
pub fn next_metadata(&mut self, metadata_file: PathBuf) {
|
|
||||||
let mut reporter = REPORTER
|
|
||||||
.get()
|
|
||||||
.expect(Report::INITIALIZED_VIA_SPAN)
|
|
||||||
.lock()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
reporter.metadata_files.push(metadata_file);
|
|
||||||
|
|
||||||
self.metadata_file = reporter.metadata_files.len() - 1;
|
|
||||||
self.case = 0;
|
|
||||||
self.input = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advance to the next case: Increas the case index by one and resets the input index to 0.
|
|
||||||
pub fn next_case(&mut self) {
|
|
||||||
self.case += 1;
|
|
||||||
self.input = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advance to the next input.
|
|
||||||
pub fn next_input(&mut self) {
|
|
||||||
self.input += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//! A reporter event sent by the report aggregator to the various listeners.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use revive_dt_compiler::Mode;
|
||||||
|
use revive_dt_format::case::CaseIdx;
|
||||||
|
|
||||||
|
use crate::{MetadataFilePath, TestCaseStatus};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ReporterEvent {
|
||||||
|
/// An event sent by the reporter once an entire metadata file and solc mode combination has
|
||||||
|
/// finished execution.
|
||||||
|
MetadataFileSolcModeCombinationExecutionCompleted {
|
||||||
|
/// The path of the metadata file.
|
||||||
|
metadata_file_path: MetadataFilePath,
|
||||||
|
/// The Solc mode that this metadata file was executed in.
|
||||||
|
mode: Mode,
|
||||||
|
/// The status of each one of the cases.
|
||||||
|
case_status: BTreeMap<CaseIdx, TestCaseStatus>,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,633 @@
|
|||||||
|
//! The types associated with the events sent by the runner to the reporter.
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
|
use alloy_primitives::Address;
|
||||||
|
use anyhow::Context as _;
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
use revive_dt_compiler::{CompilerInput, CompilerOutput, SolcCompiler};
|
||||||
|
use revive_dt_config::TestingPlatform;
|
||||||
|
use revive_dt_format::metadata::Metadata;
|
||||||
|
use revive_dt_format::{corpus::Corpus, metadata::ContractInstance};
|
||||||
|
use tokio::sync::{broadcast, oneshot};
|
||||||
|
|
||||||
|
use crate::{ExecutionSpecifier, ReporterEvent, TestSpecifier, common::MetadataFilePath};
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_test_specific {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
pub fn [< report_ $variant_ident:snake _event >](
|
||||||
|
&self
|
||||||
|
$(, $bname: impl Into<$bty> )*
|
||||||
|
$(, $aname: impl Into<$aty> )*
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
self.report([< $variant_ident Event >] {
|
||||||
|
$skip_field: self.test_specifier.clone()
|
||||||
|
$(, $bname: $bname.into() )*
|
||||||
|
$(, $aname: $aname.into() )*
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_test_specific_by_parse {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )* ; $( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_test_specific!(
|
||||||
|
$ident, $variant_ident, $skip_field;
|
||||||
|
$( $bname : $bty, )* ; $( $aname : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_scan_before {
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
test_specifier : $skip_ty:ty,
|
||||||
|
$( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_test_specific_by_parse!(
|
||||||
|
$ident, $variant_ident, test_specifier;
|
||||||
|
$( $before : $bty, )* ; $( $after : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$name:ident : $ty:ty, $( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
$( $before : $bty, )* $name : $ty,
|
||||||
|
;
|
||||||
|
$( $after : $aty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
;
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_for_variant {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
) => {};
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
$( $field_ident:ident : $field_ty:ty ),+ $(,)?
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
;
|
||||||
|
$( $field_ident : $field_ty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_execution_specific {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
pub fn [< report_ $variant_ident:snake _event >](
|
||||||
|
&self
|
||||||
|
$(, $bname: impl Into<$bty> )*
|
||||||
|
$(, $aname: impl Into<$aty> )*
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
self.report([< $variant_ident Event >] {
|
||||||
|
$skip_field: self.execution_specifier.clone()
|
||||||
|
$(, $bname: $bname.into() )*
|
||||||
|
$(, $aname: $aname.into() )*
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_execution_specific_by_parse {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )* ; $( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_execution_specific!(
|
||||||
|
$ident, $variant_ident, $skip_field;
|
||||||
|
$( $bname : $bty, )* ; $( $aname : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_scan_before_exec {
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
execution_specifier : $skip_ty:ty,
|
||||||
|
$( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_execution_specific_by_parse!(
|
||||||
|
$ident, $variant_ident, execution_specifier;
|
||||||
|
$( $before : $bty, )* ; $( $after : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$name:ident : $ty:ty, $( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before_exec!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
$( $before : $bty, )* $name : $ty,
|
||||||
|
;
|
||||||
|
$( $after : $aty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
;
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_for_variant_exec {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
) => {};
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
$( $field_ident:ident : $field_ty:ty ),+ $(,)?
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before_exec!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
;
|
||||||
|
$( $field_ident : $field_ty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_step_execution_specific {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
pub fn [< report_ $variant_ident:snake _event >](
|
||||||
|
&self
|
||||||
|
$(, $bname: impl Into<$bty> )*
|
||||||
|
$(, $aname: impl Into<$aty> )*
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
self.report([< $variant_ident Event >] {
|
||||||
|
$skip_field: self.step_specifier.clone()
|
||||||
|
$(, $bname: $bname.into() )*
|
||||||
|
$(, $aname: $aname.into() )*
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_emit_step_execution_specific_by_parse {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident,
|
||||||
|
$skip_field:ident;
|
||||||
|
$( $bname:ident : $bty:ty, )* ; $( $aname:ident : $aty:ty, )*
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_step_execution_specific!(
|
||||||
|
$ident, $variant_ident, $skip_field;
|
||||||
|
$( $bname : $bty, )* ; $( $aname : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_scan_before_step {
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
step_specifier : $skip_ty:ty,
|
||||||
|
$( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_emit_step_execution_specific_by_parse!(
|
||||||
|
$ident, $variant_ident, step_specifier;
|
||||||
|
$( $before : $bty, )* ; $( $after : $aty, )*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
$name:ident : $ty:ty, $( $after:ident : $aty:ty, )*
|
||||||
|
;
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before_step!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
$( $before : $bty, )* $name : $ty,
|
||||||
|
;
|
||||||
|
$( $after : $aty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
(
|
||||||
|
$ident:ident, $variant_ident:ident;
|
||||||
|
$( $before:ident : $bty:ty, )*
|
||||||
|
;
|
||||||
|
;
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! __report_gen_for_variant_step {
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
) => {};
|
||||||
|
(
|
||||||
|
$ident:ident,
|
||||||
|
$variant_ident:ident;
|
||||||
|
$( $field_ident:ident : $field_ty:ty ),+ $(,)?
|
||||||
|
) => {
|
||||||
|
__report_gen_scan_before_step!(
|
||||||
|
$ident, $variant_ident;
|
||||||
|
;
|
||||||
|
$( $field_ident : $field_ty, )*
|
||||||
|
;
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Defines the runner-event which is sent from the test runners to the report aggregator.
|
||||||
|
///
|
||||||
|
/// This macro defines a number of things related to the reporting infrastructure and the interface
|
||||||
|
/// used. First of all, it defines the enum of all of the possible events that the runners can send
|
||||||
|
/// to the aggregator. For each one of the variants it defines a separate struct for it to allow the
|
||||||
|
/// variant field in the enum to be put in a [`Box`].
|
||||||
|
///
|
||||||
|
/// In addition to the above, it defines [`From`] implementations for the various event types for
|
||||||
|
/// the [`RunnerEvent`] enum essentially allowing for events such as [`CorpusFileDiscoveryEvent`] to
|
||||||
|
/// be converted into a [`RunnerEvent`].
|
||||||
|
///
|
||||||
|
/// In addition to the above, it also defines the [`RunnerEventReporter`] which is a wrapper around
|
||||||
|
/// an [`UnboundedSender`] allowing for events to be sent to the report aggregator.
|
||||||
|
///
|
||||||
|
/// With the above description, we can see that this macro defines almost all of the interface of
|
||||||
|
/// the reporting infrastructure, from the enum itself, to its associated types, and also to the
|
||||||
|
/// reporter that's used to report events to the aggregator.
|
||||||
|
///
|
||||||
|
/// [`UnboundedSender`]: tokio::sync::mpsc::UnboundedSender
|
||||||
|
macro_rules! define_event {
|
||||||
|
(
|
||||||
|
$(#[$enum_meta: meta])*
|
||||||
|
$vis: vis enum $ident: ident {
|
||||||
|
$(
|
||||||
|
$(#[$variant_meta: meta])*
|
||||||
|
$variant_ident: ident {
|
||||||
|
$(
|
||||||
|
$(#[$field_meta: meta])*
|
||||||
|
$field_ident: ident: $field_ty: ty
|
||||||
|
),* $(,)?
|
||||||
|
}
|
||||||
|
),* $(,)?
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
$(#[$enum_meta])*
|
||||||
|
#[derive(Debug)]
|
||||||
|
$vis enum $ident {
|
||||||
|
$(
|
||||||
|
$(#[$variant_meta])*
|
||||||
|
$variant_ident(Box<[<$variant_ident Event>]>)
|
||||||
|
),*
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
#[derive(Debug)]
|
||||||
|
$(#[$variant_meta])*
|
||||||
|
$vis struct [<$variant_ident Event>] {
|
||||||
|
$(
|
||||||
|
$(#[$field_meta])*
|
||||||
|
$vis $field_ident: $field_ty
|
||||||
|
),*
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
|
$(
|
||||||
|
impl From<[<$variant_ident Event>]> for $ident {
|
||||||
|
fn from(value: [<$variant_ident Event>]) -> Self {
|
||||||
|
Self::$variant_ident(Box::new(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
|
/// Provides a way to report events to the aggregator.
|
||||||
|
///
|
||||||
|
/// Under the hood, this is a wrapper around an [`UnboundedSender`] which abstracts away
|
||||||
|
/// the fact that channels are used and that implements high-level methods for reporting
|
||||||
|
/// various events to the aggregator.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct [< $ident Reporter >]($vis tokio::sync::mpsc::UnboundedSender<$ident>);
|
||||||
|
|
||||||
|
impl From<tokio::sync::mpsc::UnboundedSender<$ident>> for [< $ident Reporter >] {
|
||||||
|
fn from(value: tokio::sync::mpsc::UnboundedSender<$ident>) -> Self {
|
||||||
|
Self(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [< $ident Reporter >] {
|
||||||
|
pub fn test_specific_reporter(
|
||||||
|
&self,
|
||||||
|
test_specifier: impl Into<std::sync::Arc<crate::common::TestSpecifier>>
|
||||||
|
) -> [< $ident TestSpecificReporter >] {
|
||||||
|
[< $ident TestSpecificReporter >] {
|
||||||
|
reporter: self.clone(),
|
||||||
|
test_specifier: test_specifier.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
|
||||||
|
self.0.send(event.into()).map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
pub fn [< report_ $variant_ident:snake _event >](&self, $($field_ident: impl Into<$field_ty>),*) -> anyhow::Result<()> {
|
||||||
|
self.report([< $variant_ident Event >] {
|
||||||
|
$($field_ident: $field_ident.into()),*
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A reporter that's tied to a specific test case.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct [< $ident TestSpecificReporter >] {
|
||||||
|
$vis reporter: [< $ident Reporter >],
|
||||||
|
$vis test_specifier: std::sync::Arc<crate::common::TestSpecifier>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [< $ident TestSpecificReporter >] {
|
||||||
|
pub fn execution_specific_reporter(
|
||||||
|
&self,
|
||||||
|
node_id: impl Into<usize>,
|
||||||
|
node_designation: impl Into<$crate::common::NodeDesignation>
|
||||||
|
) -> [< $ident ExecutionSpecificReporter >] {
|
||||||
|
[< $ident ExecutionSpecificReporter >] {
|
||||||
|
reporter: self.reporter.clone(),
|
||||||
|
execution_specifier: Arc::new($crate::common::ExecutionSpecifier {
|
||||||
|
test_specifier: self.test_specifier.clone(),
|
||||||
|
node_id: node_id.into(),
|
||||||
|
node_designation: node_designation.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
|
||||||
|
self.reporter.report(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
__report_gen_for_variant! { $ident, $variant_ident; $( $field_ident : $field_ty ),* }
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A reporter that's tied to a specific execution of the test case such as execution on
|
||||||
|
/// a specific node like the leader or follower.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct [< $ident ExecutionSpecificReporter >] {
|
||||||
|
$vis reporter: [< $ident Reporter >],
|
||||||
|
$vis execution_specifier: std::sync::Arc<$crate::common::ExecutionSpecifier>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [< $ident ExecutionSpecificReporter >] {
|
||||||
|
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
|
||||||
|
self.reporter.report(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
__report_gen_for_variant_exec! { $ident, $variant_ident; $( $field_ident : $field_ty ),* }
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A reporter that's tied to a specific step execution
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct [< $ident StepExecutionSpecificReporter >] {
|
||||||
|
$vis reporter: [< $ident Reporter >],
|
||||||
|
$vis step_specifier: std::sync::Arc<$crate::common::StepExecutionSpecifier>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [< $ident StepExecutionSpecificReporter >] {
|
||||||
|
fn report(&self, event: impl Into<$ident>) -> anyhow::Result<()> {
|
||||||
|
self.reporter.report(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
__report_gen_for_variant_step! { $ident, $variant_ident; $( $field_ident : $field_ty ),* }
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
define_event! {
|
||||||
|
/// An event type that's sent by the test runners/drivers to the report aggregator.
|
||||||
|
pub(crate) enum RunnerEvent {
|
||||||
|
/// An event emitted by the reporter when it wishes to listen to events emitted by the
|
||||||
|
/// aggregator.
|
||||||
|
SubscribeToEvents {
|
||||||
|
/// The channel that the aggregator is to send the receive side of the channel on.
|
||||||
|
tx: oneshot::Sender<broadcast::Receiver<ReporterEvent>>
|
||||||
|
},
|
||||||
|
/// An event emitted by runners when they've discovered a corpus file.
|
||||||
|
CorpusFileDiscovery {
|
||||||
|
/// The contents of the corpus file.
|
||||||
|
corpus: Corpus
|
||||||
|
},
|
||||||
|
/// An event emitted by runners when they've discovered a metadata file.
|
||||||
|
MetadataFileDiscovery {
|
||||||
|
/// The path of the metadata file discovered.
|
||||||
|
path: MetadataFilePath,
|
||||||
|
/// The content of the metadata file.
|
||||||
|
metadata: Metadata
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when they discover a test case.
|
||||||
|
TestCaseDiscovery {
|
||||||
|
/// A specifier for the test that was discovered.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when a test case is ignored.
|
||||||
|
TestIgnored {
|
||||||
|
/// A specifier for the test that's been ignored.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
/// A reason for the test to be ignored.
|
||||||
|
reason: String,
|
||||||
|
/// Additional fields that describe more information on why the test was ignored.
|
||||||
|
additional_fields: IndexMap<String, serde_json::Value>
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when a test case has succeeded.
|
||||||
|
TestSucceeded {
|
||||||
|
/// A specifier for the test that succeeded.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
/// The number of steps of the case that were executed by the driver.
|
||||||
|
steps_executed: usize,
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when a test case has failed.
|
||||||
|
TestFailed {
|
||||||
|
/// A specifier for the test that succeeded.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
/// A reason for the failure of the test.
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
/// An event emitted when the test case is assigned a leader node.
|
||||||
|
LeaderNodeAssigned {
|
||||||
|
/// A specifier for the test that the assignment is for.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
/// The ID of the node that this case is being executed on.
|
||||||
|
id: usize,
|
||||||
|
/// The platform of the node.
|
||||||
|
platform: TestingPlatform,
|
||||||
|
/// The connection string of the node.
|
||||||
|
connection_string: String,
|
||||||
|
},
|
||||||
|
/// An event emitted when the test case is assigned a follower node.
|
||||||
|
FollowerNodeAssigned {
|
||||||
|
/// A specifier for the test that the assignment is for.
|
||||||
|
test_specifier: Arc<TestSpecifier>,
|
||||||
|
/// The ID of the node that this case is being executed on.
|
||||||
|
id: usize,
|
||||||
|
/// The platform of the node.
|
||||||
|
platform: TestingPlatform,
|
||||||
|
/// The connection string of the node.
|
||||||
|
connection_string: String,
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when the compilation of the contracts has succeeded
|
||||||
|
/// on the pre-link contracts.
|
||||||
|
PreLinkContractsCompilationSucceeded {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// A flag of whether the contract bytecode and ABI were cached or if they were compiled
|
||||||
|
/// anew.
|
||||||
|
is_cached: bool,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler - this is optional and not provided if the
|
||||||
|
/// contracts were obtained from the cache.
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
/// The output of the compiler.
|
||||||
|
compiler_output: CompilerOutput
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when the compilation of the contracts has succeeded
|
||||||
|
/// on the post-link contracts.
|
||||||
|
PostLinkContractsCompilationSucceeded {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// A flag of whether the contract bytecode and ABI were cached or if they were compiled
|
||||||
|
/// anew.
|
||||||
|
is_cached: bool,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler - this is optional and not provided if the
|
||||||
|
/// contracts were obtained from the cache.
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
/// The output of the compiler.
|
||||||
|
compiler_output: CompilerOutput
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when the compilation of the pre-link contract has
|
||||||
|
/// failed.
|
||||||
|
PreLinkContractsCompilationFailed {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler - this is optional and not provided if the
|
||||||
|
/// contracts were obtained from the cache.
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
/// The failure reason.
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when the compilation of the post-link contract has
|
||||||
|
/// failed.
|
||||||
|
PostLinkContractsCompilationFailed {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// The version and path of the solc compiler used to compile the contracts.
|
||||||
|
solc_info: SolcCompiler,
|
||||||
|
/// The input provided to the compiler - this is optional and not provided if the
|
||||||
|
/// contracts were obtained from the cache.
|
||||||
|
compiler_input: Option<CompilerInput>,
|
||||||
|
/// The failure reason.
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when a library has been deployed.
|
||||||
|
LibrariesDeployed {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// The addresses of the libraries that were deployed.
|
||||||
|
libraries: BTreeMap<ContractInstance, Address>
|
||||||
|
},
|
||||||
|
/// An event emitted by the runners when they've deployed a new contract.
|
||||||
|
ContractDeployed {
|
||||||
|
/// A specifier for the execution that's taking place.
|
||||||
|
execution_specifier: Arc<ExecutionSpecifier>,
|
||||||
|
/// The instance name of the contract.
|
||||||
|
contract_instance: ContractInstance,
|
||||||
|
/// The address of the contract.
|
||||||
|
address: Address
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An extension to the [`Reporter`] implemented by the macro.
|
||||||
|
impl RunnerEventReporter {
|
||||||
|
pub async fn subscribe(&self) -> anyhow::Result<broadcast::Receiver<ReporterEvent>> {
|
||||||
|
let (tx, rx) = oneshot::channel::<broadcast::Receiver<ReporterEvent>>();
|
||||||
|
self.report_subscribe_to_events_event(tx)
|
||||||
|
.context("Failed to send subscribe request to reporter task")?;
|
||||||
|
rx.await.map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type Reporter = RunnerEventReporter;
|
||||||
|
pub type TestSpecificReporter = RunnerEventTestSpecificReporter;
|
||||||
|
pub type ExecutionSpecificReporter = RunnerEventExecutionSpecificReporter;
|
||||||
@@ -19,3 +19,6 @@ reqwest = { workspace = true }
|
|||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
sha2 = { workspace = true }
|
sha2 = { workspace = true }
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use std::{
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::download::SolcDownloader;
|
use crate::download::SolcDownloader;
|
||||||
|
use anyhow::Context;
|
||||||
|
|
||||||
pub const SOLC_CACHE_DIRECTORY: &str = "solc";
|
pub const SOLC_CACHE_DIRECTORY: &str = "solc";
|
||||||
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
|
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
|
||||||
@@ -31,31 +32,52 @@ pub(crate) async fn get_or_download(
|
|||||||
return Ok(target_file);
|
return Ok(target_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
create_dir_all(target_directory)?;
|
create_dir_all(&target_directory).with_context(|| {
|
||||||
download_to_file(&target_file, downloader).await?;
|
format!(
|
||||||
|
"Failed to create solc cache directory: {}",
|
||||||
|
target_directory.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
download_to_file(&target_file, downloader)
|
||||||
|
.await
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to write downloaded solc to {}",
|
||||||
|
target_file.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
cache.insert(target_file.clone());
|
cache.insert(target_file.clone());
|
||||||
|
|
||||||
Ok(target_file)
|
Ok(target_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::Result<()> {
|
async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::Result<()> {
|
||||||
tracing::info!("caching file: {}", path.display());
|
|
||||||
|
|
||||||
let Ok(file) = File::create_new(path) else {
|
let Ok(file) = File::create_new(path) else {
|
||||||
tracing::debug!("cache file already exists: {}", path.display());
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
let mut permissions = file.metadata()?.permissions();
|
let mut permissions = file
|
||||||
|
.metadata()
|
||||||
|
.with_context(|| format!("Failed to read metadata for {}", path.display()))?
|
||||||
|
.permissions();
|
||||||
permissions.set_mode(permissions.mode() | 0o111);
|
permissions.set_mode(permissions.mode() | 0o111);
|
||||||
file.set_permissions(permissions)?;
|
file.set_permissions(permissions).with_context(|| {
|
||||||
|
format!("Failed to set executable permissions on {}", path.display())
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = BufWriter::new(file);
|
let mut file = BufWriter::new(file);
|
||||||
file.write_all(&downloader.download().await?)?;
|
file.write_all(
|
||||||
file.flush()?;
|
&downloader
|
||||||
|
.download()
|
||||||
|
.await
|
||||||
|
.context("Failed to download solc binary bytes")?,
|
||||||
|
)
|
||||||
|
.with_context(|| format!("Failed to write solc binary to {}", path.display()))?;
|
||||||
|
file.flush()
|
||||||
|
.with_context(|| format!("Failed to flush file {}", path.display()))?;
|
||||||
drop(file);
|
drop(file);
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
@@ -66,8 +88,20 @@ async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::R
|
|||||||
.stderr(std::process::Stdio::null())
|
.stderr(std::process::Stdio::null())
|
||||||
.stdout(std::process::Stdio::null())
|
.stdout(std::process::Stdio::null())
|
||||||
.stdout(std::process::Stdio::null())
|
.stdout(std::process::Stdio::null())
|
||||||
.spawn()?
|
.spawn()
|
||||||
.wait()?;
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to spawn xattr to remove quarantine attribute on {}",
|
||||||
|
path.display()
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.wait()
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed waiting for xattr operation to complete on {}",
|
||||||
|
path.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use semver::Version;
|
|||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
use crate::list::List;
|
use crate::list::List;
|
||||||
|
use anyhow::Context;
|
||||||
|
|
||||||
pub static LIST_CACHE: LazyLock<Mutex<HashMap<&'static str, List>>> =
|
pub static LIST_CACHE: LazyLock<Mutex<HashMap<&'static str, List>>> =
|
||||||
LazyLock::new(Default::default);
|
LazyLock::new(Default::default);
|
||||||
@@ -30,7 +31,12 @@ impl List {
|
|||||||
return Ok(list.clone());
|
return Ok(list.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let body: List = reqwest::get(url).await?.json().await?;
|
let body: List = reqwest::get(url)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("Failed to GET solc list from {url}"))?
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("Failed to deserialize solc list JSON from {url}"))?;
|
||||||
|
|
||||||
LIST_CACHE.lock().unwrap().insert(url, body.clone());
|
LIST_CACHE.lock().unwrap().insert(url, body.clone());
|
||||||
|
|
||||||
@@ -68,14 +74,15 @@ impl SolcDownloader {
|
|||||||
}),
|
}),
|
||||||
VersionOrRequirement::Requirement(requirement) => {
|
VersionOrRequirement::Requirement(requirement) => {
|
||||||
let Some(version) = List::download(list)
|
let Some(version) = List::download(list)
|
||||||
.await?
|
.await
|
||||||
|
.with_context(|| format!("Failed to download solc builds list from {list}"))?
|
||||||
.builds
|
.builds
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|build| build.version)
|
.map(|build| build.version)
|
||||||
.filter(|version| requirement.matches(version))
|
.filter(|version| requirement.matches(version))
|
||||||
.max()
|
.max()
|
||||||
else {
|
else {
|
||||||
anyhow::bail!("Failed to find a version that satisfies {requirement:?}");
|
anyhow::bail!("Failed to find a version that satisfies {requirement}");
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
version,
|
version,
|
||||||
@@ -107,12 +114,20 @@ impl SolcDownloader {
|
|||||||
/// Errors out if the download fails or the digest of the downloaded file
|
/// Errors out if the download fails or the digest of the downloaded file
|
||||||
/// mismatches the expected digest from the release [List].
|
/// mismatches the expected digest from the release [List].
|
||||||
pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
|
pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
|
||||||
tracing::info!("downloading solc: {self:?}");
|
let builds = List::download(self.list)
|
||||||
let builds = List::download(self.list).await?.builds;
|
.await
|
||||||
|
.with_context(|| format!("Failed to download solc builds list from {}", self.list))?
|
||||||
|
.builds;
|
||||||
let build = builds
|
let build = builds
|
||||||
.iter()
|
.iter()
|
||||||
.find(|build| build.version == self.version)
|
.find(|build| build.version == self.version)
|
||||||
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))?;
|
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Requested solc version {} was not found in builds list fetched from {}",
|
||||||
|
self.version, self.list
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let path = build.path.clone();
|
let path = build.path.clone();
|
||||||
let expected_digest = build
|
let expected_digest = build
|
||||||
@@ -122,7 +137,13 @@ impl SolcDownloader {
|
|||||||
.to_string();
|
.to_string();
|
||||||
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
|
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
|
||||||
|
|
||||||
let file = reqwest::get(url).await?.bytes().await?.to_vec();
|
let file = reqwest::get(&url)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("Failed to GET solc binary from {url}"))?
|
||||||
|
.bytes()
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("Failed to read solc binary bytes from {url}"))?
|
||||||
|
.to_vec();
|
||||||
|
|
||||||
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
||||||
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
//!
|
//!
|
||||||
//! [0]: https://binaries.soliditylang.org
|
//! [0]: https://binaries.soliditylang.org
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
|
||||||
use cache::get_or_download;
|
use cache::get_or_download;
|
||||||
use download::SolcDownloader;
|
use download::SolcDownloader;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use revive_dt_common::types::VersionOrRequirement;
|
use revive_dt_common::types::VersionOrRequirement;
|
||||||
|
|
||||||
@@ -14,6 +13,25 @@ pub mod cache;
|
|||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
|
|
||||||
|
/// Return a [`SolcDownloader`] which can be used to download a `solc`
|
||||||
|
/// binary or return the resolved version it will download.
|
||||||
|
async fn downloader(
|
||||||
|
version: impl Into<VersionOrRequirement>,
|
||||||
|
wasm: bool,
|
||||||
|
) -> anyhow::Result<SolcDownloader> {
|
||||||
|
if wasm {
|
||||||
|
SolcDownloader::wasm(version).await
|
||||||
|
} else if cfg!(target_os = "linux") {
|
||||||
|
SolcDownloader::linux(version).await
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
SolcDownloader::macosx(version).await
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
SolcDownloader::windows(version).await
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Downloads the solc binary for Wasm is `wasm` is set, otherwise for
|
/// Downloads the solc binary for Wasm is `wasm` is set, otherwise for
|
||||||
/// the target platform.
|
/// the target platform.
|
||||||
///
|
///
|
||||||
@@ -24,17 +42,6 @@ pub async fn download_solc(
|
|||||||
version: impl Into<VersionOrRequirement>,
|
version: impl Into<VersionOrRequirement>,
|
||||||
wasm: bool,
|
wasm: bool,
|
||||||
) -> anyhow::Result<PathBuf> {
|
) -> anyhow::Result<PathBuf> {
|
||||||
let downloader = if wasm {
|
let downloader = downloader(version, wasm).await?;
|
||||||
SolcDownloader::wasm(version).await
|
|
||||||
} else if cfg!(target_os = "linux") {
|
|
||||||
SolcDownloader::linux(version).await
|
|
||||||
} else if cfg!(target_os = "macos") {
|
|
||||||
SolcDownloader::macosx(version).await
|
|
||||||
} else if cfg!(target_os = "windows") {
|
|
||||||
SolcDownloader::windows(version).await
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}?;
|
|
||||||
|
|
||||||
get_or_download(cache_directory, &downloader).await
|
get_or_download(cache_directory, &downloader).await
|
||||||
}
|
}
|
||||||
|
|||||||
Executable
+102
@@ -0,0 +1,102 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Revive Differential Tests - Quick Start Script
|
||||||
|
# This script clones the test repository, sets up the corpus file, and runs the tool
|
||||||
|
|
||||||
|
set -e # Exit on any error
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
TEST_REPO_URL="https://github.com/paritytech/resolc-compiler-tests"
|
||||||
|
TEST_REPO_DIR="resolc-compiler-tests"
|
||||||
|
CORPUS_FILE="./corpus.json"
|
||||||
|
WORKDIR="workdir"
|
||||||
|
|
||||||
|
# Optional positional argument: path to polkadot-sdk directory
|
||||||
|
POLKADOT_SDK_DIR="${1:-}"
|
||||||
|
|
||||||
|
# Binary paths (default to names in $PATH)
|
||||||
|
REVIVE_DEV_NODE_BIN="revive-dev-node"
|
||||||
|
ETH_RPC_BIN="eth-rpc"
|
||||||
|
SUBSTRATE_NODE_BIN="substrate-node"
|
||||||
|
|
||||||
|
echo -e "${GREEN}=== Revive Differential Tests Quick Start ===${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if test repo already exists
|
||||||
|
if [ -d "$TEST_REPO_DIR" ]; then
|
||||||
|
echo -e "${YELLOW}Test repository already exists. Pulling latest changes...${NC}"
|
||||||
|
cd "$TEST_REPO_DIR"
|
||||||
|
git pull
|
||||||
|
cd ..
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}Cloning test repository...${NC}"
|
||||||
|
git clone "$TEST_REPO_URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If polkadot-sdk path is provided, verify and use binaries from there; build if needed
|
||||||
|
if [ -n "$POLKADOT_SDK_DIR" ]; then
|
||||||
|
if [ ! -d "$POLKADOT_SDK_DIR" ]; then
|
||||||
|
echo -e "${RED}Provided polkadot-sdk directory does not exist: $POLKADOT_SDK_DIR${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
POLKADOT_SDK_DIR=$(realpath "$POLKADOT_SDK_DIR")
|
||||||
|
echo -e "${GREEN}Using polkadot-sdk at: $POLKADOT_SDK_DIR${NC}"
|
||||||
|
|
||||||
|
REVIVE_DEV_NODE_BIN="$POLKADOT_SDK_DIR/target/release/revive-dev-node"
|
||||||
|
ETH_RPC_BIN="$POLKADOT_SDK_DIR/target/release/eth-rpc"
|
||||||
|
SUBSTRATE_NODE_BIN="$POLKADOT_SDK_DIR/target/release/substrate-node"
|
||||||
|
|
||||||
|
if [ ! -x "$REVIVE_DEV_NODE_BIN" ] || [ ! -x "$ETH_RPC_BIN" ] || [ ! -x "$SUBSTRATE_NODE_BIN" ]; then
|
||||||
|
echo -e "${YELLOW}Required binaries not found in release target. Building...${NC}"
|
||||||
|
(cd "$POLKADOT_SDK_DIR" && cargo build --release --package staging-node-cli --package pallet-revive-eth-rpc --package revive-dev-node)
|
||||||
|
fi
|
||||||
|
|
||||||
|
for bin in "$REVIVE_DEV_NODE_BIN" "$ETH_RPC_BIN" "$SUBSTRATE_NODE_BIN"; do
|
||||||
|
if [ ! -x "$bin" ]; then
|
||||||
|
echo -e "${RED}Expected binary not found after build: $bin${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}No polkadot-sdk path provided. Using binaries from $PATH.${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create corpus file with absolute path resolved at runtime
|
||||||
|
echo -e "${GREEN}Creating corpus file...${NC}"
|
||||||
|
ABSOLUTE_PATH=$(realpath "$TEST_REPO_DIR/fixtures/solidity/")
|
||||||
|
|
||||||
|
cat > "$CORPUS_FILE" << EOF
|
||||||
|
{
|
||||||
|
"name": "MatterLabs Solidity Simple, Complex, and Semantic Tests",
|
||||||
|
"path": "$ABSOLUTE_PATH"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo -e "${GREEN}Corpus file created: $CORPUS_FILE${NC}"
|
||||||
|
|
||||||
|
# Create workdir if it doesn't exist
|
||||||
|
mkdir -p "$WORKDIR"
|
||||||
|
|
||||||
|
echo -e "${GREEN}Starting differential tests...${NC}"
|
||||||
|
echo "This may take a while..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Run the tool
|
||||||
|
RUST_LOG="error" cargo run --release -- \
|
||||||
|
--corpus "$CORPUS_FILE" \
|
||||||
|
--workdir "$WORKDIR" \
|
||||||
|
--number-of-nodes 5 \
|
||||||
|
--kitchensink "$SUBSTRATE_NODE_BIN" \
|
||||||
|
--revive-dev-node "$REVIVE_DEV_NODE_BIN" \
|
||||||
|
--eth_proxy "$ETH_RPC_BIN" \
|
||||||
|
> logs.log \
|
||||||
|
2> output.log
|
||||||
|
|
||||||
|
echo -e "${GREEN}=== Test run completed! ===${NC}"
|
||||||
Reference in New Issue
Block a user