|
| 1 | +use chain_core::property::FromStr; |
| 2 | +use jormungandr_automation::jormungandr::{ |
| 3 | + explorer::configuration::ExplorerParams, ConfigurationBuilder, Explorer, JormungandrProcess, |
| 4 | +}; |
| 5 | +use jormungandr_integration_tests::startup; |
| 6 | +use jormungandr_lib::{crypto::hash::Hash, interfaces::ActiveSlotCoefficient}; |
| 7 | + |
| 8 | +pub struct ExplorerTestConfig { |
| 9 | + query_complexity_limit: u64, |
| 10 | +} |
| 11 | + |
| 12 | +impl Default for ExplorerTestConfig { |
| 13 | + fn default() -> Self { |
| 14 | + ExplorerTestConfig { |
| 15 | + query_complexity_limit: 150, |
| 16 | + } |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +pub fn explorer_test_context( |
| 21 | + test_config: ExplorerTestConfig, |
| 22 | +) -> ( |
| 23 | + jormungandr_automation::jormungandr::ExplorerProcess, |
| 24 | + JormungandrProcess, |
| 25 | +) { |
| 26 | + let faucet = thor::Wallet::default(); |
| 27 | + |
| 28 | + let mut config = ConfigurationBuilder::new(); |
| 29 | + config.with_consensus_genesis_praos_active_slot_coeff(ActiveSlotCoefficient::MAXIMUM); |
| 30 | + |
| 31 | + let (jormungandr, _initial_stake_pools) = |
| 32 | + startup::start_stake_pool(&[faucet], &[], &mut config).unwrap(); |
| 33 | + |
| 34 | + let params = ExplorerParams::new(test_config.query_complexity_limit, None, None); |
| 35 | + |
| 36 | + (jormungandr.explorer(params), jormungandr) |
| 37 | +} |
| 38 | + |
| 39 | +pub fn get_invalid_block(explorer: &Explorer) { |
| 40 | + let hash = |
| 41 | + Hash::from_str("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap(); |
| 42 | + |
| 43 | + let predicted_errors = vec![ |
| 44 | + "internal error (this shouldn't happen) Couldn't find block in the explorer".to_string(), |
| 45 | + ]; |
| 46 | + |
| 47 | + let actual_errors: Vec<String> = explorer |
| 48 | + .block(hash) |
| 49 | + .unwrap() |
| 50 | + .errors |
| 51 | + .unwrap() |
| 52 | + .iter() |
| 53 | + .map(|error| error.message.to_string()) |
| 54 | + .collect(); |
| 55 | + |
| 56 | + assert_eq!(predicted_errors, actual_errors); |
| 57 | +} |
| 58 | + |
| 59 | +pub fn get_valid_block(explorer: &Explorer, genesis_block: Hash) { |
| 60 | + let block_id = explorer |
| 61 | + .block(genesis_block) |
| 62 | + .unwrap() |
| 63 | + .data |
| 64 | + .unwrap() |
| 65 | + .block |
| 66 | + .id; |
| 67 | + assert_eq!(block_id, genesis_block.to_string()); |
| 68 | +} |
| 69 | + |
| 70 | +#[test] |
| 71 | +pub fn explorer_tests() { |
| 72 | + let config = ExplorerTestConfig::default(); |
| 73 | + |
| 74 | + let (explorer, jormungandr) = explorer_test_context(config); |
| 75 | + |
| 76 | + get_invalid_block(explorer.client()); |
| 77 | + get_valid_block(explorer.client(), jormungandr.genesis_block_hash()); |
| 78 | +} |
0 commit comments