8000 impl mock evaluator · init4tech/builder@3d2b025 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d2b025

Browse files
committed
impl mock evaluator
1 parent 4c31fe2 commit 3d2b025

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/tasks/simulator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ where
139139
}
140140
Some(Ok(Some(candidate))) = futs.join_next() => {
141141
println!("candidate used gas: {:?}", candidate.result.result.gas_used());
142-
if candidate.score > best.as_ref().map(|b| b.score).unwrap_or_default() {
142+
// TODO: think about equality statement here.
143+
// if using ">" then no candidate will be returned if every score is zero
144+
// if using ">=" then the candidate will be replaced every time if every score is zero
145+
if candidate.score >= best.as_ref().map(|b| b.score).unwrap_or_default() {
143146
best = Some(candidate);
144147
}
145148
}

tests/simulator_test.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::str::FromStr;
1212
use std::sync::Arc;
1313
use tokio::sync::mpsc;
1414
use tokio::time::{Duration, Instant};
15-
use trevm::revm::primitives::ResultAndState;
15+
use trevm::revm::primitives::{Account, ExecutionResult, ResultAndState};
1616
use trevm::{NoopBlock, NoopCfg};
1717

1818
#[tokio::test(flavor = "multi_thread")]
@@ -56,11 +56,23 @@ async fn test_spawn() {
5656

5757
// Check the result
5858
assert!(best.is_some());
59-
assert_eq!(best.unwrap().score, U256::from(1));
59+
assert_eq!(best.unwrap().score, U256::from(0));
6060
}
6161

62-
fn mock_evaluator(_state: &ResultAndState) -> U256 {
63-
U256::from(1)
62+
fn mock_evaluator(state: &ResultAndState) -> U256 {
63+
// log the transaction results
64+
match &state.result {
65+
ExecutionResult::Success { .. } => println!("Execution was successful."),
66+
ExecutionResult::Revert { .. } => println!("Execution reverted."),
67+
ExecutionResult::Halt { .. } => println!("Execution halted."),
68+
}
69+
70+
// return the target account balance
71+
let target_addr = Address::from_str("0x0000000000000000000000000000000000000000").unwrap();
72+
let default_account = Account::default();
73+
let target_account = state.state.get(&target_addr).unwrap_or(&default_account);
74+
println!("target account balance: {:?}", target_account.info.balance);
75+
target_account.info.balance
6476
}
6577

6678
// Returns a new signed test transaction with default values

0 commit comments

Comments
 (0)
0