Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 835c140

Browse files
committed
Test for updating host ENR from config value in Host
1 parent b7049d9 commit 835c140

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

libp2p/Host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class Host: public Worker
368368
/// Alias for network communication.
369369
KeyPair m_alias;
370370
/// Host's Ethereum Node Record restored from network.rlp
371-
ENR m_restoredENR;
371+
ENR const m_restoredENR;
372372
std::shared_ptr<NodeTable> m_nodeTable; ///< Node table (uses kademlia-like discovery).
373373
mutable std::mutex x_nodeTable;
374374
std::shared_ptr<NodeTable> nodeTable() const { Guard l(x_nodeTable); return m_nodeTable; }

test/unittests/libp2p/peer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ BOOST_AUTO_TEST_CASE(saveENR)
238238
BOOST_REQUIRE(enr1.signature() == enr2.signature());
239239
}
240240

241+
BOOST_AUTO_TEST_CASE(updateENRfromConfig)
242+
{
243+
NetworkConfig config("", "", 30303, false);
244+
Host host1("Test", config);
245+
ENR enr1 = host1.enr();
246+
247+
bytes store(host1.saveNetwork());
248+
249+
NetworkConfig config2("13.74.189.148", "", 30303, false);
250+
Host host2("Test", config2, bytesConstRef(&store));
251+
host2.start();
252+
host2.stop();
253+
ENR enr2 = host2.enr();
254+
255+
BOOST_REQUIRE_EQUAL(enr2.sequenceNumber(), enr1.sequenceNumber() + 1);
256+
BOOST_REQUIRE_EQUAL(enr2.ip(), bi::address::from_string("13.74.189.148"));
257+
}
241258

242259
BOOST_AUTO_TEST_SUITE_END()
243260

0 commit comments

Comments
 (0)