add eq & partial_eq for RecursivePod, Pod traits and VDSet struct (for usage from introduction-pods) (#309)
* add eq & partial_eq for VDSet (for usage from introduction-pods) * add eq & partial_eq impls for Pod & RecursivePod traits
This commit is contained in:
parent
256d76ae34
commit
e1775d8578
10 changed files with 121 additions and 9 deletions
|
|
@ -77,6 +77,15 @@ pub struct VDSet {
|
|||
vds_hashes: Vec<Hash>,
|
||||
}
|
||||
|
||||
impl PartialEq for VDSet {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.root == other.root
|
||||
&& self.tree_depth == other.tree_depth
|
||||
&& self.vds_hashes == other.vds_hashes
|
||||
}
|
||||
}
|
||||
impl Eq for VDSet {}
|
||||
|
||||
impl VDSet {
|
||||
fn new_from_vds_hashes(tree_depth: usize, mut vds_hashes: Vec<Hash>) -> Result<Self> {
|
||||
// before using the hash values, sort them, so that each set of
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use std::{
|
||||
any::Any,
|
||||
collections::HashMap,
|
||||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
|
@ -73,7 +74,7 @@ impl EmptyPodVerifyTarget {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct EmptyPod {
|
||||
params: Params,
|
||||
id: PodId,
|
||||
|
|
@ -192,6 +193,17 @@ impl Pod for EmptyPod {
|
|||
})
|
||||
.expect("serialization to json")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<EmptyPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RecursivePod for EmptyPod {
|
||||
|
|
|
|||
|
|
@ -561,7 +561,7 @@ impl PodProver for Prover {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MainPod {
|
||||
params: Params,
|
||||
id: PodId,
|
||||
|
|
@ -676,6 +676,17 @@ impl Pod for MainPod {
|
|||
})
|
||||
.expect("serialization to json")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<MainPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RecursivePod for MainPod {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ use crate::{
|
|||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Statement(pub Predicate, pub Vec<StatementArg>);
|
||||
|
||||
impl Eq for Statement {}
|
||||
|
||||
impl Statement {
|
||||
pub fn is_none(&self) -> bool {
|
||||
self.0 == Predicate::Native(NativePredicate::None)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::any::Any;
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -12,7 +14,7 @@ use crate::{
|
|||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MockEmptyPod {
|
||||
params: Params,
|
||||
id: PodId,
|
||||
|
|
@ -67,6 +69,17 @@ impl Pod for MockEmptyPod {
|
|||
fn serialize_data(&self) -> serde_json::Value {
|
||||
serde_json::Value::Null
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<MockEmptyPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RecursivePod for MockEmptyPod {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// MainPod
|
||||
//
|
||||
|
||||
use std::{fmt, iter};
|
||||
use std::{any::Any, fmt, iter};
|
||||
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -56,6 +56,21 @@ pub struct MockMainPod {
|
|||
merkle_proofs_containers: Vec<MerkleClaimAndProof>,
|
||||
}
|
||||
|
||||
impl PartialEq for MockMainPod {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.params == other.params
|
||||
&& self.id == other.id
|
||||
&& self.vd_set == other.vd_set
|
||||
&& self.input_signed_pods == other.input_signed_pods
|
||||
&& self.input_recursive_pods == other.input_recursive_pods
|
||||
&& self.statements == other.statements
|
||||
&& self.operations == other.operations
|
||||
&& self.public_statements == other.public_statements
|
||||
&& self.merkle_proofs_containers == other.merkle_proofs_containers
|
||||
}
|
||||
}
|
||||
impl Eq for MockMainPod {}
|
||||
|
||||
impl fmt::Display for MockMainPod {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "MockMainPod ({}):", self.id)?;
|
||||
|
|
@ -365,6 +380,17 @@ impl Pod for MockMainPod {
|
|||
})
|
||||
.expect("serialization to json")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<MockMainPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RecursivePod for MockMainPod {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{any::Any, collections::HashMap};
|
||||
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -45,7 +45,7 @@ impl PodSigner for MockSigner {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MockSignedPod {
|
||||
id: PodId,
|
||||
signature: String,
|
||||
|
|
@ -158,6 +158,17 @@ impl Pod for MockSignedPod {
|
|||
})
|
||||
.expect("serialization to json")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<MockSignedPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use crate::{
|
|||
};
|
||||
|
||||
/// Schnorr signature over ecGFp5.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Signature {
|
||||
pub s: BigUint,
|
||||
pub e: BigUint,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, sync::LazyLock};
|
||||
use std::{any::Any, collections::HashMap, sync::LazyLock};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num_bigint::{BigUint, RandBigInt};
|
||||
|
|
@ -67,7 +67,7 @@ impl PodSigner for Signer {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SignedPod {
|
||||
pub id: PodId,
|
||||
pub signature: Signature,
|
||||
|
|
@ -204,6 +204,17 @@ impl Pod for SignedPod {
|
|||
})
|
||||
.expect("serialization to json")
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
fn equals(&self, other: &dyn Pod) -> bool {
|
||||
if let Some(other) = other.as_any().downcast_ref::<SignedPod>() {
|
||||
self == other
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -805,7 +805,17 @@ pub trait Pod: fmt::Debug + DynClone + Any {
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
fn equals(&self, other: &dyn Pod) -> bool;
|
||||
}
|
||||
impl PartialEq for Box<dyn Pod> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.equals(&**other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Box<dyn Pod> {}
|
||||
|
||||
// impl Clone for Box<dyn Pod>
|
||||
dyn_clone::clone_trait_object!(Pod);
|
||||
|
|
@ -828,6 +838,13 @@ pub trait RecursivePod: Pod {
|
|||
where
|
||||
Self: Sized;
|
||||
}
|
||||
impl PartialEq for Box<dyn RecursivePod> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.equals(&**other)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Box<dyn RecursivePod> {}
|
||||
|
||||
// impl Clone for Box<dyn RecursivePod>
|
||||
dyn_clone::clone_trait_object!(RecursivePod);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue