snarkvm_console_program/data/dynamic/record/
equal.rs1use super::*;
17
18impl<N: Network> Eq for DynamicRecord<N> {}
19
20impl<N: Network> PartialEq for DynamicRecord<N> {
21 fn eq(&self, other: &Self) -> bool {
23 *self.is_equal(other)
24 }
25}
26
27impl<N: Network> Equal<Self> for DynamicRecord<N> {
28 type Output = Boolean<N>;
29
30 fn is_equal(&self, other: &Self) -> Self::Output {
32 self.owner.is_equal(&other.owner)
34 & self.root.is_equal(&other.root)
35 & self.nonce.is_equal(&other.nonce)
36 & self.version.is_equal(&other.version)
37 }
38
39 fn is_not_equal(&self, other: &Self) -> Self::Output {
41 !self.is_equal(other)
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48 use snarkvm_console_network::MainnetV0;
49
50 use std::str::FromStr;
51
52 type CurrentNetwork = MainnetV0;
53
54 fn sample_record() -> DynamicRecord<CurrentNetwork> {
55 DynamicRecord::from_record(
56 &Record::<CurrentNetwork, Plaintext<CurrentNetwork>>::from_str(
57 r"{
58 owner: aleo14tlamssdmg3d0p5zmljma573jghe2q9n6wz29qf36re2glcedcpqfg4add.private,
59 a: true.private,
60 b: 123456789field.public,
61 c: 0group.private,
62 d: {
63 e: true.private,
64 f: 123456789field.private,
65 g: 0group.private
66 },
67 _nonce: 0group.public,
68 _version: 0u8.public
69}",
70 )
71 .unwrap(),
72 )
73 .unwrap()
74 }
75
76 fn sample_mismatched_record() -> DynamicRecord<CurrentNetwork> {
77 DynamicRecord::from_record(
78 &Record::<CurrentNetwork, Plaintext<CurrentNetwork>>::from_str(
79 r"{
80 owner: aleo14tlamssdmg3d0p5zmljma573jghe2q9n6wz29qf36re2glcedcpqfg4add.private,
81 a: true.public,
82 b: 123456789field.public,
83 c: 0group.private,
84 d: {
85 e: true.private,
86 f: 123456789field.private,
87 g: 0group.private
88 },
89 _nonce: 0group.public,
90 _version: 0u8.public
91}",
92 )
93 .unwrap(),
94 )
95 .unwrap()
96 }
97
98 fn check_is_equal() {
99 let record = sample_record();
101 let mismatched_record = sample_mismatched_record();
102
103 let candidate = record.is_equal(&record);
104 assert!(*candidate);
105
106 let candidate = record.is_equal(&mismatched_record);
107 assert!(!*candidate);
108 }
109
110 fn check_is_not_equal() {
111 let record = sample_record();
113 let mismatched_record = sample_mismatched_record();
114
115 let candidate = record.is_not_equal(&mismatched_record);
116 assert!(*candidate);
117
118 let candidate = record.is_not_equal(&record);
119 assert!(!*candidate);
120 }
121
122 #[test]
123 fn test_is_equal() {
124 check_is_equal()
125 }
126
127 #[test]
128 fn test_is_not_equal() {
129 check_is_not_equal()
130 }
131}