Drop nim-json-serialization for testing (#156)
This commit is contained in:
parent
c4a2dee42d
commit
491b4d4d21
|
@ -199,14 +199,9 @@ jobs:
|
||||||
rm -rf .git
|
rm -rf .git
|
||||||
- name: Install test dependencies
|
- name: Install test dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
# Workaround #113 and https://github.com/status-im/nim-serialization/issues/33
|
|
||||||
# and nimble flaky pinning / dependency resolution,
|
|
||||||
# json_serialization install would override nim-serialization pinning
|
|
||||||
run: |
|
run: |
|
||||||
nimble refresh
|
nimble refresh
|
||||||
nimble install -y gmp stew json_serialization
|
nimble install -y gmp stew jsony
|
||||||
nimble uninstall -y serialization
|
|
||||||
nimble install serialization@#217d78a
|
|
||||||
- name: Run Constantine tests (with Assembler & with GMP)
|
- name: Run Constantine tests (with Assembler & with GMP)
|
||||||
if: (runner.os == 'Linux' || runner.os == 'macOS') && matrix.target.cpu == 'amd64'
|
if: (runner.os == 'Linux' || runner.os == 'macOS') && matrix.target.cpu == 'amd64'
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
|
@ -127,12 +127,7 @@ before_script:
|
||||||
- export PATH="$PWD/nim-${CHANNEL}/bin${PATH:+:$PATH}"
|
- export PATH="$PWD/nim-${CHANNEL}/bin${PATH:+:$PATH}"
|
||||||
script:
|
script:
|
||||||
- nimble refresh
|
- nimble refresh
|
||||||
- nimble install -y gmp stew json_serialization
|
- nimble install -y gmp stew jsony
|
||||||
# Workaround #113 and https://github.com/status-im/nim-serialization/issues/33
|
|
||||||
# and nimble flaky pinning / dependency resolution,
|
|
||||||
# json_serialization install would override nim-serialization pinning
|
|
||||||
- nimble uninstall -y serialization
|
|
||||||
- nimble install serialization@#217d78a
|
|
||||||
|
|
||||||
# Installing Clang9.0 or later is a pain in Travis
|
# Installing Clang9.0 or later is a pain in Travis
|
||||||
# for inline assembly "flag output constraint"
|
# for inline assembly "flag output constraint"
|
||||||
|
|
|
@ -222,9 +222,7 @@ steps:
|
||||||
- bash: |
|
- bash: |
|
||||||
echo "PATH=${PATH}"
|
echo "PATH=${PATH}"
|
||||||
nimble refresh
|
nimble refresh
|
||||||
nimble install -y gmp stew json_serialization
|
nimble install -y gmp stew jsony
|
||||||
nimble uninstall -y serialization
|
|
||||||
nimble install serialization@#217d78a
|
|
||||||
displayName: 'Installing package and testing dependencies'
|
displayName: 'Installing package and testing dependencies'
|
||||||
|
|
||||||
- bash: |
|
- bash: |
|
||||||
|
|
|
@ -10,7 +10,7 @@ import
|
||||||
# Standard library
|
# Standard library
|
||||||
std/[unittest, times, os, strutils, macros],
|
std/[unittest, times, os, strutils, macros],
|
||||||
# 3rd party
|
# 3rd party
|
||||||
serialization, json_serialization,
|
jsony,
|
||||||
# Internals
|
# Internals
|
||||||
../constantine/config/[common, curves, type_bigint, type_ff],
|
../constantine/config/[common, curves, type_bigint, type_ff],
|
||||||
../constantine/towers,
|
../constantine/towers,
|
||||||
|
@ -24,18 +24,6 @@ import
|
||||||
# Test utilities
|
# Test utilities
|
||||||
./support/ec_reference_scalar_mult
|
./support/ec_reference_scalar_mult
|
||||||
|
|
||||||
# Workaround
|
|
||||||
# --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Generic sandwich - https://github.com/nim-lang/Nim/issues/11225
|
|
||||||
export serialization, json_serialization
|
|
||||||
|
|
||||||
# When run_scalar_mul_test_vs_sage is not instantiated from this exact file
|
|
||||||
# "nim-serialization" somehow tries to serialize SecretWord
|
|
||||||
# json_serialization/reader.nim(522, 12) Error: Failed to convert to JSON an unsupported type: SecretWord
|
|
||||||
#
|
|
||||||
# This obscure error actually requires exporting the `readValue` proc
|
|
||||||
|
|
||||||
# Serialization
|
# Serialization
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -145,23 +133,28 @@ const
|
||||||
TestVectorsDir* =
|
TestVectorsDir* =
|
||||||
currentSourcePath.rsplit(DirSep, 1)[0] / "vectors"
|
currentSourcePath.rsplit(DirSep, 1)[0] / "vectors"
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader, value: var BigInt) =
|
proc parseHook*(src: string, pos: var int, value: var BigInt) =
|
||||||
value.fromHex(reader.readValue(string))
|
var str: string
|
||||||
|
parseHook(src, pos, str)
|
||||||
|
value.fromHex(str)
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader, value: var ECP_ShortW_Aff) =
|
proc parseHook*(src: string, pos: var int, value: var ECP_ShortW_Aff) =
|
||||||
# When ECP_ShortW_Aff[Fp[Foo], NotOnTwist]
|
# Note when nim-serialization was used:
|
||||||
# and ECP_ShortW_Aff[Fp[Foo], OnTwist]
|
# When ECP_ShortW_Aff[Fp[Foo], NotOnTwist]
|
||||||
# are generated in the same file (i.e. twists and base curve are both on Fp)
|
# and ECP_ShortW_Aff[Fp[Foo], OnTwist]
|
||||||
# this creates bad codegen, in the C code, the `value`parameter gets the wrong type
|
# are generated in the same file (i.e. twists and base curve are both on Fp)
|
||||||
# TODO: upstream
|
# this creates bad codegen, in the C code, the `value`parameter gets the wrong type
|
||||||
|
# TODO: upstream
|
||||||
when ECP_ShortW_Aff.F is Fp:
|
when ECP_ShortW_Aff.F is Fp:
|
||||||
let P = reader.readValue(EC_G1_hex)
|
var P: EC_G1_hex
|
||||||
|
parseHook(src, pos, P)
|
||||||
let ok = value.fromHex(P.x, P.y)
|
let ok = value.fromHex(P.x, P.y)
|
||||||
doAssert ok, "\nDeserialization error on G1 for\n" &
|
doAssert ok, "\nDeserialization error on G1 for\n" &
|
||||||
" P.x: " & P.x & "\n" &
|
" P.x: " & P.x & "\n" &
|
||||||
" P.y: " & P.x & "\n"
|
" P.y: " & P.x & "\n"
|
||||||
elif ECP_ShortW_Aff.F is Fp2:
|
elif ECP_ShortW_Aff.F is Fp2:
|
||||||
let P = reader.readValue(EC_G2_hex)
|
var P: EC_G2_hex
|
||||||
|
parseHook(src, pos, P)
|
||||||
let ok = value.fromHex(P.x.c0, P.x.c1, P.y.c0, P.y.c1)
|
let ok = value.fromHex(P.x.c0, P.x.c1, P.y.c0, P.y.c1)
|
||||||
doAssert ok, "\nDeserialization error on G2 for\n" &
|
doAssert ok, "\nDeserialization error on G2 for\n" &
|
||||||
" P.x0: " & P.x.c0 & "\n" &
|
" P.x0: " & P.x.c0 & "\n" &
|
||||||
|
@ -175,7 +168,8 @@ proc loadVectors(TestType: typedesc): TestType =
|
||||||
const group = when TestType.EC.Tw == NotOnTwist: "G1"
|
const group = when TestType.EC.Tw == NotOnTwist: "G1"
|
||||||
else: "G2"
|
else: "G2"
|
||||||
const filename = "tv_" & $TestType.EC.F.C & "_scalar_mul_" & group & ".json"
|
const filename = "tv_" & $TestType.EC.F.C & "_scalar_mul_" & group & ".json"
|
||||||
result = Json.loadFile(TestVectorsDir/filename, TestType)
|
let content = readFile(TestVectorsDir/filename)
|
||||||
|
result = content.fromJson(TestType)
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue