31 string name()
const override {
return "mock capability name"; }
34 shared_ptr<Capability>
newPeerCapability(shared_ptr<SessionFace>
const&,
unsigned,
CapDesc const&, uint16_t)
override {
return shared_ptr<Capability>(); }
54 int rating()
const override {
return 0; }
57 void addNote(
string const& _k,
string const& _v)
override 68 map<CapDesc, shared_ptr<Capability>>
const&
capabilities()
const override {
return m_capabilities; }
70 shared_ptr<Peer>
peer()
const override {
return shared_ptr<Peer>(); }
94 void onPeerNewHashes(std::shared_ptr<EthereumPeer>, std::vector<std::pair<h256, u256>>
const&)
override {}
112 peer(session, &hostCap, offset, {
"eth", 0 }, 0)
114 peer.init(63, 2, 0,
h256(0),
h256(0), shared_ptr<EthereumHostDataFace>(), observer);
128 h256 dataHash(
"0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef");
129 peer.requestNodeData({ dataHash });
131 uint8_t
code =
static_cast<uint8_t
>(session->m_bytesSent[0]);
132 BOOST_REQUIRE_EQUAL(code, offset + 0x0d);
134 bytes payloadSent(session->m_bytesSent.begin() + 1, session->m_bytesSent.end());
136 BOOST_REQUIRE(rlp.isList());
137 BOOST_REQUIRE_EQUAL(rlp.itemCount(), 1);
138 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[0]), dataHash);
143 h256 dataHash0(
"0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef");
144 h256 dataHash1(
"0x0e4562a10381dec21b205ed72637e6b1b523bdd0e4d4d50af5cd23dd4500a217");
145 h256 dataHash2(
"0x53ab44f45948543775a4c405085b918e5e648db1201283bb54a59701afdaedf3");
146 peer.requestNodeData({ dataHash0, dataHash1, dataHash2 });
148 bytes payloadSent(session->m_bytesSent.begin() + 1, session->m_bytesSent.end());
150 BOOST_REQUIRE_EQUAL(rlp.itemCount(), 3);
151 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[0]), dataHash0);
152 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[1]), dataHash1);
153 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[2]), dataHash2);
158 h256 dataHash(
"0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef");
159 peer.requestNodeData({
h256(
"0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef") });
161 BOOST_REQUIRE(session->m_notes.find(
"ask") != session->m_notes.end());
162 BOOST_REQUIRE(session->m_notes[
"ask"] ==
"NodeData");
167 peer.requestNodeData({});
169 BOOST_REQUIRE(session->m_notes.find(
"ask") != session->m_notes.end());
170 BOOST_REQUIRE(session->m_notes[
"ask"] ==
"Nothing");
175 h256 blockHash0(
"0x949d991d685738352398dff73219ab19c62c06e6f8ce899fbae755d5127ed1ef");
176 h256 blockHash1(
"0x0e4562a10381dec21b205ed72637e6b1b523bdd0e4d4d50af5cd23dd4500a217");
177 h256 blockHash2(
"0x53ab44f45948543775a4c405085b918e5e648db1201283bb54a59701afdaedf3");
178 peer.requestReceipts({ blockHash0, blockHash1, blockHash2 });
180 bytes payloadSent(session->m_bytesSent.begin() + 1, session->m_bytesSent.end());
182 BOOST_REQUIRE_EQUAL(rlp.itemCount(), 3);
183 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[0]), blockHash0);
184 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[1]), blockHash1);
185 BOOST_REQUIRE_EQUAL(static_cast<h256>(rlp[2]), blockHash2);
ReputationManager m_repMan
EthereumPeerTestFixture()
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void disconnect(DisconnectReason) override
string name() const override
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
std::pair< std::string, u256 > CapDesc
PeerSessionInfo info() const override
BOOST_AUTO_TEST_CASE(EthereumPeerSuite_requestNodeData)
chrono::steady_clock::time_point lastReceived() const override
void onPeerReceipts(std::shared_ptr< EthereumPeer >, RLP const &) override
void onPeerNodeData(std::shared_ptr< EthereumPeer >, RLP const &) override
shared_ptr< MockEthereumPeerObserver > observer
std::hash for asio::adress
bool isConnected() const override
void onPeerBlockHeaders(std::shared_ptr< EthereumPeer >, RLP const &) override
void onPeerBlockBodies(std::shared_ptr< EthereumPeer >, RLP const &) override
shared_ptr< MockSession > session
unsigned messageCount() const override
shared_ptr< Capability > newPeerCapability(shared_ptr< SessionFace > const &, unsigned, CapDesc const &, uint16_t) override
void registerCapability(CapDesc const &, shared_ptr< Capability >) override
ReputationManager & repMan() override
void addNote(string const &_k, string const &_v) override
NodeID id() const override
std::vector< byte > bytes
shared_ptr< Peer > peer() const override
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
void onPeerAborting() override
u256 version() const override
MockHostCapability hostCap
#define BOOST_FIXTURE_TEST_SUITE(a, b)
chrono::steady_clock::time_point connectionTime() override
clock::time_point time_point
#define BOOST_AUTO_TEST_SUITE_END()
void onPeerNewBlock(std::shared_ptr< EthereumPeer >, RLP const &) override
void onPeerTransactions(std::shared_ptr< EthereumPeer >, RLP const &) override
void addRating(int) override
map< CapDesc, shared_ptr< Capability > > const & capabilities() const override
map< CapDesc, std::shared_ptr< Capability > > m_capabilities
void swapOut(bytes &_dest)
Swap the contents of the output stream out for some other byte array.
Class for writing to an RLP bytestream.
int rating() const override
map< string, string > m_notes
void registerFraming(uint16_t) override
Class for interpreting Recursive Linear-Prefix Data.
void onPeerNewHashes(std::shared_ptr< EthereumPeer >, std::vector< std::pair< h256, u256 >> const &) override
void onPeerStatus(std::shared_ptr< EthereumPeer >) override
Helper functions to work with json::spirit and test files.
void sealAndSend(RLPStream &_s, uint16_t) override