Skip to content

Commit 38af4ee

Browse files
authored
test-utils (#16)
* feat: test-utils * fix: lint * lint: clippy * nit: import * test: add one for extraction * chore: change hidden to feature gate * feat: assert_conforms * fix: clippy * lint: fmt * feat: assert_conforms * nit: import * chore: unused clone * chore: bump jsonrpsee * nit: newline * nit: newline
1 parent 71940bb commit 38af4ee

File tree

15 files changed

+873
-57
lines changed

15 files changed

+873
-57
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async-trait = "0.1.87"
8181
parking_lot = "0.12"
8282

8383
# Rpc
84-
jsonrpsee = "0.24"
84+
jsonrpsee = "0.24.9"
8585
jsonrpsee-core = "0.24"
8686
jsonrpsee-http-client = "0.24"
8787
jsonrpsee-types = "0.24"

crates/evm/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ reth-db-common.workspace = true
2828

2929
trevm = { workspace = true, features = ["test-utils"] }
3030

31+
signet-types = { workspace = true, features = ["test-utils"] }
32+
signet-extract = { workspace = true, features = ["test-utils"] }
33+
3134
[features]
3235
default = []
33-
test_utils = []
36+
test-utils = ["signet-types/test-utils"]

crates/evm/src/driver.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,10 @@ mod test {
780780
};
781781
use reth::primitives::{Block, RecoveredBlock, Transaction};
782782
use signet_extract::ExtractedEvent;
783-
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig};
783+
use signet_types::{
784+
config::{HostConfig, PredeployTokens, RollupConfig},
785+
test_utils::*,
786+
};
784787
use trevm::NoopCfg;
785788

786789
/// Make a fake block with a specific number.

crates/evm/src/lib.rs

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -76,61 +76,14 @@ where
7676
}
7777

7878
/// Test utilities for the Signet EVM impl.
79-
#[cfg(any(test, feature = "test_utils"))]
79+
#[cfg(any(test, feature = "test-utils"))]
8080
pub mod test_utils {
81-
use alloy::primitives::Address;
82-
use reth::revm::InMemoryDB;
83-
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig, SignetSystemConstants};
84-
85-
/// Test chain id for the host chain.
86-
pub const TEST_HOST_CHAIN_ID: u64 = 1;
87-
/// Test chain id for the RU chain.
88-
pub const TEST_RU_CHAIN_ID: u64 = 15;
89-
/// Test address for the host zenith.
90-
pub const HOST_ZENITH_ADDRESS: Address = Address::repeat_byte(0xdf);
91-
/// Test address for the RU zenith.
92-
pub const RU_ORDERS_ADDRESS: Address = Address::repeat_byte(0xac);
93-
/// Test address for the host orders.
94-
pub const HOST_ORDERS_ADDRESS: Address = Address::repeat_byte(0xdc);
95-
96-
/// Test address for USDC.
97-
pub const TEST_USDC: Address = Address::repeat_byte(0x01);
98-
99-
/// Test address for USDT.
100-
pub const TEST_USDT: Address = Address::repeat_byte(0x02);
101-
102-
/// Test address for WBTC.
103-
pub const TEST_WBTC: Address = Address::repeat_byte(0x03);
104-
105-
/// Create a new set of Signet system constants for testing.
106-
pub const fn test_signet_constants() -> SignetSystemConstants {
107-
let usdc = Address::repeat_byte(0x01);
108-
let usdt = Address::repeat_byte(0x02);
109-
let wbtc = Address::repeat_byte(0x03);
110-
111-
SignetSystemConstants::new(
112-
HostConfig::new(
113-
TEST_HOST_CHAIN_ID,
114-
0,
115-
HOST_ZENITH_ADDRESS,
116-
HOST_ORDERS_ADDRESS,
117-
Address::repeat_byte(1),
118-
Address::repeat_byte(2),
119-
PredeployTokens::new(usdc, usdt, wbtc),
120-
),
121-
RollupConfig::new(
122-
TEST_RU_CHAIN_ID,
123-
RU_ORDERS_ADDRESS,
124-
Address::repeat_byte(3),
125-
Address::repeat_byte(4),
126-
PredeployTokens::new(usdc, usdt, wbtc),
127-
),
128-
)
129-
}
81+
use signet_types::test_utils::*;
82+
use trevm::revm::InMemoryDB;
13083

