measure flipper code size

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-04-26 10:51:41 +02:00
parent 44ae9e77d5
commit 3d44685168
3 changed files with 21 additions and 7 deletions
+4 -3
View File
@@ -1,5 +1,6 @@
{
"Baseline": 3551,
"Computation": 5912,
"Fibonacci": 4909
"Flipper": 4204,
"Fibonacci": 5616,
"Computation": 6971,
"Baseline": 3743
}
+14
View File
@@ -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()),
]);
+3 -4
View File
@@ -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());