use super::*;
impl<N: Network> ToField for Identifier<N> {
type Field = Field<N>;
fn to_field(&self) -> Result<Self::Field> {
(&self).to_field()
}
}
impl<N: Network> ToField for &Identifier<N> {
type Field = Field<N>;
fn to_field(&self) -> Result<Self::Field> {
Ok(self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::data::identifier::tests::sample_identifier_as_string;
use snarkvm_console_network::MainnetV0;
type CurrentNetwork = MainnetV0;
const ITERATIONS: usize = 100;
#[test]
fn test_to_field() -> Result<()> {
let mut rng = TestRng::default();
for _ in 0..ITERATIONS {
let expected_string = sample_identifier_as_string::<CurrentNetwork>(&mut rng)?;
let expected_field = Field::<CurrentNetwork>::from_bits_le(&expected_string.to_bits_le())?;
let candidate = Identifier::<CurrentNetwork>::from_str(&expected_string)?;
assert_eq!(expected_field, candidate.to_field()?);
}
Ok(())
}
}