ic-query 0.101.0

Internet Computer query library for CloudEngine, NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
use super::*;
use crate::candid_codec::encode_value;
use crate::{
    candid_codec::decode_reply,
    nns::neuron::report::{NnsNeuronError, source::governance_result},
};

// Governance's external variant labels are part of the Candid contract.

#[test]
fn index_reply_accepts_the_native_ok_variant() {
    let bytes = encode_value(&Result::<_, GovernanceError>::Ok(NeuronIndexDataWire {
        neurons: Vec::new(),
    }))
    .unwrap();
    let reply = decode_reply::<GetNeuronIndexResultWire>(&bytes).unwrap();
    let page = governance_result(reply).unwrap();
    assert!(page.neurons.is_empty());
}

#[test]
fn boxed_info_reply_projects_the_native_error_variant() {
    let bytes = encode_value(&Result::<NeuronInfoWire, GovernanceError>::Err(
        GovernanceError {
            error_type: 4,
            error_message: "fixture neuron is absent".to_string(),
        },
    ))
    .unwrap();
    let reply = decode_reply::<GetNeuronInfoResultWire>(&bytes).unwrap();
    assert!(matches!(
        governance_result(reply),
        Err(NnsNeuronError::GovernanceResponse { error_type: 4, message })
            if message == "fixture neuron is absent"
    ));
}