Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for root candidates #200

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions trustchain-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ uuid = { version = "1.2.2", features = ["v4", "fast-rng", "macro-diagnostics"] }

[dev-dependencies]
axum-test-helper = "0.2.0"
itertools = "0.13.0"
mockall = "0.11.4"
tempfile = "3.9.0"
7 changes: 4 additions & 3 deletions trustchain-http/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ mod tests {
use super::*;
use crate::{config::HTTPConfig, server::TrustchainRouter};
use axum_test_helper::TestClient;
use itertools::Itertools;

#[tokio::test]
#[ignore = "requires MongoDB and Bitcoin RPC"]
Expand All @@ -178,13 +179,13 @@ mod tests {
let result: RootCandidatesResult = serde_json::from_str(&response.text().await).unwrap();

assert_eq!(result.date, NaiveDate::from_ymd_opt(2022, 10, 20).unwrap());

let sorted_root_candidates = result.root_candidates.into_iter().sorted().collect_vec();
assert_eq!(
result.root_candidates[16].did,
sorted_root_candidates[26].did,
"did:ion:test:EiCClfEdkTv_aM3UnBBhlOV89LlGhpQAbfeZLFdFxVFkEg"
);
assert_eq!(
result.root_candidates[16].txid,
sorted_root_candidates[26].txid,
"9dc43cca950d923442445340c2e30bc57761a62ef3eaf2417ec5c75784ea9c2c"
);
}
Expand Down
1 change: 1 addition & 0 deletions trustchain-ion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ tokio = { version = "1.20.1", features = ["full"] }

[dev-dependencies]
glob = "0.3"
itertools = "0.13.0"
mockall = "0.11.2"
29 changes: 18 additions & 11 deletions trustchain-ion/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl From<TrustchainMongodbError> for TrustchainRootError {
}

/// Struct representing a root DID candidate.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, PartialOrd, Eq, Ord)]
#[serde(rename_all = "camelCase")]
pub struct RootCandidate {
pub did: String,
Expand Down Expand Up @@ -120,13 +120,20 @@ pub async fn root_did_candidates(

#[cfg(test)]
mod tests {
use itertools::Itertools;

use super::*;

#[tokio::test]
#[ignore = "Integration test requires Bitcoin & MongoDB"]
async fn test_root_did_candidates() {
let date = NaiveDate::from_ymd_opt(2022, 10, 20).unwrap();
let result = root_did_candidates(date).await.unwrap();
let result = root_did_candidates(date)
.await
.unwrap()
.into_iter()
.sorted()
.collect_vec();

// There were 38 testnet ION operations with opIndex 0 on 20th Oct 2022.
// The block height range on that date is (2377360, 2377519).
Expand All @@ -136,33 +143,33 @@ mod tests {

assert_eq!(
result[0].did,
"did:ion:test:EiAcmytgsm-AUWtmJ9cioW-MWq-DnjIUfGYdIVUnrpg6kw"
"did:ion:test:EiA6m4-V4fW_l1xEu3jH9xvXt1JyynmO7I_rkBpFulEAuQ"
);
assert_eq!(
result[0].txid,
"1fae017f2c9f14cec0487a04b3f1d1b7336bd38547f755748beb635296de3ee8"
"b698c0919a91a161bc141cd395788296edb85d19415a6d29a13a220a8f2249e0"
);
assert_eq!(result[0].block_height, 2377360);
assert_eq!(result[0].block_height, 2377410);

// This is the root DID used in testing:
assert_eq!(
result[16].did,
result[26].did,
"did:ion:test:EiCClfEdkTv_aM3UnBBhlOV89LlGhpQAbfeZLFdFxVFkEg"
);
assert_eq!(
result[16].txid,
result[26].txid,
"9dc43cca950d923442445340c2e30bc57761a62ef3eaf2417ec5c75784ea9c2c"
);
assert_eq!(result[16].block_height, 2377445);
assert_eq!(result[26].block_height, 2377445);

assert_eq!(
result[37].did,
"did:ion:test:EiBbes2IRKhGauhQc5r4T30i06S6dEWgzCKx-WCKT3x0Lw"
"did:ion:test:EiDz_zvUa2FUIgLUvBia9wUJakhrrW889nDdGlr1-RTAWw"
);
assert_eq!(
result[37].txid,
"502f1a418eff99e50b91aea33e43e4c270af05eb0381d57ca4f48f16d7efe9e1"
"c369dd566a0dd5c2f381c1ab9c8e96b4f6b4fd323f5c1ed68dbb2a1bfb9cb48f"
);
assert_eq!(result[37].block_height, 2377514);
assert_eq!(result[37].block_height, 2377416);
}
}
Loading