mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-28 15:28:00 +00:00
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"Baseline": 3551,
|
||||
"Computation": 5912,
|
||||
"Fibonacci": 4909
|
||||
"Flipper": 4204,
|
||||
"Fibonacci": 5616,
|
||||
"Computation": 6971,
|
||||
"Baseline": 3743
|
||||
}
|
||||
@@ -10,6 +10,8 @@ pub struct Contract {
|
||||
|
||||
sol!(contract Baseline { function baseline() public payable; });
|
||||
|
||||
sol!(contract Flipper { function flip() public; });
|
||||
|
||||
sol!(contract Computation {
|
||||
function odd_product(int32 n) public pure returns (int64);
|
||||
function triangle_number(int64 n) public pure returns (int64 sum);
|
||||
@@ -116,6 +118,17 @@ impl Contract {
|
||||
calldata: SHA1::sha1Call::new((pre,)).abi_encode(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flipper() -> Self {
|
||||
let code = include_str!("../contracts/flipper.sol");
|
||||
let name = "Flipper";
|
||||
|
||||
Self {
|
||||
evm_runtime: crate::compile_evm_bin_runtime(name, code),
|
||||
pvm_runtime: crate::compile_blob(name, code),
|
||||
calldata: Flipper::flipCall::new(()).abi_encode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -140,6 +153,7 @@ mod tests {
|
||||
|
||||
let sizes = HashMap::from([
|
||||
("Baseline", Contract::baseline().pvm_runtime.len()),
|
||||
("Flipper", Contract::flipper().pvm_runtime.len()),
|
||||
("Computation", Contract::odd_product(0).pvm_runtime.len()),
|
||||
("Fibonacci", Contract::fib_iterative(0).pvm_runtime.len()),
|
||||
]);
|
||||
|
||||
@@ -26,11 +26,10 @@ fn fibonacci() {
|
||||
|
||||
#[test]
|
||||
fn flipper() {
|
||||
let code = crate::compile_blob("Flipper", include_str!("../contracts/flipper.sol"));
|
||||
let state = State::new(0xcde4efa9u32.to_be_bytes().to_vec());
|
||||
let (mut instance, export) = mock_runtime::prepare(&code, None);
|
||||
let contract = Contract::flipper();
|
||||
let (mut instance, export) = mock_runtime::prepare(&contract.pvm_runtime, None);
|
||||
|
||||
let state = crate::mock_runtime::call(state, &mut instance, export);
|
||||
let state = crate::mock_runtime::call(State::new(contract.calldata), &mut instance, export);
|
||||
assert_eq!(state.output.flags, 0);
|
||||
assert_eq!(state.storage[&U256::ZERO], U256::try_from(1).unwrap());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user