From 491b4d4d21e41e2df8a3e987d79cee1574a04ea0 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Tue, 9 Feb 2021 22:10:16 +0100 Subject: [PATCH] Drop nim-json-serialization for testing (#156) --- .github/workflows/ci.yml | 7 +----- .travis.yml | 7 +----- azure-pipelines.yml | 4 +--- tests/t_ec_sage_template.nim | 42 ++++++++++++++++-------------------- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f27b50..d8323d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,14 +199,9 @@ jobs: rm -rf .git - name: Install test dependencies 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: | nimble refresh - nimble install -y gmp stew json_serialization - nimble uninstall -y serialization - nimble install serialization@#217d78a + nimble install -y gmp stew jsony - name: Run Constantine tests (with Assembler & with GMP) if: (runner.os == 'Linux' || runner.os == 'macOS') && matrix.target.cpu == 'amd64' shell: bash diff --git a/.travis.yml b/.travis.yml index ffd6ea7..e29d4aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -127,12 +127,7 @@ before_script: - export PATH="$PWD/nim-${CHANNEL}/bin${PATH:+:$PATH}" script: - nimble refresh - - nimble install -y gmp stew json_serialization - # 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 + - nimble install -y gmp stew jsony # Installing Clang9.0 or later is a pain in Travis # for inline assembly "flag output constraint" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9d14ddb..535e3fd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -222,9 +222,7 @@ steps: - bash: | echo "PATH=${PATH}" nimble refresh - nimble install -y gmp stew json_serialization - nimble uninstall -y serialization - nimble install serialization@#217d78a + nimble install -y gmp stew jsony displayName: 'Installing package and testing dependencies' - bash: | diff --git a/tests/t_ec_sage_template.nim b/tests/t_ec_sage_template.nim index 822474d..0f43bf8 100644 --- a/tests/t_ec_sage_template.nim +++ b/tests/t_ec_sage_template.nim @@ -10,7 +10,7 @@ import # Standard library std/[unittest, times, os, strutils, macros], # 3rd party - serialization, json_serialization, + jsony, # Internals ../constantine/config/[common, curves, type_bigint, type_ff], ../constantine/towers, @@ -24,18 +24,6 @@ import # Test utilities ./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 # -------------------------------------------------------------------------- @@ -145,23 +133,28 @@ const TestVectorsDir* = currentSourcePath.rsplit(DirSep, 1)[0] / "vectors" -proc readValue*(reader: var JsonReader, value: var BigInt) = - value.fromHex(reader.readValue(string)) +proc parseHook*(src: string, pos: var int, value: var BigInt) = + var str: string + parseHook(src, pos, str) + value.fromHex(str) -proc readValue*(reader: var JsonReader, value: var ECP_ShortW_Aff) = - # When ECP_ShortW_Aff[Fp[Foo], NotOnTwist] - # and ECP_ShortW_Aff[Fp[Foo], OnTwist] - # are generated in the same file (i.e. twists and base curve are both on Fp) - # this creates bad codegen, in the C code, the `value`parameter gets the wrong type - # TODO: upstream +proc parseHook*(src: string, pos: var int, value: var ECP_ShortW_Aff) = + # Note when nim-serialization was used: + # When ECP_ShortW_Aff[Fp[Foo], NotOnTwist] + # and ECP_ShortW_Aff[Fp[Foo], OnTwist] + # are generated in the same file (i.e. twists and base curve are both on Fp) + # this creates bad codegen, in the C code, the `value`parameter gets the wrong type + # TODO: upstream 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) doAssert ok, "\nDeserialization error on G1 for\n" & " P.x: " & P.x & "\n" & " P.y: " & P.x & "\n" 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) doAssert ok, "\nDeserialization error on G2 for\n" & " P.x0: " & P.x.c0 & "\n" & @@ -175,7 +168,8 @@ proc loadVectors(TestType: typedesc): TestType = const group = when TestType.EC.Tw == NotOnTwist: "G1" else: "G2" 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 # ------------------------------------------------------------------------