Skip to content

Commit 9290725

Browse files
Add tests/signer/commands/block_commit.rs
Co-authored-by: Nikos Baxevanis <[email protected]>
1 parent fe55a46 commit 9290725

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use super::context::{SignerTestContext, SignerTestState};
2+
use crate::tests::signer::v0::MultipleMinerTest;
3+
use madhouse::{Command, CommandWrapper};
4+
use proptest::prelude::{Just, Strategy};
5+
use std::sync::{Arc, Mutex};
6+
7+
pub struct SubmitBlockCommitSecondaryMinerCommand {
8+
miners: Arc<Mutex<MultipleMinerTest>>,
9+
}
10+
11+
impl SubmitBlockCommitSecondaryMinerCommand {
12+
pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self {
13+
Self { miners }
14+
}
15+
}
16+
17+
impl Command<SignerTestState, SignerTestContext> for SubmitBlockCommitSecondaryMinerCommand {
18+
fn check(&self, state: &SignerTestState) -> bool {
19+
println!(
20+
"Checking: Submitting block commit miner 2. Result: {:?}",
21+
state.is_secondary_miner_skip_commit_op
22+
);
23+
state.is_secondary_miner_skip_commit_op
24+
}
25+
26+
fn apply(&self, _state: &mut SignerTestState) {
27+
println!("Applying: Submitting block commit miner 2");
28+
29+
let (conf_1, _) = self.miners.lock().unwrap().get_node_configs();
30+
let burnchain = conf_1.get_burnchain();
31+
let sortdb = burnchain.open_sortition_db(true).unwrap();
32+
33+
self.miners.lock().unwrap().submit_commit_miner_2(&sortdb);
34+
}
35+
36+
fn label(&self) -> String {
37+
"SUBMIT_BLOCK_COMMIT_SECONDARY_MINER".to_string()
38+
}
39+
40+
fn build(
41+
ctx: Arc<SignerTestContext>,
42+
) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> {
43+
Just(CommandWrapper::new(
44+
SubmitBlockCommitSecondaryMinerCommand::new(ctx.miners.clone()),
45+
))
46+
}
47+
}
48+
49+
pub struct SubmitBlockCommitPrimaryMinerCommand {
50+
miners: Arc<Mutex<MultipleMinerTest>>,
51+
}
52+
53+
impl SubmitBlockCommitPrimaryMinerCommand {
54+
pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self {
55+
Self { miners }
56+
}
57+
}
58+
59+
impl Command<SignerTestState, SignerTestContext> for SubmitBlockCommitPrimaryMinerCommand {
60+
fn check(&self, state: &SignerTestState) -> bool {
61+
println!(
62+
"Checking: Submitting block commit miner 1. Result: {:?}",
63+
state.is_primary_miner_skip_commit_op
64+
);
65+
state.is_primary_miner_skip_commit_op
66+
}
67+
68+
fn apply(&self, _state: &mut SignerTestState) {
69+
println!("Applying: Submitting block commit miner 1");
70+
71+
let (conf_1, _) = self.miners.lock().unwrap().get_node_configs();
72+
let burnchain = conf_1.get_burnchain();
73+
let sortdb = burnchain.open_sortition_db(true).unwrap();
74+
75+
self.miners.lock().unwrap().submit_commit_miner_1(&sortdb);
76+
}
77+
78+
fn label(&self) -> String {
79+
"SUBMIT_BLOCK_COMMIT_PRIMARY_MINER".to_string()
80+
}
81+
82+
fn build(
83+
ctx: Arc<SignerTestContext>,
84+
) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> {
85+
Just(CommandWrapper::new(
86+
SubmitBlockCommitPrimaryMinerCommand::new(ctx.miners.clone()),
87+
))
88+
}
89+
}

0 commit comments

Comments
 (0)