wrap `applyExecutionPayload` in factories for Nim 2.0 (#5395)

In Nim 2.0, the `test_fixture_operations` files fail to compile with:

```
Error: 'result' is of type <Result[system.void, system.cstring]> which cannot be captured as it would violate memory safety, declared here: /nimbus-eth2/tests/consensus_spec/bellatrix/test_fixture_operations.nim(130, 5); using '-d:nimNoLentIterators' helps in some cases. Consider using a <ref Result[system.void, system.cstring]> which can be captured.
```

Wrapping the `applyExecutionPayload` in a factory that takes `path`
avoids this problem.
This commit is contained in:
Etan Kissling 2023-09-06 10:35:37 +02:00 committed by GitHub
parent 81397342d0
commit 6af70e2f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 15 deletions

View File

@ -126,17 +126,19 @@ suite baseDescription & "Deposit " & preset():
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path) OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Execution Payload " & preset(): suite baseDescription & "Execution Payload " & preset():
for path in walkTests(OpExecutionPayloadDir): proc makeApplyExecutionPayloadCb(path: string): auto =
proc applyExecutionPayload( return proc(
preState: var bellatrix.BeaconState, body: bellatrix.BeaconBlockBody): preState: var bellatrix.BeaconState, body: bellatrix.BeaconBlockBody):
Result[void, cstring] = Result[void, cstring] =
let payloadValid = let payloadValid = os_ops.readFile(
os_ops.readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"). OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
contains("execution_valid: true") ).contains("execution_valid: true")
func executePayload(_: bellatrix.ExecutionPayload): bool = payloadValid func executePayload(_: bellatrix.ExecutionPayload): bool = payloadValid
process_execution_payload( process_execution_payload(
preState, body.execution_payload, executePayload) preState, body.execution_payload, executePayload)
for path in walkTests(OpExecutionPayloadDir):
let applyExecutionPayload = makeApplyExecutionPayloadCb(path)
runTest[bellatrix.BeaconBlockBody, typeof applyExecutionPayload]( runTest[bellatrix.BeaconBlockBody, typeof applyExecutionPayload](
OpExecutionPayloadDir, suiteName, "Execution Payload", "body", OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
applyExecutionPayload, path) applyExecutionPayload, path)

View File

@ -143,17 +143,19 @@ suite baseDescription & "Deposit " & preset():
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path) OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Execution Payload " & preset(): suite baseDescription & "Execution Payload " & preset():
for path in walkTests(OpExecutionPayloadDir): proc makeApplyExecutionPayloadCb(path: string): auto =
proc applyExecutionPayload( return proc(
preState: var capella.BeaconState, body: capella.BeaconBlockBody): preState: var capella.BeaconState, body: capella.BeaconBlockBody):
Result[void, cstring] = Result[void, cstring] =
let payloadValid = let payloadValid = os_ops.readFile(
os_ops.readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"). OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
contains("execution_valid: true") ).contains("execution_valid: true")
func executePayload(_: capella.ExecutionPayload): bool = payloadValid func executePayload(_: capella.ExecutionPayload): bool = payloadValid
process_execution_payload( process_execution_payload(
preState, body.execution_payload, executePayload) preState, body.execution_payload, executePayload)
for path in walkTests(OpExecutionPayloadDir):
let applyExecutionPayload = makeApplyExecutionPayloadCb(path)
runTest[capella.BeaconBlockBody, typeof applyExecutionPayload]( runTest[capella.BeaconBlockBody, typeof applyExecutionPayload](
OpExecutionPayloadDir, suiteName, "Execution Payload", "body", OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
applyExecutionPayload, path) applyExecutionPayload, path)

View File

@ -146,16 +146,18 @@ suite baseDescription & "Deposit " & preset():
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path) OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Execution Payload " & preset(): suite baseDescription & "Execution Payload " & preset():
for path in walkTests(OpExecutionPayloadDir): proc makeApplyExecutionPayloadCb(path: string): auto =
proc applyExecutionPayload( return proc(
preState: var deneb.BeaconState, body: deneb.BeaconBlockBody): preState: var deneb.BeaconState, body: deneb.BeaconBlockBody):
Result[void, cstring] = Result[void, cstring] =
let payloadValid = let payloadValid = os_ops.readFile(
os_ops.readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"). OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
contains("execution_valid: true") ).contains("execution_valid: true")
func executePayload(_: deneb.ExecutionPayload): bool = payloadValid func executePayload(_: deneb.ExecutionPayload): bool = payloadValid
process_execution_payload(preState, body, executePayload) process_execution_payload(preState, body, executePayload)
for path in walkTests(OpExecutionPayloadDir):
let applyExecutionPayload = makeApplyExecutionPayloadCb(path)
runTest[deneb.BeaconBlockBody, typeof applyExecutionPayload]( runTest[deneb.BeaconBlockBody, typeof applyExecutionPayload](
OpExecutionPayloadDir, suiteName, "Execution Payload", "body", OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
applyExecutionPayload, path) applyExecutionPayload, path)