snarkvm_circuit_program/id/
to_bits.rsuse super::*;
impl<A: Aleo> ToBits for ProgramID<A> {
type Boolean = Boolean<A>;
fn write_bits_le(&self, vec: &mut Vec<Self::Boolean>) {
(&self).write_bits_le(vec);
}
fn write_bits_be(&self, vec: &mut Vec<Self::Boolean>) {
(&self).write_bits_be(vec);
}
}
impl<A: Aleo> ToBits for &ProgramID<A> {
type Boolean = Boolean<A>;
fn write_bits_le(&self, vec: &mut Vec<Self::Boolean>) {
self.name().write_bits_le(vec);
self.network().write_bits_le(vec);
}
fn write_bits_be(&self, vec: &mut Vec<Self::Boolean>) {
self.name().write_bits_be(vec);
self.network().write_bits_be(vec);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{Circuit, data::identifier::tests::sample_lowercase_console_identifier_as_string};
use anyhow::Result;
const ITERATIONS: usize = 100;
fn check_to_bits_le(mode: Mode) -> Result<()> {
for _ in 0..ITERATIONS {
let expected_name_string = sample_lowercase_console_identifier_as_string::<Circuit>()?;
let expected = console::ProgramID::<<Circuit as Environment>::Network>::from_str(&format!(
"{expected_name_string}.aleo"
))?;
let candidate = ProgramID::<Circuit>::new(mode, expected);
assert_eq!(expected.to_bits_le(), candidate.to_bits_le().eject_value());
}
Ok(())
}
fn check_to_bits_be(mode: Mode) -> Result<()> {
for _ in 0..ITERATIONS {
let expected_name_string = sample_lowercase_console_identifier_as_string::<Circuit>()?;
let expected = console::ProgramID::<<Circuit as Environment>::Network>::from_str(&format!(
"{expected_name_string}.aleo"
))?;
let candidate = ProgramID::<Circuit>::new(mode, expected);
assert_eq!(expected.to_bits_be(), candidate.to_bits_be().eject_value());
}
Ok(())
}
#[test]
fn test_to_bits_le() -> Result<()> {
check_to_bits_le(Mode::Constant)?;
check_to_bits_le(Mode::Public)?;
check_to_bits_le(Mode::Private)?;
Ok(())
}
#[test]
fn test_to_bits_be() -> Result<()> {
check_to_bits_be(Mode::Constant)?;
check_to_bits_be(Mode::Public)?;
check_to_bits_be(Mode::Private)?;
Ok(())
}
}