Skip to content

Commit

Permalink
add {.push raises: [].} to more files (#5943)
Browse files Browse the repository at this point in the history
Extend `{.push raises: [].}` to all files with spec references that are
periodically updated.

- #5942
  • Loading branch information
etan-status authored Feb 22, 2024
1 parent 7642b0c commit 702f4c6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ jobs:
run: |
problematic_files=()
while read -r file; do
if ! grep -qE '^{\.push raises: \[\]\.}' "$file"; then
if ! grep -qE '^{\.push raises: \[\]\.}$' "$file"; then
problematic_files+=("$file")
fi
done < <(git diff --name-only --diff-filter=AM --ignore-submodules HEAD^ HEAD | grep -E '\.nim$' || true)
if (( ${#problematic_files[@]} )); then
echo "The following files do not have '{.push raises: []}':"
echo "The following files do not have '{.push raises: [].}':"
for file in "${problematic_files[@]}"; do
echo "- $file"
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.used.}
{.push raises: [].}
{.used.}

import
# Standard library
Expand Down
45 changes: 39 additions & 6 deletions tests/consensus_spec/fixtures_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [].}

import
# Standard library
std/[strutils, typetraits],
Expand Down Expand Up @@ -88,25 +90,37 @@ const
SszTestsDir* = FixturesDir / "tests-v" & SPEC_VERSION
MaxObjectSize* = 3_000_000

proc relativeTestPathComponent*(path: string, suitePath = SszTestsDir): string =
try:
path.relativePath(suitePath)
except Exception as exc:
raiseAssert "relativePath failed unexpectedly: " & $exc.msg

proc parseTest*(path: string, Format: typedesc[Json], T: typedesc): T =
try:
# debugEcho " [Debug] Loading file: \"", path, '\"'
result = Format.decode(readFileBytes(path), T)
except SerializationError as err:
writeStackTrace()
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write err.formatMsg(path), "\n"
try:
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write err.formatMsg(path), "\n"
except IOError:
discard
quit 1

proc sszDecodeEntireInput*(input: openArray[byte], Decoded: type): Decoded =
proc sszDecodeEntireInput*(
input: openArray[byte],
Decoded: type
): Decoded {.raises: [IOError, SerializationError, UnconsumedInput].} =
let stream = unsafeMemoryInput(input)
var reader = init(SszReader, stream)
reader.readValue(result)

if stream.readable:
raise newException(UnconsumedInput, "Remaining bytes in the input")

iterator walkTests*(dir: static string): string =
iterator walkTests*(dir: static string): string {.raises: [OSError].} =
for kind, path in walkDir(
dir/"pyspec_tests", relative = true, checkDir = true):
yield path
Expand All @@ -115,10 +129,29 @@ proc parseTest*(path: string, Format: typedesc[SSZ], T: typedesc): T =
try:
# debugEcho " [Debug] Loading file: \"", path, '\"'
sszDecodeEntireInput(snappy.decode(readFileBytes(path), MaxObjectSize), T)
except IOError as err:
writeStackTrace()
try:
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write "IOError: " & err.msg, "\n"
except IOError:
discard
quit 1
except SerializationError as err:
writeStackTrace()
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write err.formatMsg(path), "\n"
try:
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write err.formatMsg(path), "\n"
except IOError:
discard
quit 1
except UnconsumedInput as err:
writeStackTrace()
try:
stderr.write $Format & " load issue for file \"", path, "\"\n"
stderr.write "UnconsumedInput: " & err.msg, "\n"
except IOError:
discard
quit 1

proc loadForkedState*(
Expand Down
7 changes: 1 addition & 6 deletions tests/consensus_spec/test_fixture_fork_choice.nim
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,7 @@ proc runTest(suiteName: static[string], path: string, fork: ConsensusFork) =
"basic_is_head_root",
]

let relativePathComponent =
try:
path.relativePath(SszTestsDir)
except Exception as exc:
raiseAssert "relativePath failed unexpectedly: " & $exc.msg
test suiteName & " - " & relativePathComponent:
test suiteName & " - " & path.relativeTestPathComponent():
when defined(windows):
# Some test files have very long paths
skip()
Expand Down
19 changes: 13 additions & 6 deletions tests/consensus_spec/test_fixture_kzg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [].}
{.used.}

import
Expand Down Expand Up @@ -35,7 +36,8 @@ block:
"/../../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk

proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) =
test "KZG - Blob to KZG commitment - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Blob to KZG commitment - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand All @@ -56,7 +58,8 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) =
commitment.get == fromHex[48](output.getStr).get

proc runVerifyKzgProofTest(suiteName, suitePath, path: string) =
test "KZG - Verify KZG proof - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Verify KZG proof - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand All @@ -80,7 +83,8 @@ proc runVerifyKzgProofTest(suiteName, suitePath, path: string) =
v.get == output.getBool

proc runVerifyBlobKzgProofTest(suiteName, suitePath, path: string) =
test "KZG - Verify blob KZG proof - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Verify blob KZG proof - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand All @@ -104,7 +108,8 @@ proc runVerifyBlobKzgProofTest(suiteName, suitePath, path: string) =
v.get == output.getBool

proc runVerifyBlobKzgProofBatchTest(suiteName, suitePath, path: string) =
test "KZG - Verify blob KZG proof batch - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Verify blob KZG proof batch - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand All @@ -130,7 +135,8 @@ proc runVerifyBlobKzgProofBatchTest(suiteName, suitePath, path: string) =
v.get == output.getBool

proc runComputeKzgProofTest(suiteName, suitePath, path: string) =
test "KZG - Compute KZG proof - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Compute KZG proof - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand All @@ -156,7 +162,8 @@ proc runComputeKzgProofTest(suiteName, suitePath, path: string) =
p.get.y == y.get

proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) =
test "KZG - Compute blob KZG proof - " & path.relativePath(suitePath):
let relativePathComponent = path.relativeTestPathComponent(suitePath)
test "KZG - Compute blob KZG proof - " & relativePathComponent:
let
data = yaml.loadToJson(os_ops.readFile(path/"data.yaml"))[0]
output = data["output"]
Expand Down

0 comments on commit 702f4c6

Please sign in to comment.