Skip to content

Commit ac46fe3

Browse files
authored
feat: runs devnet 2 in tests for ci and make (#1101)
1 parent 6b5b179 commit ac46fe3

File tree

8 files changed

+48
-101
lines changed

8 files changed

+48
-101
lines changed

.github/workflows/core-rust.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
run: |
4848
cargo clippy --all --all-targets --no-deps -- --deny warnings # clippy for ream, default features
4949
cargo clippy --package ream-bls --all-targets --features "supranational" --no-deps -- --deny warnings # clippy for ream-bls, supranational feature
50+
make clippy-devnet2
5051
5152
cargo-sort:
5253
runs-on: ubuntu-latest
@@ -93,6 +94,20 @@ jobs:
9394
- name: Test
9495
run: cargo test --release --workspace -- --nocapture
9596

97+
test-devnet2:
98+
runs-on: ubuntu-latest
99+
needs: [format, cargo-clippy]
100+
101+
steps:
102+
- uses: actions/checkout@v4
103+
104+
- uses: Swatinem/rust-cache@v2
105+
with:
106+
cache-on-failure: true
107+
108+
- name: Test Devnet 2
109+
run: make test-devnet2
110+
96111
ef-tests:
97112
runs-on: ubuntu-latest
98113
needs: [format, cargo-clippy]

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ install: # Build and install the Ream binary under `~/.cargo/bin`.
4040
##@ Testing and Linting
4141

4242
.PHONY: test
43-
test: # Run all tests.
43+
test: # Run all tests (defaults to devnet1).
4444
cargo test --workspace -- --nocapture
4545

46+
.PHONY: test-devnet2
47+
test-devnet2: # Run all tests for for Devnet 2.
48+
cargo test --workspace --no-default-features --features "devnet2" -- --nocapture
49+
4650
.PHONY: fmt
4751
fmt: # Run `rustfmt` on the entire workspace and enfore closure variables on `map_err` to be `err`
4852
cargo +nightly fmt --all
@@ -73,6 +77,10 @@ clippy: # Run `clippy` on the entire workspace.
7377
cargo clippy --all --all-targets --features "$(FEATURES)" --no-deps -- --deny warnings
7478
cargo clippy --package ream-bls --all-targets --features "supranational" --no-deps -- --deny warnings
7579

80+
.PHONY: clippy-devnet2
81+
clippy-devnet2: # Run `clippy` for Devnet 2.
82+
cargo clippy --workspace --all-targets --no-default-features --features "devnet2" --no-deps -- --deny warnings
83+
7684
.PHONY: sort
7785
sort: # Run `cargo sort` on the entire workspace.
7886
cargo sort --grouped --workspace

bin/ream/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,9 @@ mod tests {
710710
use clap::Parser;
711711
use ream::cli::{Cli, Commands};
712712
use ream_executor::ReamExecutor;
713-
use ream_storage::{
714-
db::ReamDB,
715-
dir::setup_data_dir,
716-
tables::{field::REDBField, table::REDBTable},
717-
};
713+
#[cfg(feature = "devnet1")]
714+
use ream_storage::tables::{field::REDBField, table::REDBTable};
715+
use ream_storage::{db::ReamDB, dir::setup_data_dir};
718716
use tokio::time::{sleep, timeout};
719717

720718
use crate::{APP_NAME, run_lean_node};
@@ -758,7 +756,9 @@ mod tests {
758756
handle.abort();
759757
}
760758

759+
/// TODO: Get finalization working for devnet2
761760
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
761+
#[cfg(feature = "devnet1")]
762762
async fn test_lean_node_finalizes() {
763763
let cli = Cli::parse_from([
764764
"ream",

crates/common/consensus/lean/src/attestation.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct SignedAggregatedAttestation {
107107
}
108108

109109
#[cfg(test)]
110+
#[cfg(feature = "devnet1")]
110111
mod tests {
111112
use alloy_primitives::hex;
112113
use ssz::{Decode, Encode};
@@ -117,7 +118,6 @@ mod tests {
117118
#[test]
118119
fn test_encode_decode_signed_attestation_roundtrip() -> anyhow::Result<()> {
119120
let signed_attestation = SignedAttestation {
120-
#[cfg(feature = "devnet1")]
121121
message: Attestation {
122122
validator_id: 0,
123123
data: AttestationData {
@@ -127,15 +127,6 @@ mod tests {
127127
source: Checkpoint::default(),
128128
},
129129
},
130-
#[cfg(feature = "devnet2")]
131-
message: AttestationData {
132-
slot: 1,
133-
head: Checkpoint::default(),
134-
target: Checkpoint::default(),
135-
source: Checkpoint::default(),
136-
},
137-
#[cfg(feature = "devnet2")]
138-
validator_id: 0,
139130
signature: Signature {
140131
inner: FixedBytes::default(),
141132
},

crates/common/consensus/lean/src/block.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ pub struct BlockWithSignatures {
220220
}
221221

222222
#[cfg(test)]
223+
#[cfg(feature = "devnet1")]
223224
mod tests {
224-
225225
use alloy_primitives::hex;
226226
use ssz::{Decode, Encode};
227227

@@ -241,7 +241,6 @@ mod tests {
241241
attestations: Default::default(),
242242
},
243243
},
244-
#[cfg(feature = "devnet1")]
245244
proposer_attestation: Attestation {
246245
validator_id: 0,
247246
data: AttestationData {
@@ -251,24 +250,8 @@ mod tests {
251250
source: Checkpoint::default(),
252251
},
253252
},
254-
#[cfg(feature = "devnet2")]
255-
proposer_attestation: AggregatedAttestations {
256-
validator_id: 0,
257-
data: AttestationData {
258-
slot: 0,
259-
head: Checkpoint::default(),
260-
target: Checkpoint::default(),
261-
source: Checkpoint::default(),
262-
},
263-
},
264253
},
265-
#[cfg(feature = "devnet1")]
266254
signature: VariableList::default(),
267-
#[cfg(feature = "devnet2")]
268-
signature: BlockSignatures {
269-
attestation_signatures: VariableList::default(),
270-
proposer_signature: Signature::blank(),
271-
},
272255
};
273256

274257
let encode = signed_block_with_attestation.as_ssz_bytes();

crates/common/consensus/lean/src/state.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,10 @@ impl LeanState {
448448

449449
#[cfg(feature = "devnet2")]
450450
for (validator_id, signed) in attestation.aggregation_bits.iter().enumerate() {
451-
if signed {
452-
if !justifications.get(validator_id).unwrap_or(false) {
453-
justifications.set(validator_id, true).map_err(|err| {
454-
anyhow!("Failed to set validator {validator_id}: {err:?}")
455-
})?;
456-
}
451+
if signed && !justifications.get(validator_id).unwrap_or(false) {
452+
justifications.set(validator_id, true).map_err(|err| {
453+
anyhow!("Failed to set validator {validator_id}: {err:?}")
454+
})?;
457455
}
458456
}
459457

crates/common/fork_choice/lean/src/store.rs

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -908,19 +908,19 @@ mod tests {
908908
use alloy_primitives::{B256, FixedBytes};
909909
#[cfg(feature = "devnet1")]
910910
use ream_consensus_lean::attestation::Attestation;
911+
#[cfg(feature = "devnet1")]
912+
use ream_consensus_lean::block::{BlockBody, BlockHeader};
913+
#[cfg(feature = "devnet1")]
914+
use ream_consensus_lean::config::Config;
911915
#[cfg(feature = "devnet2")]
912916
use ream_consensus_lean::{
913917
attestation::{AggregatedAttestation, AggregatedAttestations},
914918
block::BlockSignatures,
915919
};
916920
use ream_consensus_lean::{
917921
attestation::{AttestationData, SignedAttestation},
918-
block::{
919-
Block, BlockBody, BlockHeader, BlockWithAttestation, BlockWithSignatures,
920-
SignedBlockWithAttestation,
921-
},
922+
block::{Block, BlockWithAttestation, BlockWithSignatures, SignedBlockWithAttestation},
922923
checkpoint::Checkpoint,
923-
config::Config,
924924
state::LeanState,
925925
utils::generate_default_validators,
926926
validator::is_proposer,
@@ -1014,6 +1014,7 @@ mod tests {
10141014

10151015
/// Test basic block production by authorized proposer.
10161016
#[tokio::test]
1017+
#[cfg(feature = "devnet1")]
10171018
async fn test_produce_block_basic() {
10181019
let (mut store, mut genesis_state) = sample_store(10).await;
10191020

@@ -1187,6 +1188,7 @@ mod tests {
11871188

11881189
/// Test that produced block's state is consistent with block content
11891190
#[tokio::test]
1191+
#[cfg(feature = "devnet1")]
11901192
pub async fn test_produce_block_state_consistency() {
11911193
let (mut store, _) = sample_store(10).await;
11921194

@@ -1203,7 +1205,6 @@ mod tests {
12031205
let head_block = block_provider.get(head).unwrap().unwrap();
12041206

12051207
let attestation = SignedAttestation {
1206-
#[cfg(feature = "devnet1")]
12071208
message: Attestation {
12081209
validator_id: 7,
12091210
data: AttestationData {
@@ -1216,19 +1217,7 @@ mod tests {
12161217
source: store.get_attestation_target().await.unwrap(),
12171218
},
12181219
},
1219-
#[cfg(feature = "devnet2")]
1220-
message: AttestationData {
1221-
slot: head_block.message.block.slot,
1222-
head: Checkpoint {
1223-
root: head,
1224-
slot: head_block.message.block.slot,
1225-
},
1226-
target: latest_justified_provider.get().unwrap(),
1227-
source: store.get_attestation_target().await.unwrap(),
1228-
},
12291220
signature: Signature::blank(),
1230-
#[cfg(feature = "devnet2")]
1231-
validator_id: 7,
12321221
};
12331222
latest_known_attestations.insert(7, attestation).unwrap();
12341223

@@ -1456,6 +1445,7 @@ mod tests {
14561445

14571446
/// Test producing a block then creating attestation for it.
14581447
#[tokio::test]
1448+
#[cfg(feature = "devnet1")]
14591449
pub async fn test_block_production_then_attestation() {
14601450
let (mut store, _) = sample_store(10).await;
14611451

@@ -1479,42 +1469,22 @@ mod tests {
14791469

14801470
store.update_head().await.unwrap();
14811471

1482-
#[cfg(feature = "devnet1")]
14831472
let attestation = Attestation {
14841473
validator_id: 7,
14851474
data: store.produce_attestation_data(2).await.unwrap(),
14861475
};
14871476

1488-
#[cfg(feature = "devnet2")]
1489-
let mut aggregation_bits = BitList::<U4096>::with_capacity(32).unwrap();
1490-
#[cfg(feature = "devnet2")]
1491-
aggregation_bits.set(0, true).unwrap();
1492-
1493-
#[cfg(feature = "devnet2")]
1494-
let attestation = AggregatedAttestation {
1495-
aggregation_bits,
1496-
message: store.produce_attestation_data(2).await.unwrap(),
1497-
};
1498-
1499-
#[cfg(feature = "devnet1")]
15001477
assert_eq!(attestation.validator_id, 7);
1501-
#[cfg(feature = "devnet2")]
1502-
assert_eq!(attestation.aggregation_bits, attestation.aggregation_bits);
15031478
assert_eq!(attestation.slot(), 2);
1504-
#[cfg(feature = "devnet1")]
15051479
assert_eq!(
15061480
attestation.data.source,
15071481
latest_justified_provider.get().unwrap()
15081482
);
1509-
#[cfg(feature = "devnet2")]
1510-
assert_eq!(
1511-
attestation.message.source,
1512-
latest_justified_provider.get().unwrap()
1513-
);
15141483
}
15151484

15161485
/// Test producing a block then creating attestation for it.
15171486
#[tokio::test]
1487+
#[cfg(feature = "devnet1")]
15181488
pub async fn test_multiple_validators_coordination() {
15191489
let (mut store, _) = sample_store(10).await;
15201490

@@ -1543,17 +1513,11 @@ mod tests {
15431513

15441514
let mut attestations = Vec::new();
15451515
for i in 2..6 {
1546-
#[cfg(feature = "devnet1")]
15471516
let attestation = Attestation {
15481517
validator_id: i,
15491518
data: store.produce_attestation_data(2).await.unwrap(),
15501519
};
15511520

1552-
#[cfg(feature = "devnet2")]
1553-
let attestation = AggregatedAttestations {
1554-
validator_id: i,
1555-
data: store.produce_attestation_data(2).await.unwrap(),
1556-
};
15571521
attestations.push(attestation);
15581522
}
15591523

@@ -1602,6 +1566,7 @@ mod tests {
16021566

16031567
/// Test edge cases in validator operations.
16041568
#[tokio::test]
1569+
#[cfg(feature = "devnet1")]
16051570
pub async fn test_validator_edge_cases() {
16061571
let (mut store, _) = sample_store(10).await;
16071572

@@ -1620,31 +1585,18 @@ mod tests {
16201585
.await
16211586
.unwrap();
16221587

1623-
#[cfg(feature = "devnet1")]
16241588
let attestation = Attestation {
16251589
validator_id: 9,
16261590
data: store.produce_attestation_data(10).await.unwrap(),
16271591
};
16281592

1629-
#[cfg(feature = "devnet2")]
1630-
let mut aggregation_bits = BitList::<U4096>::with_capacity(32).unwrap();
1631-
#[cfg(feature = "devnet2")]
1632-
aggregation_bits.set(0, true).unwrap();
1633-
1634-
#[cfg(feature = "devnet2")]
1635-
let attestation = AggregatedAttestation {
1636-
aggregation_bits,
1637-
message: store.produce_attestation_data(10).await.unwrap(),
1638-
};
1639-
#[cfg(feature = "devnet1")]
16401593
assert_eq!(attestation.validator_id, 9);
1641-
#[cfg(feature = "devnet2")]
1642-
assert_eq!(attestation.aggregation_bits, attestation.aggregation_bits);
16431594
assert_eq!(attestation.slot(), 10);
16441595
}
16451596

16461597
/// Test validator operations with minimal store state.
16471598
#[tokio::test]
1599+
#[cfg(feature = "devnet1")]
16481600
pub async fn test_validator_operations_empty_store() {
16491601
let empty_checkpoint = Checkpoint {
16501602
slot: 0,

testing/lean-spec-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version.workspace = true
1212
[features]
1313
lean-spec-tests = []
1414
default = ["devnet1"]
15-
devnet1 = []
16-
devnet2 = []
15+
devnet1 = ["ream-consensus-lean/devnet1", "ream-fork-choice-lean/devnet1"]
16+
devnet2 = ["ream-consensus-lean/devnet2", "ream-fork-choice-lean/devnet2"]
1717

1818
[dependencies]
1919
alloy-primitives.workspace = true

0 commit comments

Comments
 (0)