Skip to content

Commit 712168b

Browse files
committed
Enhance test configuration and type annotations in test_conftest.py
Signed-off-by: DavidOsipov <[email protected]>
1 parent 568cb21 commit 712168b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
"${workspaceFolder}/.devcontainer/requirements.txt"
1010
],
1111
"snyk.folderConfigs": [],
12+
"python.testing.pytestArgs": [
13+
"tests"
14+
],
15+
"python.testing.unittestEnabled": true,
16+
"python.testing.pytestEnabled": true,
1217
}

tests/test_conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_prime(bits: int, safe: bool = True) -> mpz:
131131
while not bool(gmpy2.is_prime(p, 25)):
132132
p = mpz(secrets.randbits(min_bits) | (1 << (min_bits - 1)) | 1)
133133

134-
end_time = time.monotonic()
134+
end_time: float = time.monotonic()
135135
test_logger.info("Prime generation complete in %.2fs.", end_time - start_time)
136136
_prime_cache[cache_key] = p
137137
return p
@@ -209,11 +209,11 @@ def eval_poly(self, poly: Sequence[FieldElement], x: FieldElement) -> mpz:
209209
x_val = mpz(x)
210210
y = mpz(0)
211211
for coeff in reversed(poly):
212-
# Ensure coeff is mpz before arithmetic, use f_mod
213-
# Convert result back to mpz to ensure correct type
214-
# This fixes the issue where f_mod could return mpfr in some cases
215-
result: mpz = gmpy2.f_mod(mpz(y * x_val + mpz(coeff)), self.prime)
216-
y = mpz(result) # Explicitly cast back to mpz
212+
# Always ensure we're working with mpz types
213+
y = mpz(y) * mpz(x_val) # Multiply by x
214+
y: mpz | mpfr = mpz(y) + mpz(coeff) # Add coefficient
215+
# Apply modulo operation
216+
y = gmpy2.f_mod(mpz(y), self.prime) # Explicit cast to mpz
217217
return y
218218

219219
def interpolate(self, shares: list[SharePoint]) -> mpz:

0 commit comments

Comments
 (0)