Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:

clippy:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
Expand Down
47 changes: 39 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/cast/src/rlp_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Item {
Data(Vec<u8>),
Array(Vec<Item>),
Array(Vec<Self>),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are this change needed, they don't seem related to the PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is reported by clippy

}

impl Encodable for Item {
Expand Down
12 changes: 6 additions & 6 deletions crates/chisel/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,22 @@ enum Type {
Builtin(DynSolType),

/// (type)
Array(Box<Type>),
Array(Box<Self>),

/// (type, length)
FixedArray(Box<Type>, usize),
FixedArray(Box<Self>, usize),

/// (type, index)
ArrayIndex(Box<Type>, Option<usize>),
ArrayIndex(Box<Self>, Option<usize>),

/// (types)
Tuple(Vec<Option<Type>>),
Tuple(Vec<Option<Self>>),

/// (name, params, returns)
Function(Box<Type>, Vec<Option<Type>>, Vec<Option<Type>>),
Function(Box<Self>, Vec<Option<Self>>, Vec<Option<Self>>),

/// (lhs, rhs)
Access(Box<Type>, String),
Access(Box<Self>, String),

/// (types)
Custom(Vec<String>),
Expand Down
14 changes: 7 additions & 7 deletions crates/cli/src/opts/build/revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub struct ResolcOpts {
)]
pub resolc_compile: Option<bool>,

/// Enable PVM mode at startup (independent of compilation)
/// Use pallet-revive runtime backend
#[arg(
long = "resolc-startup",
help = "Enable PVM mode at startup",
value_name = "RESOLC_STARTUP",
long = "polkadot",
help = "Use pallet-revive runtime backend",
value_name = "POLKADOT",
action = clap::ArgAction::SetTrue
)]
pub resolc_startup: Option<bool>,
pub polkadot: Option<bool>,

