Fabcoin Core  0.16.2
P2P Digital Currency
StateTests.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/filesystem/operations.hpp>
24 #include <boost/test/unit_test.hpp>
25 
27 #include <libdevcore/CommonIO.h>
28 #include <libethereum/BlockChain.h>
29 #include <libethereum/State.h>
30 #include <libethereum/ExtVM.h>
31 #include <libethereum/Defaults.h>
32 #include <libevm/VM.h>
34 
35 using namespace std;
36 using namespace json_spirit;
37 using namespace dev;
38 using namespace dev::eth;
39 
40 namespace dev { namespace test {
41 
42 void doStateTests(json_spirit::mValue& _v, bool _fillin)
43 {
44  for (auto& i: _v.get_obj())
45  {
46  string testname = i.first;
47  json_spirit::mObject& o = i.second.get_obj();
48 
49  if (!TestOutputHelper::passTest(o, testname))
50  continue;
51 
52  //For 100% at the log output
53  if (_fillin == false && Options::get().fillchain)
54  continue;
55 
56  BOOST_REQUIRE_MESSAGE(o.count("env") > 0, testname + "env not set!");
57  BOOST_REQUIRE_MESSAGE(o.count("pre") > 0, testname + "pre not set!");
58  BOOST_REQUIRE_MESSAGE(o.count("transaction") > 0, testname + "transaction not set!");
59 
60  ImportTest importer(o, _fillin, testType::GeneralStateTest);
61  const State importedStatePost = importer.m_statePost;
62 
63  Listener::ExecTimeGuard guard{i.first};
64  importer.executeTest();
65  if (Options::get().fillchain)
66  continue;
67 
68  if (_fillin)
69  {
70 #if ETH_FATDB
71  if (importer.exportTest(bytes()))
72  cerr << testname << endl;
73 #else
74  BOOST_THROW_EXCEPTION(Exception() << errinfo_comment(testname + "You can not fill tests when FATDB is switched off"));
75 #endif
76  }
77  else
78  {
79  BOOST_REQUIRE(o.count("post") > 0);
80 
81  //check post hashes against cpp client on all networks
82  mObject post = o["post"].get_obj();
83  vector<size_t> wrongTransactionsIndexes;
84  for (mObject::const_iterator i = post.begin(); i != post.end(); ++i)
85  {
86  for (auto const& exp: i->second.get_array())
87  {
88  if (!Options::get().singleTestNet.empty() && i->first != Options::get().singleTestNet)
89  continue;
90  importer.checkGeneralTestSection(exp.get_obj(), wrongTransactionsIndexes, i->first);
91  }
92  }
93  }
94  }
95 }
96 } }// Namespace Close
97 
99 {
100 public:
102  {
103  string casename = boost::unit_test::framework::current_test_case().p_name;
104  if (casename == "stBoundsTest" && !test::Options::get().memory)
105  return;
106  if (casename == "stMemoryStressTest" && !test::Options::get().memory)
107  return;
108  if (casename == "stQuadraticComplexityTest" && !test::Options::get().quadratic)
109  return;
110  fillAllFilesInFolder(casename);
111  }
112 
113  void fillAllFilesInFolder(string _folder)
114  {
115  std::string fillersPath = dev::test::getTestPath() + "/src/GeneralStateTestsFiller/" + _folder;
116 
117  boost::filesystem::directory_iterator iterator_tmp(fillersPath);
118  int fileCount = 0;
119  for(; iterator_tmp != boost::filesystem::directory_iterator(); ++iterator_tmp)
120  if (boost::filesystem::is_regular_file(iterator_tmp->path()) && iterator_tmp->path().extension() == ".json")
121  fileCount++;
123  fileCount *= 2; //tests are checked when filled and after they been filled
125 
126  boost::filesystem::directory_iterator iterator(fillersPath);
127  for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
128  if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() == ".json")
129  {
130  string fileboost = iterator->path().filename().string();
131  dev::test::executeTests(fileboost, "/GeneralStateTests/"+_folder, "/GeneralStateTestsFiller/"+_folder, dev::test::doStateTests);
132  }
134  }
135 };
136 
138 
139 //Frontier Tests
140 BOOST_AUTO_TEST_CASE(stBlockHashTest){}
141 BOOST_AUTO_TEST_CASE(stBoundsTest){}
142 BOOST_AUTO_TEST_CASE(stCallCodes){}
143 BOOST_AUTO_TEST_CASE(stCallCreateCallCodeTest){}
145 BOOST_AUTO_TEST_CASE(stInitCodeTest){}
146 BOOST_AUTO_TEST_CASE(stLogTests){}
147 BOOST_AUTO_TEST_CASE(stMemoryTest){}
148 BOOST_AUTO_TEST_CASE(stPreCompiledContracts){}
150 BOOST_AUTO_TEST_CASE(stRecursiveCreate){}
151 BOOST_AUTO_TEST_CASE(stRefundTest){}
152 BOOST_AUTO_TEST_CASE(stSolidityTest){}
153 BOOST_AUTO_TEST_CASE(stSpecialTest){}
154 BOOST_AUTO_TEST_CASE(stSystemOperationsTest){}
155 BOOST_AUTO_TEST_CASE(stTransactionTest){}
156 BOOST_AUTO_TEST_CASE(stTransitionTest){}
157 BOOST_AUTO_TEST_CASE(stWalletTest){}
158 
159 //Homestead Tests
160 BOOST_AUTO_TEST_CASE(stCallDelegateCodesCallCodeHomestead){}
161 BOOST_AUTO_TEST_CASE(stCallDelegateCodesHomestead){}
162 BOOST_AUTO_TEST_CASE(stHomesteadSpecific){}
163 BOOST_AUTO_TEST_CASE(stDelegatecallTestHomestead){}
164 
165 //EIP150 Tests
166 BOOST_AUTO_TEST_CASE(stChangedEIP150){}
167 BOOST_AUTO_TEST_CASE(stEIP150singleCodeGasPrices){}
168 BOOST_AUTO_TEST_CASE(stMemExpandingEIP150Calls){}
169 BOOST_AUTO_TEST_CASE(stEIP150Specific){}
170 
171 //EIP158 Tests
172 BOOST_AUTO_TEST_CASE(stEIP158Specific){}
173 BOOST_AUTO_TEST_CASE(stNonZeroCallsTest){}
174 BOOST_AUTO_TEST_CASE(stZeroCallsTest){}
175 BOOST_AUTO_TEST_CASE(stZeroCallsRevert){}
176 BOOST_AUTO_TEST_CASE(stCodeSizeLimit){}
177 BOOST_AUTO_TEST_CASE(stCreateTest){}
178 BOOST_AUTO_TEST_CASE(stRevertTest){}
179 
180 //Metropolis Tests
181 BOOST_AUTO_TEST_CASE(stStackTests){}
182 
183 //Stress Tests
184 BOOST_AUTO_TEST_CASE(stAttackTest){}
185 BOOST_AUTO_TEST_CASE(stMemoryStressTest){}
186 BOOST_AUTO_TEST_CASE(stQuadraticComplexityTest){}
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
bool filltests
Create JSON test files from execution results.
Definition: Options.h:41
static Options const & get(int argc=0, char **argv=0)
Get reference to options The first time used, options are parsed with argc, argv. ...
Definition: Options.cpp:203
std::hash for asio::adress
Definition: Common.h:323
Model of an Ethereum state, essentially a facade for the trie.
Definition: State.h:161
BOOST_AUTO_TEST_CASE(stBlockHashTest)
Definition: StateTests.cpp:140
void doStateTests(json_spirit::mValue &_v, bool _fillin)
Definition: StateTests.cpp:42
Base class for all exceptions.
Definition: Exceptions.h:39
Test started/finished notification RAII helper.
Definition: TestHelper.h:189
std::vector< byte > bytes
Definition: Common.h:75
std::string getTestPath()
Definition: Common.cpp:35
void fillAllFilesInFolder(string _folder)
Definition: StateTests.cpp:113
mConfig::Object_type mObject
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
boost::error_info< struct tag_comment, std::string > errinfo_comment
Definition: Assertions.h:78
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
void executeTests(const string &_name, const string &_testPathAppendix, const string &_fillerPathAppendix, std::function< void(json_spirit::mValue &, bool)> doTests, bool _addFillerSuffix)
Definition: TestHelper.cpp:434
Helper functions to work with json::spirit and test files.
static void initTest(int _maxTests=1)