explicitly mention `{.raises.}` in `tests` folder (#5990)

Add `{.raises.}` annotations to `tests` files where needed to enable
`{.push raises: [].}`. Avoids interfering with periodic changes such as
spec version bumps, and avoids special casing folders when editing.
The effort to maintain `{.raises.}` is trivial after the initial round.
This commit is contained in:
Etan Kissling 2024-02-29 11:28:32 +01:00 committed by GitHub
parent 794ec9ed19
commit f4ff438aab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 117 additions and 32 deletions

View File

@ -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
@ -40,7 +41,11 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type altair.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type altair.SignedBeaconBlock,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -58,7 +63,11 @@ proc checkSSZ(T: type altair.SignedBeaconBlock, dir: string, expectedHash: SSZHa
# TODO check the value (requires YAML loader)
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -71,7 +80,10 @@ proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# TODO check the value (requires YAML loader)
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc loadExpectedHashTreeRoot(
dir: string
): SSZHashTreeRoot {.raises: [
Exception, IOError, OSError, YamlConstructionError, YamlParserError].} =
let s = openFileStream(dir/"roots.yaml")
yaml.load(s, result)
s.close()

View File

@ -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
@ -40,7 +41,11 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type bellatrix.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type bellatrix.SignedBeaconBlock,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -58,7 +63,11 @@ proc checkSSZ(T: type bellatrix.SignedBeaconBlock, dir: string, expectedHash: SS
# TODO check the value (requires YAML loader)
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -71,7 +80,10 @@ proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# TODO check the value (requires YAML loader)
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc loadExpectedHashTreeRoot(
dir: string
): SSZHashTreeRoot {.raises: [
Exception, IOError, OSError, YamlConstructionError, YamlParserError].} =
let s = openFileStream(dir/"roots.yaml")
yaml.load(s, result)
s.close()

View File

@ -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
@ -42,7 +43,11 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type capella.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type capella.SignedBeaconBlock,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -60,7 +65,11 @@ proc checkSSZ(T: type capella.SignedBeaconBlock, dir: string, expectedHash: SSZH
# TODO check the value (requires YAML loader)
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -73,7 +82,10 @@ proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# TODO check the value (requires YAML loader)
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc loadExpectedHashTreeRoot(
dir: string
): SSZHashTreeRoot {.raises: [
Exception, IOError, OSError, YamlConstructionError, YamlParserError].} =
let s = openFileStream(dir/"roots.yaml")
yaml.load(s, result)
s.close()

View File

@ -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
@ -45,7 +46,11 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type deneb.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type deneb.SignedBeaconBlock,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -63,7 +68,11 @@ proc checkSSZ(T: type deneb.SignedBeaconBlock, dir: string, expectedHash: SSZHas
# TODO check the value (requires YAML loader)
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -76,7 +85,10 @@ proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# TODO check the value (requires YAML loader)
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc loadExpectedHashTreeRoot(
dir: string
): SSZHashTreeRoot {.raises: [
Exception, IOError, OSError, YamlConstructionError, YamlParserError].} =
let s = openFileStream(dir/"roots.yaml")
yaml.load(s, result)
s.close()

View File

@ -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
@ -40,7 +41,11 @@ type
# Note this only tracks HashTreeRoot
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
proc checkSSZ(T: type phase0.SignedBeaconBlock, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type phase0.SignedBeaconBlock,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -58,7 +63,11 @@ proc checkSSZ(T: type phase0.SignedBeaconBlock, dir: string, expectedHash: SSZHa
# TODO check the value (requires YAML loader)
proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
proc checkSSZ(
T: type,
dir: string,
expectedHash: SSZHashTreeRoot
) {.raises: [IOError, SerializationError, UnconsumedInput].} =
# Deserialize into a ref object to not fill Nim stack
let encoded = snappy.decode(
readFileBytes(dir/"serialized.ssz_snappy"), MaxObjectSize)
@ -71,7 +80,10 @@ proc checkSSZ(T: type, dir: string, expectedHash: SSZHashTreeRoot) =
# TODO check the value (requires YAML loader)
proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc loadExpectedHashTreeRoot(
dir: string
): SSZHashTreeRoot {.raises: [
Exception, IOError, OSError, YamlConstructionError, YamlParserError].} =
let s = openFileStream(dir/"roots.yaml")
yaml.load(s, result)
s.close()

View File

@ -96,10 +96,11 @@ proc initialLoad(
(dag, fkChoice)
proc loadOps(
path: string, fork: ConsensusFork
path: string,
fork: ConsensusFork
): seq[Operation] {.raises: [
IOError, KeyError, UnconsumedInput, ValueError,
YamlParserError, YamlConstructionError].} =
YamlConstructionError, YamlParserError].} =
let stepsYAML = os_ops.readFile(path/"steps.yaml")
let steps = yaml.loadToJson(stepsYAML)
@ -290,10 +291,11 @@ proc stepChecks(
raiseAssert "Unsupported check '" & $check & "'"
proc doRunTest(
path: string, fork: ConsensusFork
path: string,
fork: ConsensusFork
) {.raises: [
IOError, KeyError, UnconsumedInput, ValueError,
YamlParserError, YamlConstructionError].} =
YamlConstructionError, YamlParserError].} =
let db = BeaconChainDB.new("", inMemory = true)
defer:
db.close()

View File

@ -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
@ -21,7 +22,8 @@ import
./fixtures_utils, ./os_ops
proc runTest[T](suiteName, path: string, objType: typedesc[T]) =
test "Light client - Single merkle proof - " & path.relativePath(SszTestsDir):
let relativePathComponent = path.relativeTestPathComponent()
test "Light client - Single merkle proof - " & relativePathComponent:
type
TestProof = object
leaf: string

View File

@ -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
@ -52,13 +53,17 @@ type
current_slot: Slot
checks: TestChecks
proc loadSteps(path: string, fork_digests: ForkDigests): seq[TestStep] =
proc loadSteps(
path: string,
fork_digests: ForkDigests
): seq[TestStep] {.raises: [
KeyError, ValueError, YamlConstructionError, YamlParserError].} =
let stepsYAML = os_ops.readFile(path/"steps.yaml")
let steps = yaml.loadToJson(stepsYAML)
result = @[]
for step in steps[0]:
func getChecks(c: JsonNode): TestChecks =
func getChecks(c: JsonNode): TestChecks {.raises: [KeyError].} =
TestChecks(
finalized_slot:
c["finalized_header"]["slot"].getInt().Slot,
@ -122,9 +127,11 @@ proc loadSteps(path: string, fork_digests: ForkDigests): seq[TestStep] =
doAssert false, "Unknown test step: " & $step
proc runTest(suiteName, path: string) =
test "Light client - Sync - " & path.relativePath(SszTestsDir):
let relativePathComponent = path.relativeTestPathComponent()
test "Light client - Sync - " & relativePathComponent:
# Reduce stack size by making this a `proc`
proc loadTestMeta(): (RuntimeConfig, TestMeta) =
proc loadTestMeta(): (RuntimeConfig, TestMeta) {.raises: [
Exception, IOError, PresetFileError, PresetIncompatibleError].} =
let (cfg, _) = readRuntimeConfig(path/"config.yaml")
when false:

View File

@ -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
@ -25,7 +26,8 @@ type
updates_count: uint64
proc runTest(suiteName, path: string, lcDataFork: static LightClientDataFork) =
test "Light client - Update ranking - " & path.relativePath(SszTestsDir):
let relativePathComponent = path.relativeTestPathComponent()
test "Light client - Update ranking - " & relativePathComponent:
let meta = block:
var s = openFileStream(path/"meta.yaml")
defer: close(s)

View File

@ -1,10 +1,11 @@
# beacon_chain
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * 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
@ -21,7 +22,8 @@ import
./fixtures_utils, ./os_ops
proc runTest[T](suiteName, path: string, objType: typedesc[T]) =
test "Merkle proof - Single merkle proof - " & path.relativePath(SszTestsDir):
let relativePathComponent = path.relativeTestPathComponent()
test "Merkle proof - Single merkle proof - " & relativePathComponent:
type
TestProof = object
leaf: string

View File

@ -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 ../../beacon_chain/spec/forks
@ -15,7 +16,10 @@ from ../testutil import check, preset, suite, test
from ../../beacon_chain/spec/state_transition import process_slots
from ../helpers/debug_state import reportDiff
proc runTest(T: type, testDir, forkName: static[string], suiteName, identifier: string) =
proc runTest(
T: type,
testDir, forkName: static[string],
suiteName, identifier: string) {.raises: [IOError, ValueError].} =
let
testDir = testDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64

View File

@ -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
@ -25,7 +26,8 @@ type
fork_block {.defaultVal: -1.}: int
bls_setting {.defaultVal: 1.}: int
proc getTransitionInfo(testPath: string): TransitionInfo =
proc getTransitionInfo(
testPath: string): TransitionInfo {.raises: [Exception, IOError].} =
var transitionInfo: TransitionInfo
let s = openFileStream(testPath/"meta.yaml")
defer: close(s)

View File

@ -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
@ -18,12 +19,15 @@ type
dataDir* {.name: "data-dir".}: string
el* {.name: "el".}: seq[EngineApiUrlConfigValue]
proc loadExampleConfig(content: string, cmdLine = newSeq[string]()): ExampleConfigFile =
proc loadExampleConfig(
content: string,
cmdLine = newSeq[string]()
): ExampleConfigFile {.raises: [ConfigurationError, OSError].} =
ExampleConfigFile.load(
cmdLine = cmdLine,
secondarySources = proc (
config: ExampleConfigFile, sources: ref SecondarySources
) {.raises: [ConfigurationError].} =
config: ExampleConfigFile,
sources: ref SecondarySources) {.raises: [ConfigurationError].} =
sources.addConfigFileContent(Toml, content))
const