Skip to content

Commit 3ee90ff

Browse files
committed
chore: address review comments
1 parent 72bc2e5 commit 3ee90ff

File tree

3 files changed

+55
-42
lines changed

3 files changed

+55
-42
lines changed

src/est.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl SearchRange {
3434

3535
/// Calculate the midpoint of the search range.
3636
pub(crate) const fn midpoint(&self) -> u64 {
37-
((self.max() as u128 + self.min() as u128) / 2) as u64
37+
(self.max() + self.min()) / 2
3838
}
3939

4040
/// Get the start of the search range.
@@ -296,6 +296,12 @@ mod tests {
296296
range.maybe_lower_max(180);
297297
assert_eq!(range.max(), 180);
298298
assert_eq!(range.midpoint(), 152);
299+
300+
range.maybe_raise_min(100);
301+
assert_eq!(range.min(), 125);
302+
303+
range.maybe_lower_max(200);
304+
assert_eq!(range.max(), 180);
299305
}
300306
}
301307

src/evm.rs

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,41 +2348,29 @@ where
23482348

23492349
#[cfg(test)]
23502350
mod tests {
2351-
use std::sync::LazyLock;
2352-
2353-
use alloy::network::{TransactionBuilder, TransactionBuilder7702};
2354-
use alloy::rpc::types::Authorization;
2355-
use alloy::signers::k256::ecdsa::SigningKey;
2356-
use alloy::signers::local::PrivateKeySigner;
2357-
use alloy::signers::SignerSync;
2358-
use alloy::{consensus::constants::ETH_TO_WEI, rpc::types::TransactionRequest};
2359-
2360-
use revm::context::transaction::AuthorizationTr;
2361-
use revm::database::InMemoryDB;
2362-
use revm::inspector::NoOpInspector;
2363-
use revm::primitives::bytes;
2364-
2365-
use crate::test_utils::{test_trevm_with_funds, LOG_BYTECODE};
2366-
use crate::{EvmNeedsCfg, TrevmBuilder};
2367-
use crate::{NoopBlock, NoopCfg};
2368-
2351+
use alloy::{
2352+
network::{TransactionBuilder, TransactionBuilder7702},
2353+
rpc::types::{Authorization, TransactionRequest},
2354+
signers::SignerSync,
2355+
consensus::constants::ETH_TO_WEI,
2356+
};
2357+
use revm::{
2358+
context::transaction::AuthorizationTr,
2359+
database::InMemoryDB,
2360+
primitives::bytes,
2361+
};
2362+
use crate::{
2363+
test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_BYTECODE},
2364+
TrevmBuilder, NoopBlock, NoopCfg,
2365+
};
23692366
use super::*;
23702367

