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:
arnaucube 2025-06-24 17:41:46 +02:00 committed by GitHub
parent 256d76ae34
commit e1775d8578
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 121 additions and 9 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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)]