Fabcoin Core  0.16.2
P2P Digital Currency
overlaydb.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 */
23 #include <boost/test/unit_test.hpp>
25 #include <libdevcore/OverlayDB.h>
27 
28 using namespace std;
29 using namespace dev;
30 using namespace dev::test;
31 
33 
35 {
36  ldb::Options o;
37  o.max_open_files = 256;
38  o.create_if_missing = true;
39  ldb::DB* db = nullptr;
41  ldb::Status status = ldb::DB::Open(o, td.path(), &db);
42  BOOST_REQUIRE(status.ok() && db);
43 
44  OverlayDB odb(db);
45  BOOST_CHECK(!odb.get().size());
46 
47  // commit nothing
48  odb.commit();
49 
50  bytes value = fromHex("43");
51  BOOST_CHECK(!odb.get().size());
52 
53  odb.insert(h256(42), &value);
54  BOOST_CHECK(odb.get().size());
55  BOOST_CHECK(odb.exists(h256(42)));
56  BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0]));
57 
58  odb.commit();
59  BOOST_CHECK(!odb.get().size());
60  BOOST_CHECK(odb.exists(h256(42)));
61  BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0]));
62 
63  odb.insert(h256(41), &value);
64  odb.commit();
65  BOOST_CHECK(!odb.get().size());
66  BOOST_CHECK(odb.exists(h256(41)));
67  BOOST_CHECK_EQUAL(odb.lookup(h256(41)), toString(value[0]));
68  BOOST_CHECK(odb.deepkill(h256(41)));
69  BOOST_CHECK(!odb.exists(h256(41)));
70  BOOST_CHECK_EQUAL(odb.lookup(h256(41)), string());
71 }
72 
74 {
75  ldb::Options o;
76  o.max_open_files = 256;
77  o.create_if_missing = true;
78  ldb::DB* db = nullptr;
80  ldb::Status status = ldb::DB::Open(o, td.path(), &db);
81  BOOST_REQUIRE(status.ok() && db);
82 
83  OverlayDB odb(db);
84 
85  bytes value = fromHex("43");
86  bytes valueAux = fromHex("44");
87 
88  odb.insert(h256(42), &value);
89  odb.insert(h256(0), &value);
90  odb.insert(h256(numeric_limits<u256>::max()), &value);
91 
92  odb.insertAux(h256(42), &valueAux);
93  odb.insertAux(h256(0), &valueAux);
94  odb.insertAux(h256(numeric_limits<u256>::max()), &valueAux);
95 
96  odb.commit();
97 
98  BOOST_CHECK(!odb.get().size());
99 
100  BOOST_CHECK(odb.exists(h256(42)));
101  BOOST_CHECK_EQUAL(odb.lookup(h256(42)), toString(value[0]));
102 
103  BOOST_CHECK(odb.exists(h256(0)));
104  BOOST_CHECK_EQUAL(odb.lookup(h256(0)), toString(value[0]));
105 
108 
109  BOOST_CHECK(odb.lookupAux(h256(42)) == valueAux);
110  BOOST_CHECK(odb.lookupAux(h256(0)) == valueAux);
111  BOOST_CHECK(odb.lookupAux(h256(std::numeric_limits<u256>::max())) == valueAux);
112 }
113 
115 {
116  ldb::Options o;
117  o.max_open_files = 256;
118  o.create_if_missing = true;
119  ldb::DB* db = nullptr;
121  ldb::Status status = ldb::DB::Open(o, td.path(), &db);
122  BOOST_REQUIRE(status.ok() && db);
123 
124  OverlayDB odb(db);
125  bytes value = fromHex("42");
126 
127  odb.insert(h256(43), &value);
128  BOOST_CHECK(odb.get().size());
129  odb.rollback();
130  BOOST_CHECK(!odb.get().size());
131 }
132 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Definition: util.h:95
std::hash for asio::adress
Definition: Common.h:323
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
BOOST_AUTO_TEST_CASE(basicUsage)
Definition: overlaydb.cpp:34
ExecStats::duration max
Definition: ExecStats.cpp:36
std::vector< byte > bytes
Definition: Common.h:75
FixedHash< 32 > h256
Definition: FixedHash.h:340
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
std::string const & path() const
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
temporary directory implementation It creates temporary directory in the given path.
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)
Definition: object.cpp:17