From 77d93d71bdd77bd67f74e84e4dcec4bbd75a39c6 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 16 Feb 2022 10:17:00 +0100 Subject: [PATCH] tests: generate PeerRecords from NodeId this is just for the testing --- tests/p2p/test_providers.nim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/p2p/test_providers.nim b/tests/p2p/test_providers.nim index a01662d..62a48a3 100644 --- a/tests/p2p/test_providers.nim +++ b/tests/p2p/test_providers.nim @@ -17,7 +17,9 @@ import chronicles, ../../eth/p2p/discoveryv5/protocol as discv5_protocol, ./discv5_test_helper, - libp2p/routing_record + libp2p/routing_record, + libp2p/multihash, + libp2p/multicodec proc initProvidersNode( rng: ref BrHmacDrbgContext, @@ -29,6 +31,21 @@ proc initProvidersNode( let d = initDiscoveryNode(rng, privKey, address, bootstrapRecords) newProvidersProtocol(d) +proc toPeerRecord(p: ProvidersProtocol) : PeerRecord = + ## hadle conversion between the two worlds + + #NodeId is a keccak-256 hash created by keccak256.digest and stored as UInt256 + let discNodeId = p.discovery.localNode.id + ## get it back to MDigest form + var digest: MDigest[256] + digest.data = discNodeId.toBytesBE + ## get into a MultiHash + var mh = MultiHash.init(multiCodec("keccak-256"), digest).orError(HashError).get() + result = PeerRecord.init( + peerId = PeerId.init(mh.data.buffer).get, + seqNo = 0, + addresses = @[]) + proc bootstrapNodes(nodecount: int, bootnodes: openArray[Record], rng = keys.newRng()) : seq[ProvidersProtocol] = for i in 0..