|
| 1 | +use super::context::{SignerTestContext, SignerTestState}; |
| 2 | +use madhouse::{Command, CommandWrapper}; |
| 3 | +use proptest::prelude::{Just, Strategy}; |
| 4 | +use std::sync::Arc; |
| 5 | + |
| 6 | +pub struct StallMiningCommand; |
| 7 | + |
| 8 | +impl Command<SignerTestState, SignerTestContext> for StallMiningCommand { |
| 9 | + fn check(&self, state: &SignerTestState) -> bool { |
| 10 | + println!( |
| 11 | + "Checking: Stalling mining. Result: {:?}", |
| 12 | + !state.mining_stalled |
| 13 | + ); |
| 14 | + !state.mining_stalled |
| 15 | + } |
| 16 | + |
| 17 | + fn apply(&self, state: &mut SignerTestState) { |
| 18 | + println!("Applying: Stalling mining"); |
| 19 | + crate::tests::signer::v0::test_mine_stall_set(true); |
| 20 | + state.mining_stalled = true; |
| 21 | + } |
| 22 | + |
| 23 | + fn label(&self) -> String { |
| 24 | + "STALL_MINING".to_string() |
| 25 | + } |
| 26 | + |
| 27 | + fn build( |
| 28 | + _ctx: Arc<SignerTestContext>, |
| 29 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 30 | + Just(CommandWrapper::new(StallMiningCommand)) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +pub struct RecoverFromStallCommand; |
| 35 | + |
| 36 | +impl Command<SignerTestState, SignerTestContext> for RecoverFromStallCommand { |
| 37 | + fn check(&self, state: &SignerTestState) -> bool { |
| 38 | + println!( |
| 39 | + "Checking: Recovering from mining stall. Result: {:?}", |
| 40 | + state.mining_stalled |
| 41 | + ); |
| 42 | + state.mining_stalled |
| 43 | + } |
| 44 | + |
| 45 | + fn apply(&self, state: &mut SignerTestState) { |
| 46 | + println!("Applying: Recovering from mining stall"); |
| 47 | + crate::tests::signer::v0::test_mine_stall_set(false); |
| 48 | + state.mining_stalled = false; |
| 49 | + } |
| 50 | + |
| 51 | + fn label(&self) -> String { |
| 52 | + "RECOVER_FROM_STALL".to_string() |
| 53 | + } |
| 54 | + |
| 55 | + fn build( |
| 56 | + _ctx: Arc<SignerTestContext>, |
| 57 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 58 | + Just(CommandWrapper::new(RecoverFromStallCommand)) |
| 59 | + } |
| 60 | +} |
0 commit comments