nim-eth/tests/fuzzing/enr/generate.nim
Kim De Mey d7577f59d7
Rework of ENR decoding code (#709)
- Rework to have exception raise only at rlp decoding and use
result types from then onwards
- Adjust the current API to have result versions and deprecated
the ones which had var Record + bool
- Add PublickKey to the Record object, as this allows us to skip
fromRaw calls whenever access is needed to the public key
- Add a TypedRecord.fromRecord which cannot fail and deprecate
the old one
- Some other minor clean-up & re-ordering
2024-06-27 15:15:23 +02:00

25 lines
687 B
Nim

import
std/[os, strutils, net],
../../../eth/keys, ../../../eth/p2p/discoveryv5/enr,
../fuzzing_helpers
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
const inputsDir = sourceDir / "corpus"
proc generate() =
let
rng = newRng()
privKey = PrivateKey.random(rng[])
ip = Opt.some(parseIpAddress("127.0.0.1"))
port = Opt.some(Port(20301))
block:
let record = enr.Record.init(1, privKey, ip, port, port)[]
record.raw.toFile(inputsDir / "enr1")
block:
let record = enr.Record.init(1, privKey, ip, port, port, [toFieldPair("test", 1'u)])[]
record.raw.toFile(inputsDir / "enr2")
discard existsOrCreateDir(inputsDir)
generate()