Constructors and contract creation (#11)

Implement constructor logic and support create/create2 in the mock runtime

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
Cyrill Leutwiler
2024-05-22 21:35:32 +02:00
committed by GitHub
parent 42697edc67
commit 06aa289d9b
26 changed files with 692 additions and 720 deletions
+48 -2
View File
@@ -1,5 +1,5 @@
use alloy_primitives::{I256, U256};
use alloy_sol_types::{sol, SolCall};
use alloy_sol_types::{sol, SolCall, SolConstructor};
use crate::mock_runtime::{CallOutput, State};
@@ -13,7 +13,11 @@ pub struct Contract {
sol!(contract Baseline { function baseline() public payable; });
sol!(contract Flipper { function flip() public; });
sol!(contract Flipper {
constructor (bool);
function flip() public;
});
sol!(contract Computation {
function odd_product(int32 n) public pure returns (int64);
@@ -113,6 +117,12 @@ sol!(
}
);
sol!(
contract CreateB {
fallback() external payable;
}
);
impl Contract {
/// Execute the contract.
///
@@ -228,6 +238,18 @@ impl Contract {
}
}
pub fn flipper_constructor(coin: bool) -> Self {
let code = include_str!("../contracts/flipper.sol");
let name = "Flipper";
Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: Flipper::constructorCall::new((coin,)).abi_encode(),
}
}
pub fn erc20() -> Self {
let code = include_str!("../contracts/ERC20.sol");
let name = "ERC20";
@@ -359,6 +381,30 @@ impl Contract {
calldata: Events::emitEventCall::new((topics,)).abi_encode(),
}
}
pub fn create_a() -> Self {
let code = include_str!("../contracts/Create.sol");
let name = "CreateA";
Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: vec![0; 4],
}
}
pub fn create_b() -> Self {
let code = include_str!("../contracts/Create.sol");
let name = "CreateB";
Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: vec![0; 4],
}
}
}
#[cfg(test)]