Skip to content

Commit 790178f

Browse files
authored
Npg 3331 explorer testing infra (#4084)
* explorer tests * reformat test file * reformat block.graphql * ci fixes * ci fixes * address clippy fixes * pr review refactor + ci fixes * add default for test config * cargo fmt fix * allow(clippy::derive_partial_eq_without_eq) * clippy suggestions (CI fix) * clippy suggestions (CI fix)
1 parent da5a0f5 commit 790178f

File tree

34 files changed

+831
-812
lines changed

34 files changed

+831
-812
lines changed

Cargo.lock

Lines changed: 671 additions & 761 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

explorer/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ lazy_static = "1.4"
4040
http-zipkin = "0.3.0"
4141

4242
jormungandr-lib = {path = "../jormungandr-lib"}
43+
jormungandr-automation = { path = "../testing/jormungandr-automation" }
44+
jormungandr-integration-tests = { path = "../testing/jormungandr-integration-tests" }
45+
thor = { path = "../testing/thor" }
4346

4447
cardano-legacy-address = {git = "https://github.com/input-output-hk/chain-libs.git", branch = "master"}
4548
chain-addr = {git = "https://github.com/input-output-hk/chain-libs.git", branch = "master"}

explorer/src/api/graphql/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl Block {
505505
Ok(Arc::clone(block))
506506
} else {
507507
let block = db.get_block(&self.hash).await.ok_or_else(|| {
508-
ApiError::InternalError("Couldn't find block's contents in explorer".to_owned())
508+
ApiError::InternalError("Couldn't find block in the explorer".to_owned())
509509
})?;
510510

511511
*contents = Some(Arc::clone(&block));
@@ -518,7 +518,7 @@ impl Block {
518518
db.get_block_with_branches(&self.hash)
519519
.await
520520
.ok_or_else(|| {
521-
ApiError::InternalError("Couldn't find block's contents in explorer".to_owned())
521+
ApiError::InternalError("Couldn't find block in the explorer".to_owned())
522522
})?;
523523

524524
let mut contents = self.contents.lock().await;

explorer/src/api/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ pub fn filter(
113113
parent_span_id = Empty,
114114
);
115115
if let Some(remote_addr) = info.remote_addr() {
116-
span.record("remote_addr", &remote_addr.to_string().as_str());
116+
span.record("remote_addr", remote_addr.to_string().as_str());
117117
}
118118
if let Some(trace_context) = get_trace_context(info.request_headers()) {
119-
span.record("trace_id", &trace_context.trace_id().to_string().as_str());
120-
span.record("span_id", &trace_context.span_id().to_string().as_str());
119+
span.record("trace_id", trace_context.trace_id().to_string().as_str());
120+
span.record("span_id", trace_context.span_id().to_string().as_str());
121121
if let Some(parent_span_id) = trace_context.parent_id() {
122-
span.record("parent_span_id", &parent_span_id.to_string().as_str());
122+
span.record("parent_span_id", parent_span_id.to_string().as_str());
123123
}
124124
}
125125
span

explorer/src/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl LogSettings {
123123
.create(true)
124124
.write(true)
125125
.append(true)
126-
.open(&path)
126+
.open(path)
127127
.map_err(|cause| Error::File {
128128
path: path.clone(),
129129
cause,

explorer/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ mod indexer;
44
mod logging;
55
mod settings;
66

7+
#[cfg(test)]
8+
mod tests;
9+
710
use crate::indexer::Indexer;
811
use anyhow::Context;
912
use chain_core::{packer::Codec, property::Deserialize};

explorer/src/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ mod filter_level_opt_serde {
252252
Option::<String>::deserialize(deserializer)?
253253
.map(|variant| {
254254
variant.parse().map_err(|_| {
255-
D::Error::unknown_variant(&variant, &**LOG_FILTER_LEVEL_POSSIBLE_VALUES)
255+
D::Error::unknown_variant(&variant, &LOG_FILTER_LEVEL_POSSIBLE_VALUES)
256256
})
257257
})
258258
.transpose()

explorer/src/tests.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}

jcli/src/jcli_lib/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn address_info(address: &AddressReadable) -> Result<(), Error> {
118118
println!("public key: {}", pubk.to_bech32_str());
119119
println!("group key: {}", groupk.to_bech32_str());
120120
}
121-
Kind::Script(id) => println!("script identifier: {}", hex::encode(&id)),
121+
Kind::Script(id) => println!("script identifier: {}", hex::encode(id)),
122122
}
123123
Ok(())
124124
}

jormungandr-lib/src/interfaces/committee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Serialize for CommitteeIdDef {
5050
S: Serializer,
5151
{
5252
if serializer.is_human_readable() {
53-
let hex = hex::encode(&self.0);
53+
let hex = hex::encode(self.0);
5454
serializer.serialize_str(&hex)
5555
} else {
5656
serializer.serialize_bytes(&self.0)

0 commit comments

Comments
 (0)