ic-query 0.99.1

Internet Computer query library for CloudEngine, NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
use ic_platform_types::Principal;
use ic_query::nns::registry::{
    NnsRegistryCertification, NnsRegistryInventoryProvenance, NnsRegistryVersionReport,
};
use ic_query::subnet_catalog::SubnetCatalogRegistryRecordSubject;

#[test]
fn downstream_report_data_and_json_do_not_require_cli_presentation() {
    let report = NnsRegistryVersionReport {
        schema_version: 1,
        provenance: NnsRegistryInventoryProvenance {
            network: "ic".into(),
            registry_canister_id: "rwlgt-iiaaa-aaaaa-aaaaa-cai".into(),
            registry_version: 42,
            fetched_at: "2023-11-14T22:13:20Z".into(),
            source_endpoint: "https://icp-api.io".into(),
            fetched_by: "embedding-tool".into(),
        },
        certification: NnsRegistryCertification {
            certificate_verified: true,
            certificate_time_nanos: 1_700_000_000_000_000_000,
            root_key_digest: "ab".repeat(32),
            certificate_hex: "cd".repeat(8),
            hash_tree_hex: "ef".repeat(4),
        },
    };
    assert_eq!(report.provenance.registry_version, 42);
    let json = serde_json::to_value(&report).unwrap();
    assert_eq!(json["registry_version"], 42);
    assert_eq!(json["source_endpoint"], "https://icp-api.io");
}

#[test]
fn catalog_record_subjects_accept_owned_principals_and_preserve_json() {
    for principal in [
        Principal::management_canister(),
        Principal::anonymous(),
        Principal::from_slice(&[255; Principal::MAX_LENGTH_IN_BYTES]),
    ] {
        let subject = SubnetCatalogRegistryRecordSubject::subnet_record(principal);
        let json = serde_json::to_value(&subject).unwrap();
        assert_eq!(json["subnet"], principal.to_text());
        assert_eq!(
            json["key"],
            format!("subnet_record_{}", principal.to_text())
        );
        assert_eq!(json["canister_range_start"], serde_json::Value::Null);
        let decoded: SubnetCatalogRegistryRecordSubject = serde_json::from_value(json).unwrap();
        assert_eq!(decoded, subject);

        let shard = SubnetCatalogRegistryRecordSubject::canister_ranges(principal);
        let json = serde_json::to_value(&shard).unwrap();
        assert_eq!(json["canister_range_start"], principal.to_text());
        let decoded: SubnetCatalogRegistryRecordSubject = serde_json::from_value(json).unwrap();
        assert_eq!(decoded, shard);
    }
}