nim-ethers/testmodule/examples.nim
Eric 458e969397
Make Transaction.data optional
eth_getTransactionByHash responses from geth don't include data, and there was an exception raised, "key not found: data"
2023-10-25 10:51:56 +11:00

25 lines
594 B
Nim

import std/random
import std/sequtils
import pkg/ethers
randomize()
proc example*[N](_: type array[N, byte]): array[N, byte] =
var a: array[N, byte]
for b in a.mitems:
b = rand(byte)
a
proc example*(_: type seq[byte]): seq[byte] =
let length = rand(0..<20)
newSeqWith(length, rand(byte))
proc example*(_: type Address): Address =
Address.init(array[20, byte].example)
proc example*(_: type UInt256): UInt256 =
UInt256.fromBytesBE(array[32, byte].example)
proc example*(_: type Transaction): Transaction =
Transaction(to: Address.example, data: some seq[byte].example)