use super::*;
impl<N: Network> FromBytes for ProverSolution<N> {
fn read_le<R: Read>(mut reader: R) -> IoResult<Self> {
let partial_solution: PartialSolution<N> = FromBytes::read_le(&mut reader)?;
let proof = KZGProof::read_le(&mut reader)?;
Ok(Self::new(partial_solution, proof))
}
}
impl<N: Network> ToBytes for ProverSolution<N> {
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.partial_solution.write_le(&mut writer)?;
self.proof.write_le(&mut writer)
}
}
#[cfg(test)]
mod tests {
use super::*;
use console::{account::PrivateKey, network::Testnet3};
type CurrentNetwork = Testnet3;
#[test]
fn test_bytes() -> Result<()> {
let mut rng = TestRng::default();
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let address = Address::try_from(private_key)?;
let partial_solution = PartialSolution::new(address, u64::rand(&mut rng), KZGCommitment(rng.gen()));
let expected = ProverSolution::new(partial_solution, KZGProof { w: rng.gen(), random_v: None });
let expected_bytes = expected.to_bytes_le()?;
assert_eq!(expected, ProverSolution::read_le(&expected_bytes[..])?);
assert!(ProverSolution::<CurrentNetwork>::read_le(&expected_bytes[1..]).is_err());
Ok(())
}
}