use crate::Error;
use crate::TangleTestHarness;
use blueprint_client_tangle::EventsClient;
use blueprint_core_testing_utils::setup_log;
use tangle_subxt::subxt::tx::Signer;
#[tokio::test]
async fn test_client_initialization() -> Result<(), Error> {
setup_log();
let temp_dir = tempfile::TempDir::new()?;
let harness = Box::pin(TangleTestHarness::<()>::setup(temp_dir)).await?;
assert!(
harness
.client()
.subxt_client()
.blocks()
.at_latest()
.await
.is_ok(),
"Client should be connected"
);
Ok(())
}
#[tokio::test]
async fn test_operator_metadata() -> Result<(), Error> {
setup_log();
let temp_dir = tempfile::TempDir::new()?;
let harness = Box::pin(TangleTestHarness::<()>::setup(temp_dir)).await?;
let metadata = harness
.client()
.operator_metadata(harness.sr25519_signer.account_id().clone())
.await
.unwrap();
assert!(
metadata.is_none(),
"New account should not have operator metadata"
);
Ok(())
}
#[tokio::test]
async fn test_services_client() -> Result<(), Error> {
setup_log();
let temp_dir = tempfile::TempDir::new()?;
let harness = Box::pin(TangleTestHarness::<()>::setup(temp_dir)).await?;
let services = harness.client().services_client();
let block_hash = harness
.client()
.now()
.await
.expect("Should get current block hash");
let blueprint = services
.get_blueprint_by_id(block_hash, 999_999)
.await
.unwrap();
assert!(
blueprint.is_none(),
"Non-existent blueprint should return None"
);
let blueprints = services
.query_operator_blueprints(block_hash, harness.sr25519_signer.account_id().clone())
.await
.unwrap_or_default();
assert!(
blueprints.is_empty(),
"New operator should have no blueprints"
);
Ok(())
}
#[tokio::test]
async fn test_events_client() -> Result<(), Error> {
setup_log();
let temp_dir = tempfile::TempDir::new()?;
let harness = Box::pin(TangleTestHarness::<()>::setup(temp_dir)).await?;
let latest = harness.client().latest_event().await;
assert!(latest.is_some(), "Should have access to latest event");
let event = harness.client().next_event().await;
assert!(event.is_some(), "Should be able to get next event");
if let Some(event) = event {
assert!(event.number > 0, "Block number should be positive");
assert_ne!(event.hash, [0u8; 32], "Block hash should not be zero");
}
Ok(())
}
#[tokio::test]
async fn test_service_operators() -> Result<(), Error> {
setup_log();
let temp_dir = tempfile::TempDir::new()?;
let harness = Box::pin(TangleTestHarness::<()>::setup(temp_dir)).await?;
let services = harness.client().services_client();
let block_hash = harness
.client()
.now()
.await
.expect("Should get current block hash");
let operators = services
.current_service_operators(block_hash, 999_999)
.await
.unwrap();
assert!(
operators.is_empty(),
"Non-existent service should have no operators"
);
Ok(())
}