2019-04-05 08:13:22 +00:00
|
|
|
import
|
2021-05-11 07:24:10 +00:00
|
|
|
std/strutils,
|
|
|
|
chronos, bearssl,
|
2021-04-06 11:33:24 +00:00
|
|
|
../../eth/[keys, p2p], ../../eth/p2p/[discovery, enode]
|
2019-04-05 08:13:22 +00:00
|
|
|
|
|
|
|
var nextPort = 30303
|
|
|
|
|
2019-06-17 20:12:50 +00:00
|
|
|
proc localAddress*(port: int): Address =
|
2019-04-05 08:13:22 +00:00
|
|
|
let port = Port(port)
|
2020-02-17 23:07:23 +00:00
|
|
|
result = Address(udpPort: port, tcpPort: port,
|
|
|
|
ip: parseIpAddress("127.0.0.1"))
|
2019-04-05 08:13:22 +00:00
|
|
|
|
2020-07-07 08:56:26 +00:00
|
|
|
proc setupTestNode*(
|
|
|
|
rng: ref BrHmacDrbgContext,
|
|
|
|
capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode {.gcsafe.} =
|
|
|
|
# Don't create new RNG every time in production code!
|
|
|
|
let keys1 = KeyPair.random(rng[])
|
2021-02-13 08:41:09 +00:00
|
|
|
result = newEthereumNode(keys1, localAddress(nextPort), NetworkId(1), nil,
|
2020-07-07 08:56:26 +00:00
|
|
|
addAllCapabilities = false, rng = rng)
|
2019-04-05 08:13:22 +00:00
|
|
|
nextPort.inc
|
|
|
|
for capability in capabilities:
|
|
|
|
result.addCapability capability
|
|
|
|
|
2019-10-22 12:08:25 +00:00
|
|
|
template sourceDir*: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|
|
|
|
|
|
|
proc recvMsgMock*(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] =
|
2020-04-20 18:14:39 +00:00
|
|
|
var rlp = rlpFromBytes(msg)
|
2019-10-22 12:08:25 +00:00
|
|
|
|
2019-10-22 15:00:19 +00:00
|
|
|
let msgId = rlp.read(int32)
|
2020-02-17 23:07:23 +00:00
|
|
|
return (msgId.int, rlp)
|