Skip to content

Commit 7f0f9f5

Browse files
committed
test: fix conversion of sum of GroupVars
1 parent 7d94f15 commit 7f0f9f5

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/linear_relation/convert.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,10 @@ impl<G: Group> From<ScalarTerm<G>> for Sum<Weighted<ScalarTerm<G>, G::Scalar>> {
148148
}
149149
}
150150

151-
// Convert a Sum with a single Weighted<GroupVar, Scalar> to Weighted<Term, Scalar>
152-
impl<G: Group> From<Sum<Weighted<GroupVar<G>, G::Scalar>>> for Weighted<Term<G>, G::Scalar> {
151+
impl<G: Group> From<Sum<Weighted<GroupVar<G>, G::Scalar>>> for Sum<Weighted<Term<G>, G::Scalar>> {
153152
fn from(sum: Sum<Weighted<GroupVar<G>, G::Scalar>>) -> Self {
154-
assert_eq!(
155-
sum.0.len(),
156-
1,
157-
"Can only convert Sum with exactly one element to Weighted<Term>"
158-
);
159-
sum.0.into_iter().next().unwrap().into()
153+
let sum = sum.0.into_iter().map(|x| x.into()).collect::<Vec<_>>();
154+
Self(sum)
160155
}
161-
}
156+
157+
}

src/tests/test_validation_criteria.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,16 @@ mod instance_validation {
135135
#[test]
136136
fn without_witness() {
137137
let B = G::generator();
138-
let x = Scalar::from(42);
138+
let A = G::generator() * Scalar::from(42);
139+
let pub_scalar = Scalar::from(42);
139140

140141
let mut linear_relation = LinearRelation::<G>::new();
141142
let B_var = linear_relation.allocate_element();
142-
let _X_var = linear_relation.allocate_eq(B_var * x + B_var * Scalar::from(3));
143+
let A_var = linear_relation.allocate_element();
144+
let _X_var = linear_relation.allocate_eq(B_var * pub_scalar + A_var * Scalar::from(3));
143145

144146
linear_relation.set_element(B_var, B);
147+
linear_relation.set_element(A_var, A);
145148
let result = CanonicalLinearRelation::try_from(&linear_relation);
146149
assert!(result.is_err());
147150
}

0 commit comments

Comments
 (0)