Skip to content

Commit 330fbec

Browse files
committed
add tests
1 parent 0c817f3 commit 330fbec

File tree

12 files changed

+2015
-67
lines changed

12 files changed

+2015
-67
lines changed

Cargo.lock

Lines changed: 391 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["bin/lumen", "crates/common", "crates/node", "crates/rollkit"]
3+
members = ["bin/lumen", "crates/common", "crates/node", "crates/rollkit", "crates/tests"]
44

55
[workspace.package]
66
version = "0.1.0"

crates/rollkit/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ alloy-rlp.workspace = true
2626
serde = { workspace = true, features = ["derive"] }
2727
thiserror.workspace = true
2828

29+
[dev-dependencies]
30+
serde_json.workspace = true
31+
2932
[lints]
3033
workspace = true

crates/rollkit/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
/// Rollkit-specific types and related definitions.
88
pub mod types;
99

10+
#[cfg(test)]
11+
mod tests;
12+
1013
// Re-export public types
1114
pub use types::{PayloadAttributesError, RollkitPayloadAttributes};

crates/rollkit/src/tests.rs

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
use crate::types::{PayloadAttributesError, RollkitPayloadAttributes};
2+
use alloy_primitives::{Address, B256};
3+
4+
#[cfg(test)]
5+
mod tests {
6+
use super::*;
7+
8+
/// Test payload attributes creation and basic field assignment
9+
#[test]
10+
fn test_payload_attributes_creation() {
11+
let transactions = vec![];
12+
let gas_limit = Some(1000000u64);
13+
let timestamp = 1234567890u64;
14+
let prev_randao = B256::random();
15+
let suggested_fee_recipient = Address::random();
16+
let parent_hash = B256::random();
17+
let block_number = 1u64;
18+
19+
let attrs = RollkitPayloadAttributes::new(
20+
transactions.clone(),
21+
gas_limit,
22+
timestamp,
23+
prev_randao,
24+
suggested_fee_recipient,
25+
parent_hash,
26+
block_number,
27+
);
28+
29+
assert_eq!(attrs.transactions, transactions);
30+
assert_eq!(attrs.gas_limit, gas_limit);
31+
assert_eq!(attrs.timestamp, timestamp);
32+
assert_eq!(attrs.prev_randao, prev_randao);
33+
assert_eq!(attrs.suggested_fee_recipient, suggested_fee_recipient);
34+
assert_eq!(attrs.parent_hash, parent_hash);
35+
assert_eq!(attrs.block_number, block_number);
36+
}
37+
38+
/// Test comprehensive payload attributes validation including gas limits
39+
#[test]
40+
fn test_payload_attributes_validation() {
41+
// Test valid attributes with empty transactions (allowed for rollkit)
42+
let attrs = RollkitPayloadAttributes::new(
43+
vec![],
44+
Some(1000000),
45+
1234567890,
46+
B256::random(),
47+
Address::random(),
48+
B256::random(),
49+
1,
50+
);
51+
assert!(
52+
attrs.validate().is_ok(),
53+
"Valid attributes should pass validation"
54+
);
55+
56+
// Test valid attributes with no gas limit (should use default)
57+
let attrs = RollkitPayloadAttributes::new(
58+
vec![],
59+
None,
60+
1234567890,
61+
B256::random(),
62+
Address::random(),
63+
B256::random(),
64+
1,
65+
);
66+
assert!(
67+
attrs.validate().is_ok(),
68+
"No gas limit should be valid (use default)"
69+
);
70+
71+
// Test invalid attributes with zero gas limit
72+
let attrs = RollkitPayloadAttributes::new(
73+
vec![],
74+
Some(0),
75+
1234567890,
76+
B256::random(),
77+
Address::random(),
78+
B256::random(),
79+
1,
80+
);
81+
assert!(
82+
attrs.validate().is_err(),
83+
"Zero gas limit should be invalid"
84+
);
85+
assert!(matches!(
86+
attrs.validate().unwrap_err(),
87+
PayloadAttributesError::InvalidGasLimit
88+
));
89+
}
90+
91+
/// Test gas limit validation edge cases
92+
#[test]
93+
fn test_gas_limit_validation() {
94+
// Test minimum valid gas limit (1)
95+
let attrs = RollkitPayloadAttributes::new(
96+
vec![],
97+
Some(1),
98+
1234567890,
99+
B256::random(),
100+
Address::random(),
101+
B256::random(),
102+
1,
103+
);
104+
assert!(
105+
attrs.validate().is_ok(),
106+
"Minimum gas limit (1) should be valid"
107+
);
108+
109+
// Test maximum gas limit
110+
let attrs = RollkitPayloadAttributes::new(
111+
vec![],
112+
Some(u64::MAX),
113+
1234567890,
114+
B256::random(),
115+
Address::random(),
116+
B256::random(),
117+
1,
118+
);
119+
assert!(
120+
attrs.validate().is_ok(),
121+
"Maximum gas limit should be valid"
122+
);
123+
124+
// Test typical gas limits
125+
for gas_limit in [21_000, 1_000_000, 30_000_000, 100_000_000] {
126+
let attrs = RollkitPayloadAttributes::new(
127+
vec![],
128+
Some(gas_limit),
129+
1234567890,
130+
B256::random(),
131+
Address::random(),
132+
B256::random(),
133+
1,
134+
);
135+
assert!(
136+
attrs.validate().is_ok(),
137+
"Typical gas limit {} should be valid",
138+
gas_limit
139+
);
140+
}
141+
}
142+
143+
/// Test payload attributes serialization and deserialization
144+
#[test]
145+
fn test_payload_attributes_serialization() {
146+
let attrs = RollkitPayloadAttributes::new(
147+
vec![],
148+
Some(1000000),
149+
1234567890,
150+
B256::random(),
151+
Address::random(),
152+
B256::random(),
153+
1,
154+
);
155+
156+
let serialized = serde_json::to_string(&attrs).unwrap();
157+
let deserialized: RollkitPayloadAttributes = serde_json::from_str(&serialized).unwrap();
158+
159+
assert_eq!(attrs.transactions.len(), deserialized.transactions.len());
160+
assert_eq!(attrs.gas_limit, deserialized.gas_limit);
161+
assert_eq!(attrs.timestamp, deserialized.timestamp);
162+
assert_eq!(attrs.prev_randao, deserialized.prev_randao);
163+
assert_eq!(
164+
attrs.suggested_fee_recipient,
165+
deserialized.suggested_fee_recipient
166+
);
167+
assert_eq!(attrs.parent_hash, deserialized.parent_hash);
168+
assert_eq!(attrs.block_number, deserialized.block_number);
169+
}
170+
171+
/// Test all error types and their string representations
172+
#[test]
173+
fn test_payload_attributes_errors() {
174+
// Test that error types can be created and formatted correctly
175+
let error = PayloadAttributesError::EmptyTransactions;
176+
assert_eq!(error.to_string(), "No transactions provided");
177+
178+
let error = PayloadAttributesError::InvalidGasLimit;
179+
assert_eq!(error.to_string(), "Invalid gas limit");
180+
181+
let error = PayloadAttributesError::TransactionValidation("test error".to_string());
182+
assert_eq!(
183+
error.to_string(),
184+
"Transaction validation failed: test error"
185+
);
186+
}
187+
188+
/// Test payload attributes with edge case values
189+
#[test]
190+
fn test_payload_attributes_edge_cases() {
191+
// Test with maximum timestamp
192+
let attrs = RollkitPayloadAttributes::new(
193+
vec![],
194+
Some(u64::MAX),
195+
u64::MAX,
196+
B256::repeat_byte(0xFF),
197+
Address::repeat_byte(0xFF),
198+
B256::repeat_byte(0xFF),
199+
u64::MAX,
200+
);
201+
assert!(attrs.validate().is_ok(), "Maximum values should be valid");
202+
203+
// Test with zero values (except gas limit which must be > 0)
204+
let attrs = RollkitPayloadAttributes::new(
205+
vec![],
206+
Some(1), // Minimum valid gas limit
207+
0,
208+
B256::ZERO,
209+
Address::ZERO,
210+
B256::ZERO,
211+
0,
212+
);
213+
assert!(
214+
attrs.validate().is_ok(),
215+
"Zero values (except gas limit) should be valid"
216+
);
217+
218+
// Test with empty byte values
219+
let attrs = RollkitPayloadAttributes::new(
220+
vec![],
221+
None, // No gas limit specified
222+
1234567890,
223+
B256::ZERO,
224+
Address::ZERO,
225+
B256::ZERO,
226+
1,
227+
);
228+
assert!(attrs.validate().is_ok(), "Zero byte values should be valid");
229+
}
230+
231+
/// Test validation consistency across different scenarios
232+
#[test]
233+
fn test_validation_consistency() {
234+
// Test that validation is consistent regardless of other field values
235+
let base_attrs = |gas_limit| {
236+
RollkitPayloadAttributes::new(
237+
vec![],
238+
gas_limit,
239+
1234567890,
240+
B256::random(),
241+
Address::random(),
242+
B256::random(),
243+
1,
244+
)
245+
};
246+
247+
// Valid gas limits should always pass
248+
assert!(base_attrs(Some(1)).validate().is_ok());
249+
assert!(base_attrs(Some(21_000)).validate().is_ok());
250+
assert!(base_attrs(Some(30_000_000)).validate().is_ok());
251+
assert!(base_attrs(None).validate().is_ok());
252+
253+
// Invalid gas limits should always fail
254+
assert!(base_attrs(Some(0)).validate().is_err());
255+
}
256+
}

