|
| 1 | +use super::context::{SignerTestContext, SignerTestState}; |
| 2 | +use madhouse::{Command, CommandWrapper}; |
| 3 | +use proptest::prelude::{Just, Strategy}; |
| 4 | +use stacks::util::tests::TestFlag; |
| 5 | +use std::sync::Arc; |
| 6 | + |
| 7 | +pub struct SkipCommitOpPrimaryMiner { |
| 8 | + miner_1_skip_commit_flag: TestFlag<bool>, |
| 9 | +} |
| 10 | + |
| 11 | +impl SkipCommitOpPrimaryMiner { |
| 12 | + pub fn new(miner_1_skip_commit_flag: TestFlag<bool>) -> Self { |
| 13 | + Self { |
| 14 | + miner_1_skip_commit_flag, |
| 15 | + } |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +impl Command<SignerTestState, SignerTestContext> for SkipCommitOpPrimaryMiner { |
| 20 | + fn check(&self, state: &SignerTestState) -> bool { |
| 21 | + println!( |
| 22 | + "Checking: Skipping commit operations for miner 1. Result: {:?}", |
| 23 | + !state.is_primary_miner_skip_commit_op |
| 24 | + ); |
| 25 | + !state.is_primary_miner_skip_commit_op |
| 26 | + } |
| 27 | + |
| 28 | + fn apply(&self, state: &mut SignerTestState) { |
| 29 | + println!("Applying: Skipping commit operations for miner 1"); |
| 30 | + |
| 31 | + self.miner_1_skip_commit_flag.set(true); |
| 32 | + |
| 33 | + state.is_primary_miner_skip_commit_op = true; |
| 34 | + } |
| 35 | + |
| 36 | + fn label(&self) -> String { |
| 37 | + "SKIP_COMMIT_OP_PRIMARY_MINER".to_string() |
| 38 | + } |
| 39 | + |
| 40 | + fn build( |
| 41 | + ctx: Arc<SignerTestContext>, |
| 42 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 43 | + Just(CommandWrapper::new(SkipCommitOpPrimaryMiner::new( |
| 44 | + ctx.miners.lock().unwrap().get_primary_skip_commit_flag(), |
| 45 | + ))) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +pub struct SkipCommitOpSecondaryMiner { |
| 50 | + miner_2_skip_commit_flag: TestFlag<bool>, |
| 51 | +} |
| 52 | + |
| 53 | +impl SkipCommitOpSecondaryMiner { |
| 54 | + pub fn new(miner_2_skip_commit_flag: TestFlag<bool>) -> Self { |
| 55 | + Self { |
| 56 | + miner_2_skip_commit_flag, |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +impl Command<SignerTestState, SignerTestContext> for SkipCommitOpSecondaryMiner { |
| 62 | + fn check(&self, state: &SignerTestState) -> bool { |
| 63 | + println!( |
| 64 | + "Checking: Skipping commit operations for miner 2. Result: {:?}", |
| 65 | + !state.is_secondary_miner_skip_commit_op |
| 66 | + ); |
| 67 | + !state.is_secondary_miner_skip_commit_op |
| 68 | + } |
| 69 | + |
| 70 | + fn apply(&self, state: &mut SignerTestState) { |
| 71 | + println!("Applying: Skipping commit operations for miner 2"); |
| 72 | + |
| 73 | + self.miner_2_skip_commit_flag.set(true); |
| 74 | + |
| 75 | + state.is_secondary_miner_skip_commit_op = true; |
| 76 | + } |
| 77 | + |
| 78 | + fn label(&self) -> String { |
| 79 | + "SKIP_COMMIT_OP_SECONDARY_MINER".to_string() |
| 80 | + } |
| 81 | + |
| 82 | + fn build( |
| 83 | + ctx: Arc<SignerTestContext>, |
| 84 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 85 | + Just(CommandWrapper::new(SkipCommitOpSecondaryMiner::new( |
| 86 | + ctx.miners.lock().unwrap().get_secondary_skip_commit_flag(), |
| 87 | + ))) |
| 88 | + } |
| 89 | +} |
0 commit comments