/// The test ensures that the conversion rate proposal passes the invariants
/// check if a) there is currently no record in the registry or
/// b) the proposal contains a timestamp that is larger than the timestamp
/// of the conversion rate record in the registry.
The test ensures that the conversion rate proposal passes the invariants
check if a) there is currently no record in the registry or
b) the proposal contains a timestamp that is larger than the timestamp
of the conversion rate record in the registry.
The test ensures that the conversion rate proposal passes the invariants check if a ) there is currently no record in the registry or b ) the proposal contains a timestamp that is larger than the timestamp of the conversion rate record in the registry .
fn conversion_rate_invariant_valid_timestamp() {
        // Create a valid registry:
        let mut registry = create_valid_registry();
        // Create a conversion rate to be added to the snapshot:
        let proposed_conversion_rate = IcpXdrConversionRateRecord {
            timestamp_seconds: 3141592,
            xdr_permyriad_per_icp: 123451234,
        };
        // Create a snapshot with the proposed conversion rate:
        let snapshot = registry.take_latest_snapshot_with_mutations(&[insert(
            &make_icp_xdr_conversion_rate_record_key().into_bytes(),
            encode_or_panic::<IcpXdrConversionRateRecord>(&proposed_conversion_rate),
        )]);
        // The conversion rate invariants should be satisfied because there is no record
        // in the registry:
        registry.check_conversion_rate_invariants(&snapshot);
        // Manually add an initial rate with a smaller timestamp:
        let initial_conversion_rate = IcpXdrConversionRateRecord {
            timestamp_seconds: 1415926,
            xdr_permyriad_per_icp: 123451234,
        };
        registry.maybe_apply_mutation_internal(vec![insert(
            &make_icp_xdr_conversion_rate_record_key().into_bytes(),
            encode_or_panic::<IcpXdrConversionRateRecord>(&initial_conversion_rate),
        )]);
        // The conversion rate invariants should still be satisfied:
        registry.check_conversion_rate_invariants(&snapshot);
    }
fn conversion_rate_invariant_valid_timestamp ( ) { // Create a valid registry: let mut registry = create_valid_registry ( ) ; // Create a conversion rate to be added to the snapshot: let proposed_conversion_rate = IcpXdrConversionRateRecord { timestamp_seconds : 3141592 , xdr_permyriad_per_icp : 123451234 , } ; // Create a snapshot with the proposed conversion rate: let snapshot = registry . take_latest_snapshot_with_mutations ( & [ insert ( & make_icp_xdr_conversion_rate_record_key ( ) . into_bytes ( ) , encode_or_panic :: < IcpXdrConversionRateRecord > ( & proposed_conversion_rate ) , ) ] ) ; // The conversion rate invariants should be satisfied because there is no record // in the registry: registry . check_conversion_rate_invariants ( & snapshot ) ; // Manually add an initial rate with a smaller timestamp: let initial_conversion_rate = IcpXdrConversionRateRecord { timestamp_seconds : 1415926 , xdr_permyriad_per_icp : 123451234 , } ; registry . maybe_apply_mutation_internal ( vec ! [ insert ( make_icp_xdr_conversion_rate_record_key ( ) into_bytes ( ) encode_or_panic IcpXdrConversionRateRecord ( initial_conversion_rate ) ) ] ) ; // The conversion rate invariants should still be satisfied: registry . check_conversion_rate_invariants ( & snapshot ) ; }
The test ensures that the conversion rate proposal passes the invariants
check if a) there is currently no record in the registry or
b) the proposal contains a timestamp that is larger than the timestamp
of the conversion rate record in the registry.
The test ensures that the conversion rate proposal passes the invariants check if a ) there is currently no record in the registry or b ) the proposal contains a timestamp that is larger than the timestamp of the conversion rate record in the registry .