|
| 1 | +use std::sync::{Arc, Mutex}; |
| 2 | + |
| 3 | +use madhouse::{Command, CommandWrapper}; |
| 4 | +use proptest::prelude::{Just, Strategy}; |
| 5 | + |
| 6 | +use crate::tests::signer::v0::{verify_sortition_winner, MultipleMinerTest}; |
| 7 | + |
| 8 | +use super::{context::SignerTestState, SignerTestContext}; |
| 9 | + |
| 10 | +pub struct VerifyMiner1WonSortition { |
| 11 | + miners: Arc<Mutex<MultipleMinerTest>>, |
| 12 | +} |
| 13 | + |
| 14 | +impl VerifyMiner1WonSortition { |
| 15 | + pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self { |
| 16 | + Self { miners } |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +impl Command<SignerTestState, SignerTestContext> for VerifyMiner1WonSortition { |
| 21 | + fn check(&self, _state: &SignerTestState) -> bool { |
| 22 | + info!( |
| 23 | + "Checking: Verifying miner 1 won sortition. Result: {:?}", |
| 24 | + true |
| 25 | + ); |
| 26 | + true |
| 27 | + } |
| 28 | + |
| 29 | + fn apply(&self, _state: &mut SignerTestState) { |
| 30 | + info!("Applying: Verifying miner 1 won sortition"); |
| 31 | + |
| 32 | + let (conf_1, _) = self.miners.lock().unwrap().get_node_configs(); |
| 33 | + let burnchain = conf_1.get_burnchain(); |
| 34 | + let sortdb = burnchain.open_sortition_db(true).unwrap(); |
| 35 | + let (miner_pkh_1, _) = self.miners.lock().unwrap().get_miner_public_key_hashes(); |
| 36 | + |
| 37 | + verify_sortition_winner(&sortdb, &miner_pkh_1); |
| 38 | + } |
| 39 | + fn label(&self) -> String { |
| 40 | + "VERIFY_MINER_1_WON_SORTITION".to_string() |
| 41 | + } |
| 42 | + fn build( |
| 43 | + ctx: Arc<SignerTestContext>, |
| 44 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 45 | + Just(CommandWrapper::new(VerifyMiner1WonSortition::new( |
| 46 | + ctx.miners.clone(), |
| 47 | + ))) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +pub struct VerifyMiner2WonSortition { |
| 52 | + miners: Arc<Mutex<MultipleMinerTest>>, |
| 53 | +} |
| 54 | + |
| 55 | +impl VerifyMiner2WonSortition { |
| 56 | + pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self { |
| 57 | + Self { miners } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +impl Command<SignerTestState, SignerTestContext> for VerifyMiner2WonSortition { |
| 62 | + fn check(&self, _state: &SignerTestState) -> bool { |
| 63 | + info!( |
| 64 | + "Checking: Verifying miner 2 won sortition. Result: {:?}", |
| 65 | + true |
| 66 | + ); |
| 67 | + true |
| 68 | + } |
| 69 | + |
| 70 | + fn apply(&self, _state: &mut SignerTestState) { |
| 71 | + info!("Applying: Verifying miner 2 won sortition"); |
| 72 | + |
| 73 | + let (conf_1, _) = self.miners.lock().unwrap().get_node_configs(); |
| 74 | + let burnchain = conf_1.get_burnchain(); |
| 75 | + let sortdb = burnchain.open_sortition_db(true).unwrap(); |
| 76 | + let (_, miner_pkh_2) = self.miners.lock().unwrap().get_miner_public_key_hashes(); |
| 77 | + |
| 78 | + verify_sortition_winner(&sortdb, &miner_pkh_2); |
| 79 | + } |
| 80 | + fn label(&self) -> String { |
| 81 | + "VERIFY_MINER_2_WON_SORTITION".to_string() |
| 82 | + } |
| 83 | + fn build( |
| 84 | + ctx: Arc<SignerTestContext>, |
| 85 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 86 | + Just(CommandWrapper::new(VerifyMiner2WonSortition::new( |
| 87 | + ctx.miners.clone(), |
| 88 | + ))) |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +pub struct VerifyLastSortitionWinnerReorged { |
| 93 | + miners: Arc<Mutex<MultipleMinerTest>>, |
| 94 | +} |
| 95 | + |
| 96 | +impl VerifyLastSortitionWinnerReorged { |
| 97 | + pub fn new(miners: Arc<Mutex<MultipleMinerTest>>) -> Self { |
| 98 | + Self { miners } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +impl Command<SignerTestState, SignerTestContext> for VerifyLastSortitionWinnerReorged { |
| 103 | + fn check(&self, _state: &SignerTestState) -> bool { |
| 104 | + info!( |
| 105 | + "Checking: Verifying last sortition winner reorged. Result: {:?}", |
| 106 | + true |
| 107 | + ); |
| 108 | + true |
| 109 | + } |
| 110 | + |
| 111 | + fn apply(&self, _state: &mut SignerTestState) { |
| 112 | + info!("Applying: Verifying last sortition winner reorged"); |
| 113 | + self.miners |
| 114 | + .lock() |
| 115 | + .unwrap() |
| 116 | + .assert_last_sortition_winner_reorged(); |
| 117 | + } |
| 118 | + |
| 119 | + fn label(&self) -> String { |
| 120 | + "VERIFY_LAST_SORTITION_WINNER_REORGED".to_string() |
| 121 | + } |
| 122 | + |
| 123 | + fn build( |
| 124 | + ctx: Arc<SignerTestContext>, |
| 125 | + ) -> impl Strategy<Value = CommandWrapper<SignerTestState, SignerTestContext>> { |
| 126 | + Just(CommandWrapper::new(VerifyLastSortitionWinnerReorged::new( |
| 127 | + ctx.miners.clone(), |
| 128 | + ))) |
| 129 | + } |
| 130 | +} |
0 commit comments