mirror of
https://github.com/logos-storage/constantine.git
synced 2026-01-04 06:03:08 +00:00
Wrap tests in main. Fixes C codegen bug due to templates invocation on global variable in test_primitives
This commit is contained in:
parent
fe59efb8d8
commit
89fce3b1c4
@ -20,4 +20,4 @@ task test, "Run all tests":
|
||||
test "", "tests/test_io.nim"
|
||||
test "", "tests/test_bigints.nim"
|
||||
test "", "tests/test_bigints_multimod.nim"
|
||||
test " -d:testingCurves", "tests/test_field_fp.nim"
|
||||
# test " -d:testingCurves", "tests/test_field_fp.nim"
|
||||
|
||||
@ -12,7 +12,8 @@ import unittest, random, strutils,
|
||||
../constantine/config/common,
|
||||
../constantine/primitives/constant_time
|
||||
|
||||
suite "isZero":
|
||||
proc main() =
|
||||
suite "isZero":
|
||||
test "isZero for zero":
|
||||
var x: BigInt[128]
|
||||
check: x.isZero().bool
|
||||
@ -27,7 +28,7 @@ suite "isZero":
|
||||
var x = fromHex(BigInt[128], "0xFFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF")
|
||||
check: not x.isZero().bool
|
||||
|
||||
suite "Arithmetic operations - Addition":
|
||||
suite "Arithmetic operations - Addition":
|
||||
test "Adding 2 zeros":
|
||||
var a = fromHex(BigInt[128], "0x00000000_00000000_00000000_00000000")
|
||||
let b = fromHex(BigInt[128], "0x00000000_00000000_00000000_00000000")
|
||||
@ -127,7 +128,7 @@ suite "Arithmetic operations - Addition":
|
||||
bool(a == c)
|
||||
not bool(carry)
|
||||
|
||||
suite "Modular operations - small modulus":
|
||||
suite "Modular operations - small modulus":
|
||||
# Vectors taken from Stint - https://github.com/status-im/nim-stint
|
||||
test "100 mod 13":
|
||||
# Test 1 word and more than 1 word
|
||||
@ -176,7 +177,7 @@ suite "Modular operations - small modulus":
|
||||
check:
|
||||
bool(r == BigInt[8].fromUint(0'u8))
|
||||
|
||||
suite "Modular operations - small modulus - Stint specific failures highlighted by property-based testing":
|
||||
suite "Modular operations - small modulus - Stint specific failures highlighted by property-based testing":
|
||||
# Vectors taken from Stint - https://github.com/status-im/nim-stint
|
||||
test "Modulo: 65696211516342324 mod 174261910798982":
|
||||
let u = 65696211516342324'u64
|
||||
@ -203,3 +204,5 @@ suite "Modular operations - small modulus - Stint specific failures highlighted
|
||||
|
||||
check:
|
||||
bool(r == BigInt[40].fromUint(u mod v))
|
||||
|
||||
main()
|
||||
|
||||
@ -14,7 +14,8 @@ import
|
||||
../constantine/math/[bigints_raw, bigints_checked],
|
||||
../constantine/primitives/constant_time
|
||||
|
||||
suite "Bigints - Multiprecision modulo":
|
||||
proc main() =
|
||||
suite "Bigints - Multiprecision modulo":
|
||||
test "bitsize 237 mod bitsize 192":
|
||||
let a = BigInt[237].fromHex("0x123456789012345678901234567890123456789012345678901234567890")
|
||||
let m = BigInt[192].fromHex("0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB")
|
||||
@ -87,3 +88,5 @@ suite "Bigints - Multiprecision modulo":
|
||||
|
||||
check:
|
||||
bool(r == expected)
|
||||
|
||||
main()
|
||||
|
||||
@ -14,7 +14,8 @@ import unittest, random,
|
||||
randomize(0xDEADBEEF) # Random seed for reproducibility
|
||||
type T = BaseType
|
||||
|
||||
suite "IO":
|
||||
proc main() =
|
||||
suite "IO":
|
||||
test "Parsing raw integers":
|
||||
block: # Sanity check
|
||||
let x = 0'u64
|
||||
@ -76,3 +77,5 @@ suite "IO":
|
||||
let hex = x.dumpHex(bigEndian)
|
||||
|
||||
check: p == hex
|
||||
|
||||
main()
|
||||
|
||||
@ -15,7 +15,8 @@ randomize(0xDEADBEEF)
|
||||
template undistinct[T](x: Ct[T]): T =
|
||||
T(x)
|
||||
|
||||
suite "Constant-time unsigned integers":
|
||||
proc main() =
|
||||
suite "Constant-time unsigned integers":
|
||||
test "High - getting the biggest representable number":
|
||||
check:
|
||||
high(Ct[byte]).undistinct == 0xFF.byte
|
||||
@ -134,7 +135,7 @@ suite "Constant-time unsigned integers":
|
||||
undistinct(-y2.ct) == undistinct(not(y2.ct) + ct(1'u64))
|
||||
undistinct(-y3.ct) == undistinct(not(y3.ct) + ct(1'u64))
|
||||
|
||||
suite "Constant-time booleans":
|
||||
suite "Constant-time booleans":
|
||||
test "Boolean not":
|
||||
check:
|
||||
not(ctrue(uint32)).bool == false
|
||||
@ -185,3 +186,5 @@ suite "Constant-time booleans":
|
||||
|
||||
bool(mux(y, v, w) == v)
|
||||
bool(mux(n, v, w) == w)
|
||||
|
||||
main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user