|
| 1 | +use super::context::{SignerTestContext, SignerTestState}; |
| 2 | +use crate::tests::signer::v0::MultipleMinerTest; |
| 3 | +use madhouse::{Command, CommandWrapper}; |
| 4 | +use proptest::prelude::Strategy; |
| 5 | +use std::sync::{Arc, Mutex}; |
| 6 | + |
| 7 | +pub struct MineTenureCommand { |
| 8 | + miners: Arc<Mutex<MultipleMinerTest>>, |
| 9 | + timeout_secs: u64, |
| 10 | +} |
| 11 | + |
| 12 | +impl MineTenureCommand { |
| 13 | + pub fn new(miners: Arc<Mutex<MultipleMinerTest>>, timeout_secs: u64) -> Self { |
| 14 | + Self { |
| 15 | + miners, |
| 16 | + timeout_secs, |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +impl Command<SignerTestState, SignerTestContext> for MineTenureCommand { |
| 22 | + fn check(&self, _state: &SignerTestState) -> bool { |
| 23 | + println!("Checking: Mining tenure. Result: {:?}", true); |
| 24 | + true |
| 25 | + } |
| 26 | + |
| 27 | + fn apply(&self, _state: &mut SignerTestState) { |
| 28 | + println!( |
| 29 | + "Applying: Mining tenure and waiting for it for {:?} seconds", |
| 30 | + self.timeout_secs |
| 31 | + ); |
| 32 | + |
| 33 | + let sortdb = { |
| 34 | + let miners = self.miners.lock().unwrap(); |
| 35 | + let (conf_1, _) = miners.get_node_configs(); |
| 36 | + let burnchain = conf_1.get_burnchain(); |
| 37 | + let sortdb = burnchain.open_sortition_db(true).unwrap(); |
| 38 | + sortdb |
| 39 | + }; |
| 40 | + |
| 41 | + { |
| 42 | + let mut miners = self.miners.lock().unwrap(); |
| 43 | + miners |
| 44 | + .mine_bitcoin_blocks_and_confirm(&sortdb, 1, self.timeout_secs) |
| 45 | + .expect("Failed to mine BTC block"); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + fn label(&self) -> String { |
| 50 | + "MINE_TENURE".to_string() |
| 51 | + } |
| 52 | + |
| 53 | + fn build( |
| 54 | + ctx: Arc<SignerTestContext>, |
| 55 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 56 | + (60u64..90u64).prop_map(move |timeout_secs| { |
| 57 | + CommandWrapper::new(MineTenureCommand::new(ctx.miners.clone(), timeout_secs)) |
| 58 | + }) |
| 59 | + } |
| 60 | +} |
0 commit comments