/// Specify the resolc version, or a path to a local resolc, to build with.
///
Expand Down Expand Up @@ -88,8 +88,8 @@ impl ResolcOpts {
resolc.resolc_compile
);
set_if_some!(
self.resolc_startup.and_then(|v| if v { Some(true) } else { None }),
resolc.resolc_startup
self.polkadot.and_then(|v| if v { Some(true) } else { None }),
resolc.polkadot
);
set_if_some!(
self.use_resolc.as_ref().map(|v| SolcReq::from(v.trim_start_matches("resolc:"))),
Expand Down
33 changes: 26 additions & 7 deletions crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,32 @@ pub fn get_provider_builder(config: &Config) -> Result<ProviderBuilder> {

/// Return an [ExecutorStrategy] via the config.
pub fn get_executor_strategy(config: &Config) -> ExecutorStrategy {
// TODO: using resolc compiler: `[FAIL: EvmError: StackUnderflow] constructor() (gas: 0)`
if config.resolc.resolc_compile {
info!("using revive strategy");
use revive_strategy::ReviveExecutorStrategyBuilder;
ExecutorStrategy::new_revive(config.resolc.resolc_startup)
} else {
ExecutorStrategy::new_evm()
use revive_strategy::{ReviveExecutorStrategyBuilder, ReviveRuntimeMode};

let polkadot = config.resolc.polkadot;
let resolc = config.resolc.resolc_compile;

match (resolc, polkadot) {
// (default) - Standard Foundry EVM test
(false, false) => {
info!("using standard EVM strategy");
ExecutorStrategy::new_evm()
}
// --resolc - Run PolkaVM backend on pallet-revive (PVM)
(true, false) => {
info!("using revive strategy with PVM backend");
ExecutorStrategy::new_revive(ReviveRuntimeMode::Pvm)
}
// --resolc --polkadot - Run PolkaVM backend on pallet-revive (PVM)
(true, true) => {
info!("using revive strategy with PVM backend (polkadot mode)");
ExecutorStrategy::new_revive(ReviveRuntimeMode::Pvm)
}
// --polkadot (without resolc) - Run EVM backend on pallet-revive
(false, true) => {
info!("using revive strategy with EVM backend on pallet-revive");
ExecutorStrategy::new_revive(ReviveRuntimeMode::Evm)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct ResolcConfig {
/// Enable compilation using resolc
pub resolc_compile: bool,

/// Enable PVM mode at startup (independent of compilation)
pub resolc_startup: bool,
/// Use pallet-revive runtime backend
pub polkadot: bool,

/// The resolc compiler
pub resolc: Option<SolcReq>,
Expand Down
1 change: 1 addition & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ serial_test.workspace = true
mockall = "0.13"
globset = "0.4"
paste = "1.0"
rstest = "0.24"
similar-asserts.workspace = true
svm = { package = "svm-rs", version = "0.5", default-features = false, features = [
"rustls",
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ path = "out"

[profile.default.resolc]
resolc_compile = false
resolc_startup = false
polkadot = false

[fmt]
line_length = 120
Expand Down Expand Up @@ -1345,7 +1345,7 @@ exclude = []
"script_execution_protection": true,
"resolc": {
"resolc_compile": false,
"resolc_startup": false,
"polkadot": false,
"resolc": null,
"optimizer_mode": null,
"heap_size": null,
Expand Down
66 changes: 61 additions & 5 deletions crates/forge/tests/cli/revive_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract CounterTest is DSTest {
.unwrap();
prj.update_config(|config| config.evm_version = EvmVersion::Cancun);

let res = cmd.args(["test", "--resolc", "-vvv", "--resolc-startup"]).assert();
let res = cmd.args(["test", "--resolc", "-vvv", "--polkadot"]).assert();
res.stderr_eq(str![""]).stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Expand Down Expand Up @@ -121,7 +121,7 @@ contract SetNonce is DSTest {
.unwrap();
prj.update_config(|config| config.evm_version = EvmVersion::Cancun);

let res = cmd.args(["test", "--resolc", "-vvv", "--resolc-startup"]).assert_success();
let res = cmd.args(["test", "--resolc", "-vvv", "--polkadot"]).assert_success();
res.stderr_eq(str![""]).stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Expand Down Expand Up @@ -165,7 +165,7 @@ contract Roll is DSTest {
)
.unwrap();

let res = cmd.args(["test", "--resolc", "-vvv", "--resolc-startup"]).assert_success();
let res = cmd.args(["test", "--resolc", "-vvv", "--polkadot"]).assert_success();
res.stderr_eq(str![""]).stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Expand Down Expand Up @@ -209,7 +209,7 @@ contract Warp is DSTest {
)
.unwrap();

let res = cmd.args(["test", "--resolc", "-vvv", "--resolc-startup"]).assert_success();
let res = cmd.args(["test", "--resolc", "-vvv", "--polkadot"]).assert_success();
res.stderr_eq(str![""]).stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Expand Down Expand Up @@ -254,7 +254,7 @@ function test_Balance() public {
)
.unwrap();

let res = cmd.args(["test", "--resolc", "-vvv", "--resolc-startup"]).assert_success();
let res = cmd.args(["test", "--resolc", "-vvv", "--polkadot"]).assert_success();
res.stderr_eq(str![""]).stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Expand Down Expand Up @@ -331,3 +331,59 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)

"#]]);
});

// Test --polkadot flag: EVM execution on pallet-revive backend
forgetest!(polkadot_evm_backend, |prj, cmd| {
prj.insert_ds_test();
prj.insert_vm();
prj.add_source(
"Counter.sol",
r#"
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Counter {
uint256 public number;

constructor(uint256 _initial) {
number = _initial;
}

function increment() public {
number = number + 1;
}

function getNumber() public view returns (uint256) {
return number;
}
}
"#,
)
.unwrap();

prj.add_source(
"CounterTest.t.sol",
r#"
import "./test.sol";
import {Counter} from "./Counter.sol";

contract CounterTest is DSTest {
function test_PolkadotEVMBackend() public {
// This test runs EVM bytecode on pallet-revive EVM backend
Counter counter = new Counter(42);
assertEq(counter.getNumber(), 42);

counter.increment();
assertEq(counter.getNumber(), 43);

counter.increment();
assertEq(counter.getNumber(), 44);
}
}
"#,
)
.unwrap();

// Test with --polkadot flag (EVM backend on pallet-revive)
cmd.args(["test", "--polkadot", "-vvv"]).assert_success();
});
Loading
Loading