crates/tests/Cargo.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[package]
2+
name = "lumen-tests"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
description = "Test suite for Lumen rollkit integration"
10+
publish = false
11+
12+
[dependencies]
13+
# Lumen dependencies
14+
lumen-rollkit = { path = "../rollkit" }
15+
lumen-node = { path = "../node" }
16+
lumen-common = { path = "../common" }
17+
18+
# Reth dependencies
19+
reth-testing-utils.workspace = true
20+
reth-db.workspace = true
21+
reth-evm-ethereum.workspace = true
22+
reth-transaction-pool.workspace = true
23+
reth-consensus.workspace = true
24+
reth-tasks.workspace = true
25+
reth-tracing.workspace = true
26+
reth-provider = { workspace = true, features = ["test-utils"] }
27+
reth-payload-primitives.workspace = true
28+
reth-primitives.workspace = true
29+
reth-primitives-traits.workspace = true
30+
reth-node-api.workspace = true
31+
reth-payload-builder.workspace = true
32+
reth-basic-payload-builder.workspace = true
33+
reth-engine-local.workspace = true
34+
reth-revm.workspace = true
35+
reth-node-types.workspace = true
36+
reth-payload-builder-primitives.workspace = true
37+
reth-execution-types.workspace = true
38+
reth-evm.workspace = true
39+
reth-errors.workspace = true
40+
reth-engine-primitives.workspace = true
41+
reth-ethereum-primitives.workspace = true
42+
reth-chainspec.workspace = true
43+
44+
# Alloy dependencies
45+
alloy-genesis.workspace = true
46+
alloy-rpc-types.workspace = true
47+
alloy-rpc-types-engine.workspace = true
48+
alloy-primitives.workspace = true
49+
alloy-eips.workspace = true
50+
alloy-consensus.workspace = true
51+
alloy-rlp.workspace = true
52+
53+
# Core dependencies
54+
tempfile.workspace = true
55+
hex = "0.4"
56+
reqwest = { version = "0.11", features = ["json"] }
57+
chrono = { version = "0.4", features = ["serde"] }
58+
rand = "0.8"
59+
tokio = { workspace = true, features = ["full"] }
60+
serde = { workspace = true, features = ["derive"] }
61+
serde_json.workspace = true
62+
async-trait.workspace = true
63+
futures.workspace = true
64+
eyre.workspace = true
65+
tracing.workspace = true
66+
67+
[lints]
68+
workspace = true

0 commit comments

Comments
 (0)