Fabcoin Core  0.16.2
P2P Digital Currency
whisperDB.cpp
Go to the documentation of this file.
1 /*
2 This file is part of cpp-ethereum.
3 
4 cpp-ethereum is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 cpp-ethereum is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #include <thread>
23 
24 #if defined(_MSC_VER)
25 #pragma warning(push)
26 #pragma warning(disable:4535) // calling _set_se_translator requires /EHa
27 #endif
28 #include <boost/test/unit_test.hpp>
29 #if defined(_MSC_VER)
30 #pragma warning(pop)
31 #endif
32 
33 #include <libp2p/Host.h>
34 #include <libwhisper/WhisperDB.h>
35 #include <libwhisper/WhisperHost.h>
37 
38 using namespace std;
39 using namespace dev;
40 using namespace dev::test;
41 using namespace dev::shh;
42 using namespace dev::p2p;
43 
44 struct P2PFixture: public TestOutputHelper
45 {
49 };
50 
52 
53 //
54 // Disabled tests as they are unstable and tend to stall the test suite.
55 //
56 
57 //BOOST_AUTO_TEST_CASE(basic)
58 //{
59 // VerbosityHolder setTemporaryLevel(10);
60 // cnote << "Testing Whisper DB...";
61 
62 // string s;
63 // string const text1 = "lorem";
64 // string const text2 = "ipsum";
65 // h256 h1(0xBEEF);
66 // h256 h2(0xC0FFEE);
67 // WhisperMessagesDB db;
68 
69 // db.kill(h1);
70 // db.kill(h2);
71 
72 // s = db.lookup(h1);
73 // BOOST_REQUIRE(s.empty());
74 
75 // db.insert(h1, text2);
76 // s = db.lookup(h2);
77 // BOOST_REQUIRE(s.empty());
78 // s = db.lookup(h1);
79 // BOOST_REQUIRE(!s.compare(text2));
80 
81 // db.insert(h1, text1);
82 // s = db.lookup(h2);
83 // BOOST_REQUIRE(s.empty());
84 // s = db.lookup(h1);
85 // BOOST_REQUIRE(!s.compare(text1));
86 
87 // db.insert(h2, text2);
88 // s = db.lookup(h2);
89 // BOOST_REQUIRE(!s.compare(text2));
90 // s = db.lookup(h1);
91 // BOOST_REQUIRE(!s.compare(text1));
92 
93 // db.kill(h1);
94 // db.kill(h2);
95 
96 // s = db.lookup(h2);
97 // BOOST_REQUIRE(s.empty());
98 // s = db.lookup(h1);
99 // BOOST_REQUIRE(s.empty());
100 //}
101 
102 //BOOST_AUTO_TEST_CASE(persistence)
103 //{
104 // VerbosityHolder setTemporaryLevel(10);
105 // cnote << "Testing persistence of Whisper DB...";
106 
107 // string s;
108 // string const text1 = "sator";
109 // string const text2 = "arepo";
110 // h256 const h1(0x12345678);
111 // h256 const h2(0xBADD00DE);
112 
113 // {
114 // WhisperMessagesDB db;
115 // db.kill(h1);
116 // db.kill(h2);
117 // s = db.lookup(h1);
118 // BOOST_REQUIRE(s.empty());
119 // db.insert(h1, text2);
120 // s = db.lookup(h2);
121 // BOOST_REQUIRE(s.empty());
122 // s = db.lookup(h1);
123 // BOOST_REQUIRE(!s.compare(text2));
124 // }
125 
126 // this_thread::sleep_for(chrono::milliseconds(20));
127 
128 // {
129 // WhisperMessagesDB db;
130 // db.insert(h1, text1);
131 // db.insert(h2, text2);
132 // }
133 
134 // this_thread::sleep_for(chrono::milliseconds(20));
135 
136 // {
137 // WhisperMessagesDB db;
138 // s = db.lookup(h2);
139 // BOOST_REQUIRE(!s.compare(text2));
140 // s = db.lookup(h1);
141 // BOOST_REQUIRE(!s.compare(text1));
142 // db.kill(h1);
143 // db.kill(h2);
144 // }
145 //}
146 
147 //BOOST_AUTO_TEST_CASE(messages)
148 //{
149 // cnote << "Testing load/save Whisper messages...";
150 // VerbosityHolder setTemporaryLevel(2);
151 
152 // unsigned const TestSize = 3;
153 // map<h256, Envelope> m1;
154 // map<h256, Envelope> preexisting;
155 // KeyPair us = KeyPair::create();
156 
157 // {
158 // p2p::Host h("Test");
159 // auto wh = h.registerCapability(make_shared<WhisperHost>(true));
160 // preexisting = wh->all();
161 // cnote << preexisting.size() << "preexisting messages in DB";
162 // wh->installWatch(BuildTopic("test"));
163 
164 // for (unsigned i = 0; i < TestSize; ++i)
165 // wh->post(us.secret(), RLPStream().append(i).out(), BuildTopic("test"), 0xFFFFF);
166 
167 // m1 = wh->all();
168 // }
169 
170 // {
171 // p2p::Host h("Test");
172 // auto wh = h.registerCapability(make_shared<WhisperHost>(true));
173 // map<h256, Envelope> m2 = wh->all();
174 // wh->installWatch(BuildTopic("test"));
175 // BOOST_REQUIRE_EQUAL(m1.size(), m2.size());
176 // BOOST_REQUIRE_EQUAL(m1.size() - preexisting.size(), TestSize);
177 
178 // for (auto i: m1)
179 // {
180 // RLPStream rlp1;
181 // RLPStream rlp2;
182 // i.second.streamRLP(rlp1);
183 // m2[i.first].streamRLP(rlp2);
184 // BOOST_REQUIRE_EQUAL(rlp1.out().size(), rlp2.out().size());
185 // for (unsigned j = 0; j < rlp1.out().size(); ++j)
186 // BOOST_REQUIRE_EQUAL(rlp1.out()[j], rlp2.out()[j]);
187 // }
188 // }
189 
190 // WhisperMessagesDB db;
191 // unsigned x = 0;
192 
193 // for (auto i: m1)
194 // if (preexisting.find(i.first) == preexisting.end())
195 // {
196 // db.kill(i.first);
197 // ++x;
198 // }
199 
200 // BOOST_REQUIRE_EQUAL(x, TestSize);
201 //}
202 
203 //BOOST_AUTO_TEST_CASE(corruptedData)
204 //{
205 // cnote << "Testing corrupted data...";
206 // VerbosityHolder setTemporaryLevel(2);
207 
208 // map<h256, Envelope> m;
209 // h256 x = h256::random();
210 
211 // {
212 // WhisperMessagesDB db;
213 // db.insert(x, "this is a test input, representing corrupt data");
214 // }
215 
216 // {
217 // p2p::Host h("Test");
218 // auto wh = h.registerCapability(make_shared<WhisperHost>(true));
219 // m = wh->all();
220 // BOOST_REQUIRE(m.end() == m.find(x));
221 // }
222 
223 // {
224 // WhisperMessagesDB db;
225 // string s = db.lookup(x);
226 // BOOST_REQUIRE(s.empty());
227 // }
228 //}
229 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::hash for asio::adress
Definition: Common.h:323
Definition: Eth.h:45
TestOutputHelper testHelper
Definition: whisperDB.cpp:48
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
static bool test_allowLocal
Setting true causes isAllowed to return true for all addresses. (Used by test fixtures) ...
Definition: Common.h:185
Helper functions to work with json::spirit and test files.