use crate::{
attestation::api::get_pck,
helpers::tests::{initialize_test_logger, setup_client},
node_info::api::{BuildDetails, VersionDetails},
};
use entropy_kvdb::clean_tests;
use entropy_shared::types::{HashingAlgorithm, TssPublicKeys};
use entropy_testing_utils::constants::{TSS_ACCOUNTS, X25519_PUBLIC_KEYS};
use serial_test::serial;
#[tokio::test]
#[serial]
async fn version_test() {
clean_tests();
initialize_test_logger().await;
setup_client().await;
let client = reqwest::Client::new();
let response = client.get("http://127.0.0.1:3001/v1/version").send().await.unwrap();
let version_details: VersionDetails =
serde_json::from_str(&response.text().await.unwrap()).unwrap();
assert_eq!(
version_details,
VersionDetails {
cargo_package_version: env!("CARGO_PKG_VERSION").to_string(),
git_tag_commit: env!("VERGEN_GIT_DESCRIBE").to_string(),
build: BuildDetails::NonProduction,
}
);
clean_tests();
}
#[tokio::test]
#[serial]
async fn hashes_test() {
clean_tests();
initialize_test_logger().await;
setup_client().await;
let response = reqwest::get("http://127.0.0.1:3001/v1/hashes").await.unwrap();
let algorithms: Vec<HashingAlgorithm> = response.json().await.unwrap();
assert_eq!(
algorithms,
vec![
HashingAlgorithm::Sha1,
HashingAlgorithm::Sha2,
HashingAlgorithm::Sha3,
HashingAlgorithm::Keccak,
HashingAlgorithm::Blake2_256,
HashingAlgorithm::Identity,
HashingAlgorithm::Custom(0),
]
);
clean_tests();
}
#[tokio::test]
#[serial]
async fn info_test() {
clean_tests();
initialize_test_logger().await;
setup_client().await;
let client = reqwest::Client::new();
let response = client.get("http://127.0.0.1:3001/v1/info").send().await.unwrap();
let public_keys: TssPublicKeys = response.json().await.unwrap();
assert_eq!(
public_keys,
TssPublicKeys {
tss_account: TSS_ACCOUNTS[0].0.into(),
x25519_public_key: X25519_PUBLIC_KEYS[0],
ready: true,
provisioning_certification_key: get_pck(TSS_ACCOUNTS[0].clone()).unwrap(),
}
);
clean_tests();
}