13184
/// Create a new Signet EVM with an in-memory database for testing.
13285
pub fn test_signet_evm() -> super::EvmNeedsCfg<'static, trevm::revm::db::InMemoryDB> {
133-
let mut trevm = super::signet_evm(InMemoryDB::default(), test_signet_constants());
86+
let mut trevm = super::signet_evm(InMemoryDB::default(), TEST_CONSTANTS);
13487
trevm.inner_mut_unchecked().cfg_mut().chain_id = TEST_RU_CHAIN_ID;
13588
trevm
13689
}

crates/extract/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ alloy.workspace = true
1717
reth.workspace = true
1818

1919
tracing.workspace = true
20+
21+
# test utils
22+
reth-exex = { workspace = true, optional = true }
23+
24+
[dev-dependencies]
25+
signet-types = { workspace = true, features = ["test-utils"] }
26+
reth-exex = { workspace = true }
27+
28+
[features]
29+
default = []
30+
test-utils = ["dep:reth-exex", "signet-types/test-utils"]

crates/extract/src/block.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use crate::ExtractedEvent;
12
use reth::primitives::{Block, RecoveredBlock};
23
use signet_types::MarketContext;
34
use signet_zenith::{Passage, Transactor, Zenith};
45

5-
use crate::ExtractedEvent;
6-
76
/// The output of the block extraction process. This struct contains borrows
87
/// from a block object, the extracted events, and a [`MarketContext`]
98
/// populated with the fills present in the host block.
@@ -73,7 +72,7 @@ impl Extracts<'_> {
7372

7473
impl<'a> Extracts<'a> {
7574
/// Used for testing.
76-
#[doc(hidden)]
75+
#[cfg(any(test, feature = "test-utils"))]
7776
pub fn empty(host_block: &'a RecoveredBlock<Block>) -> Self {
7877
Self {
7978
host_block,

crates/extract/src/extractor.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,37 @@ impl Extractor {
150150
})
151151
}
152152
}
153+
154+
#[cfg(test)]
155+
mod test {
156+
use super::*;
157+
use crate::test_utils::*;
158+
use alloy::{
159+
consensus::constants::GWEI_TO_WEI,
160+
primitives::{Address, U256},
161+
};
162+
use signet_types::test_utils::*;
163+
164+
#[test]
165+
fn extraction() {
166+
let mut ru_block = RuBlockSpec::new(TEST_CONSTANTS)
167+
.with_gas_limit(12345)
168+
.with_reward_address(Address::repeat_byte(0x99));
169+
ru_block.add_simple_send(&TEST_SIGNERS[0], TEST_USERS[1], U256::from(GWEI_TO_WEI), 0);
170+
171+
let hbs = HostBlockSpec::new(TEST_CONSTANTS)
172+
.with_block_number(1)
173+
.enter(TEST_USERS[0], (GWEI_TO_WEI * 4) as usize)
174+
.enter(TEST_USERS[1], (GWEI_TO_WEI * 2) as usize)
175+
.enter_token(TEST_USERS[2], 10_000_000, USDC)
176+
.simple_transact(TEST_USERS[0], TEST_USERS[4], [1, 2, 3, 4], GWEI_TO_WEI as usize)
177+
.fill(USDT, TEST_USERS[4], 10_000)
178+
.submit_block(ru_block);
179+
let (chain, _) = hbs.to_chain();
180+
181+
let extractor = Extractor::new(&TEST_CONSTANTS);
182+
let extracts = extractor.extract_signet(&chain).next().unwrap();
183+
184+
hbs.assert_conforms(&extracts);
185+
}
186+
}

crates/extract/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ pub use extractor::Extractor;
3636

3737
mod block;
3838
pub use block::Extracts;
39+
40+
#[cfg(any(test, feature = "test-utils"))]
41+
/// Utils for unit and integration tests.
42+
pub mod test_utils;

0 commit comments

Comments
 (0)