2371-
static ALICE: LazyLock<PrivateKeySigner> =
2372-
LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x11; 32]).unwrap()));
2373-
static BOB: LazyLock<PrivateKeySigner> =
2374-
LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x22; 32]).unwrap()));
2375-
2376-
fn trevm_with_funds() -> EvmNeedsCfg<InMemoryDB, NoOpInspector> {
2377-
test_trevm_with_funds(&[
2378-
(ALICE.address(), U256::from(ETH_TO_WEI)),
2379-
(BOB.address(), U256::from(ETH_TO_WEI)),
2380-
])
2381-
}
2382-
23832368
#[test]
23842369
fn test_estimate_gas_simple_transfer() {
2385-
let trevm = trevm_with_funds();
2370+
let trevm = test_trevm_with_funds(&[
2371+
(ALICE.address(), U256::from(ETH_TO_WEI)),
2372+
(BOB.address(), U256::from(ETH_TO_WEI)),
2373+
]);
23862374

23872375
let tx = TransactionRequest::default()
23882376
.from(ALICE.address())
@@ -2394,7 +2382,7 @@ mod tests {
23942382

23952383
assert!(estimation.is_success());
23962384
// The gas used should correspond to a simple transfer.
2397-
assert!(estimation.gas_used() == 21000);
2385+
assert_eq!(estimation.gas_used(), 21000);
23982386
}
23992387

24002388
#[test]
@@ -2418,7 +2406,7 @@ mod tests {
24182406
};
24192407
let signature = BOB.sign_hash_sync(&authorization.signature_hash()).unwrap();
24202408
let signed_authorization = authorization.into_signed(signature);
2421-
assert!(signed_authorization.authority().unwrap() == BOB.address());
2409+
assert_eq!(signed_authorization.authority().unwrap(), BOB.address());
24222410

24232411
let tx = TransactionRequest::default()
24242412
.from(ALICE.address())
@@ -2429,19 +2417,14 @@ mod tests {
24292417
let (estimation, trevm) =
24302418
trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap();
24312419

2432-
dbg!(&estimation);
24332420
assert!(estimation.is_success());
24342421

24352422
let tx = tx.with_gas_limit(estimation.limit());
24362423

2437-
let mut output = trevm.clear_tx().fill_tx(&tx).run().unwrap().accept();
2438-
2439-
let bob_code = output.1.read_code(BOB.address());
2440-
dbg!(&bob_code);
2424+
let output = trevm.clear_tx().fill_tx(&tx).run().unwrap().accept();
24412425

2442-
dbg!(&output.0);
24432426
assert!(output.0.is_success());
2444-
assert!(output.0.logs().len() == 1);
2427+
assert_eq!(output.0.logs().len(), 1);
24452428
}
24462429
}
24472430

src/test_utils.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use std::sync::LazyLock;
2+
13
use crate::{helpers::Ctx, EvmNeedsCfg, Trevm};
2-
use alloy::primitives::{Address, U256};
4+
use alloy::{primitives::{Address, U256}, signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner}};
35
use revm::{
46
bytecode::Bytecode,
57
database::{CacheDB, EmptyDB, InMemoryDB, State},
@@ -13,8 +15,30 @@ use revm::{
1315
};
1416

1517
/// LogContract bytecode
18+
/// ```
19+
/// contract LogContract {
20+
/// event Hello();
21+
/// event World();
22+
///
23+
/// function emitHello() public {
24+
/// emit Hello();
25+
/// }
26+
///
27+
/// function emitWorld() public {
28+
/// emit World();
29+
/// }
30+
/// }
31+
/// ```
1632
pub const LOG_BYTECODE: &str = "0x60806040526004361015610013575b6100ca565b61001d5f3561003c565b80637b3ab2d01461003757639ee1a4400361000e57610097565b610064565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261005a57565b61004c565b5f0190565b3461009257610074366004610050565b61007c6100ce565b610084610042565b8061008e8161005f565b0390f35b610048565b346100c5576100a7366004610050565b6100af610106565b6100b7610042565b806100c18161005f565b0390f35b610048565b5f80fd5b7fbcdfe0d5b27dd186282e187525415c57ea3077c34efb39148111e4d342e7ab0e6100f7610042565b806101018161005f565b0390a1565b7f2d67bb91f17bca05af6764ab411e86f4ddf757adb89fcec59a7d21c525d4171261012f610042565b806101398161005f565b0390a156fea2646970667358221220e22cd46ba129dcbd6f62f632cc862b0924d3f36c991fd0b45947581aa3010d6464736f6c634300081a0033";
1733

34+
35+
/// Alice testing signer
36+
pub static ALICE: LazyLock<PrivateKeySigner> =
37+
LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x11; 32]).unwrap()));
38+
/// Bob testing signer
39+
pub static BOB: LazyLock<PrivateKeySigner> =
40+
LazyLock::new(|| PrivateKeySigner::from(SigningKey::from_slice(&[0x22; 32]).unwrap()));
41+
1842
impl<Insp, State> Trevm<InMemoryDB, Insp, State>
1943
where
2044
Insp: Inspector<Ctx<InMemoryDB>>,

0 commit comments

Comments
 (0)