Fabcoin Core  0.16.2
P2P Digital Currency
TestHelper.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 */
24 #if !defined(_WIN32)
25 #include <stdio.h>
26 #endif
27 #include <boost/algorithm/string/trim.hpp>
28 #include <libethereum/Client.h>
29 #include <test/libtesteth/Stats.h>
30 
31 using namespace std;
32 using namespace dev::eth;
33 
34 namespace dev
35 {
36 namespace eth
37 {
38 
39 void mine(Client& c, int numBlocks)
40 {
41  auto startBlock = c.blockChain().details().number;
42 
43  c.startSealing();
44  while(c.blockChain().details().number < startBlock + numBlocks)
45  std::this_thread::sleep_for(std::chrono::milliseconds(100));
46  c.stopSealing();
47 }
48 
50 {
51  (void)c1;
52  (void)c2;
53  // TODO: Move to WebThree. eth::Client no longer handles networking.
54 #if 0
55  short c1Port = 20000;
56  short c2Port = 21000;
57  c1.startNetwork(c1Port);
58  c2.startNetwork(c2Port);
59  c2.connect("127.0.0.1", c1Port);
60 #endif
61 }
62 
63 void mine(Block& s, BlockChain const& _bc, SealEngineFace* _sealer)
64 {
65  s.commitToSeal(_bc, s.info().extraData());
66  Notified<bytes> sealed;
67  _sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
68  _sealer->generateSeal(s.info());
69  sealed.waitNot({});
70  _sealer->onSealGenerated([](bytes const&){});
71  s.sealBlock(sealed);
72 }
73 
74 void mine(BlockHeader& _bi, SealEngineFace* _sealer, bool _verify)
75 {
76  Notified<bytes> sealed;
77  _sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
78  _sealer->generateSeal(_bi);
79  sealed.waitNot({});
80  _sealer->onSealGenerated([](bytes const&){});
81  _bi = BlockHeader(sealed, HeaderData);
82 // cdebug << "Block mined" << Ethash::boundary(_bi).hex() << Ethash::nonce(_bi) << _bi.hash(WithoutSeal).hex();
83  if (_verify) //sometimes it is needed to mine incorrect blockheaders for testing
84  _sealer->verify(JustSeal, _bi);
85 }
86 
87 }
88 
89 namespace test
90 {
91 
92 
94 {
95  switch(_netId)
96  {
97  case eth::Network::FrontierTest: return "Frontier";
98  case eth::Network::HomesteadTest: return "Homestead";
99  case eth::Network::EIP150Test: return "EIP150";
100  case eth::Network::EIP158Test: return "EIP158";
101  case eth::Network::MetropolisTest: return "Metropolis";
102  default: return "other";
103  }
104  return "unknown";
105 }
106 
107 eth::Network stringToNetId(string const& _netname)
108 {
109  if (netIdToString(eth::Network::FrontierTest) == _netname)
110  return eth::Network::FrontierTest;
111  if (netIdToString(eth::Network::HomesteadTest) == _netname)
112  return eth::Network::HomesteadTest;
113  if (netIdToString(eth::Network::EIP150Test) == _netname)
114  return eth::Network::EIP150Test;
115  if (netIdToString(eth::Network::EIP158Test) == _netname)
116  return eth::Network::EIP158Test;
117  if (netIdToString(eth::Network::MetropolisTest) == _netname)
118  return eth::Network::MetropolisTest;
119  BOOST_ERROR(TestOutputHelper::testName() + " network not found: " + _netname);
120  return eth::Network::FrontierTest;
121 }
122 
123 
125 {
126  json_spirit::mObject txObject;
127  txObject["nonce"] = toCompactHex(_txn.nonce(), HexPrefix::Add, 1);
128  txObject["data"] = toHex(_txn.data(), 2, HexPrefix::Add);
129  txObject["gasLimit"] = toCompactHex(_txn.gas(), HexPrefix::Add, 1);
130  txObject["gasPrice"] = toCompactHex(_txn.gasPrice(), HexPrefix::Add, 1);
131  txObject["r"] = toCompactHex(_txn.signature().r, HexPrefix::Add, 1);
132  txObject["s"] = toCompactHex(_txn.signature().s, HexPrefix::Add, 1);
133  txObject["v"] = toCompactHex(_txn.signature().v + 27, HexPrefix::Add, 1);
134  txObject["to"] = _txn.isCreation() ? "" : toString(_txn.receiveAddress());
135  txObject["value"] = toCompactHex(_txn.value(), HexPrefix::Add, 1);
136  return txObject;
137 }
138 
140 {
141  AccountMaskMap emptyMap;
142  return fillJsonWithState(_state, emptyMap);
143 }
144 
146 {
147  bool mapEmpty = (_map.size() == 0);
148  json_spirit::mObject oState;
149  for (auto const& a: _state.addresses())
150  {
151  if (_map.size() && _map.find(a.first) == _map.end())
152  continue;
153 
155  if (mapEmpty || _map.at(a.first).hasBalance())
156  o["balance"] = toCompactHex(_state.balance(a.first), HexPrefix::Add, 1);
157  if (mapEmpty || _map.at(a.first).hasNonce())
158  o["nonce"] = toCompactHex(_state.getNonce(a.first), HexPrefix::Add, 1);
159  {
160  if (mapEmpty || _map.at(a.first).hasStorage())
161  {
162  json_spirit::mObject store;
163  for (auto const& s: _state.storage(a.first))
164  store[toCompactHex(s.second.first, HexPrefix::Add, 1)] = toCompactHex(s.second.second, HexPrefix::Add, 1);
165  o["storage"] = store;
166  }
167  }
168 
169  if (mapEmpty || _map.at(a.first).hasCode())
170  o["code"] = toHex(_state.code(a.first), 2, HexPrefix::Add);
171  oState[toString(a.first)] = o;
172  }
173  return oState;
174 }
175 
177 {
179  if (_logs.size() == 0) return ret;
180  for (LogEntry const& l: _logs)
181  {
183  o["address"] = toString(l.address);
184  json_spirit::mArray topics;
185  for (auto const& t: l.topics)
186  topics.push_back(toString(t));
187  o["topics"] = topics;
188  o["data"] = toHex(l.data, 2, HexPrefix::Add);
189  o["bloom"] = toString(l.bloom());
190  ret.push_back(o);
191  }
192  return ret;
193 }
194 
196 {
197  switch (_v.type())
198  {
199  case json_spirit::str_type: return u256(_v.get_str());
200  case json_spirit::int_type: return (u256)_v.get_uint64();
201  case json_spirit::bool_type: return (u256)(uint64_t)_v.get_bool();
202  case json_spirit::real_type: return (u256)(uint64_t)_v.get_real();
203  default: cwarn << "Bad type for scalar: " << _v.type();
204  }
205  return 0;
206 }
207 
209 {
210  switch (_v.type())
211  {
212  case json_spirit::str_type: return (byte)stoi(_v.get_str());
213  case json_spirit::int_type: return (byte)_v.get_uint64();
214  case json_spirit::bool_type: return (byte)_v.get_bool();
215  case json_spirit::real_type: return (byte)_v.get_real();
216  default: cwarn << "Bad type for scalar: " << _v.type();
217  }
218  return 0;
219 }
220 
221 bytes importByteArray(std::string const& _str)
222 {
223  return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str, WhenError::Throw);
224 }
225 
227 {
228  bytes data;
229  if (_o.at("data").type() == json_spirit::str_type)
230  data = importByteArray(_o.at("data").get_str());
231  else
232  for (auto const& j: _o.at("data").get_array())
233  data.push_back(toByte(j));
234  return data;
235 }
236 
238 {
239  for (auto& account: _o.count("alloc") ? _o["alloc"].get_obj() : _o.count("accounts") ? _o["accounts"].get_obj() : _o)
240  {
241  auto obj = account.second.get_obj();
242  if (obj.count("code") && obj["code"].type() == json_spirit::str_type)
243  {
244  string code = obj["code"].get_str();
245  obj["code"] = compileLLL(code);
246  }
247  account.second = obj;
248  }
249 }
250 
251 string compileLLL(string const& _code)
252 {
253  if (_code == "")
254  return "0x";
255  if (_code.substr(0,2) == "0x" && _code.size() >= 2)
256  return _code;
257 
258 #if defined(_WIN32)
259  BOOST_ERROR("LLL compilation only supported on posix systems.");
260  return "";
261 #else
262  char input[1024];
263  boost::filesystem::path path(boost::filesystem::temp_directory_path() / boost::filesystem::unique_path());
264  string cmd = string("lllc ") + path.string();
265  writeFile(path.string(), _code);
266 
267  FILE *fp = popen(cmd.c_str(), "r");
268  if (fp == NULL)
269  BOOST_ERROR("Failed to run lllc");
270  if (fgets(input, sizeof(input) - 1, fp) == NULL)
271  BOOST_ERROR("Reading empty file for lllc");
272  pclose(fp);
273 
274  boost::filesystem::remove(path);
275  string result(input);
276  result = "0x" + boost::trim_copy(result);
277  return result;
278 #endif
279 }
280 
282 {
283  bytes code;
284  if (_o["code"].type() == json_spirit::str_type)
285  if (_o["code"].get_str().find("0x") != 0)
286  code = fromHex(compileLLL(_o["code"].get_str()));
287  else
288  code = fromHex(_o["code"].get_str().substr(2));
289  else if (_o["code"].type() == json_spirit::array_type)
290  {
291  code.clear();
292  for (auto const& j: _o["code"].get_array())
293  code.push_back(toByte(j));
294  }
295  return code;
296 }
297 
299 {
300  LogEntries logEntries;
301  for (auto const& l: _a)
302  {
303  json_spirit::mObject o = l.get_obj();
304  BOOST_REQUIRE(o.count("address") > 0);
305  BOOST_REQUIRE(o.count("topics") > 0);
306  BOOST_REQUIRE(o.count("data") > 0);
307  BOOST_REQUIRE(o.count("bloom") > 0);
308  LogEntry log;
309  log.address = Address(o["address"].get_str());
310  for (auto const& t: o["topics"].get_array())
311  log.topics.push_back(h256(t.get_str()));
312  log.data = importData(o);
313  logEntries.push_back(log);
314  }
315  return logEntries;
316 }
317 
319 {
320  int j = 0;
321  auto expectedOutput = _o["out"].get_str();
322 
323  if (expectedOutput.find("#") == 0)
324  BOOST_CHECK(_output.size() == toInt(expectedOutput.substr(1)));
325  else if (_o["out"].type() == json_spirit::array_type)
326  for (auto const& d: _o["out"].get_array())
327  {
328  BOOST_CHECK_MESSAGE(_output[j] == toInt(d), "Output byte [" << j << "] different!");
329  ++j;
330  }
331  else if (expectedOutput.find("0x") == 0)
332  BOOST_CHECK(_output.contentsEqual(fromHex(expectedOutput.substr(2))));
333  else
334  BOOST_CHECK(_output.contentsEqual(fromHex(expectedOutput)));
335 }
336 
337 void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _resultStore, Address _expectedAddr)
338 {
339  _expectedAddr = _expectedAddr; //unsed parametr when macro
340  for (auto&& expectedStorePair : _expectedStore)
341  {
342  auto& expectedStoreKey = expectedStorePair.first;
343  auto resultStoreIt = _resultStore.find(expectedStoreKey);
344  if (resultStoreIt == _resultStore.end())
345  BOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey);
346  else
347  {
348  auto& expectedStoreValue = expectedStorePair.second;
349  auto& resultStoreValue = resultStoreIt->second;
350  BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
351  }
352  }
353  BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size());
354  for (auto&& resultStorePair: _resultStore)
355  {
356  if (!_expectedStore.count(resultStorePair.first))
357  BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first);
358  }
359 }
360 
361 void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs)
362 {
363  BOOST_REQUIRE_EQUAL(_resultLogs.size(), _expectedLogs.size());
364 
365  for (size_t i = 0; i < _resultLogs.size(); ++i)
366  {
367  BOOST_CHECK_EQUAL(_resultLogs[i].address, _expectedLogs[i].address);
368  BOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics);
369  BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data);
370  }
371 }
372 
373 void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates)
374 {
375  BOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size());
376 
377  for (size_t i = 0; i < _resultCallCreates.size(); ++i)
378  {
379  BOOST_CHECK(_resultCallCreates[i].data() == _expectedCallCreates[i].data());
380  BOOST_CHECK(_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress());
381  BOOST_CHECK(_resultCallCreates[i].gas() == _expectedCallCreates[i].gas());
382  BOOST_CHECK(_resultCallCreates[i].value() == _expectedCallCreates[i].value());
383  }
384 }
385 
387 {
388  if (!Options::get().singleTest)
389  return;
390 
391  if (Options::get().singleTestFile.empty() || Options::get().singleTestName.empty())
392  {
393  cnote << "Missing user test specification\nUsage: testeth --singletest <filename> <testname>\n";
394  return;
395  }
396 
397  auto& filename = Options::get().singleTestFile;
398  auto& testname = Options::get().singleTestName;
399 
400  if (g_logVerbosity != -1)
401  VerbosityHolder sentinel(12);
402 
403  try
404  {
405  cnote << "Testing user defined test: " << filename;
407  string s = contentsString(filename);
408  BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
410  json_spirit::mObject oSingleTest;
411 
412  json_spirit::mObject::const_iterator pos = v.get_obj().find(testname);
413  if (pos == v.get_obj().end())
414  {
415  cnote << "Could not find test: " << testname << " in " << filename << "\n";
416  return;
417  }
418  else
419  oSingleTest[pos->first] = pos->second;
420 
421  json_spirit::mValue v_singleTest(oSingleTest);
422  doTests(v_singleTest, test::Options::get().filltests);
423  }
424  catch (Exception const& _e)
425  {
426  BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
427  }
428  catch (std::exception const& _e)
429  {
430  BOOST_ERROR("Failed Test with Exception: " << _e.what());
431  }
432 }
433 
434 void executeTests(const string& _name, const string& _testPathAppendix, const string& _fillerPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests, bool _addFillerSuffix)
435 {
436  string testPath = getTestPath() + _testPathAppendix;
437  string testFillerPath = getTestPath() + "/src/" + _fillerPathAppendix;
438 
439  if (Options::get().stats)
440  Listener::registerListener(Stats::get());
441 
442  string name = _name;
443  if (_name.rfind("Filler.json") != std::string::npos)
444  name = _name.substr(0, _name.rfind("Filler.json"));
445 
446  if (Options::get().filltests)
447  {
448  try
449  {
450  cnote << "Populating tests...";
452  boost::filesystem::path p(__FILE__);
453 
454  string nameEnding = _addFillerSuffix ? "Filler.json" : ".json";
455  string testfilename = testFillerPath + "/" + name + nameEnding;
456  string s = asString(dev::contents(testfilename));
457  BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testfilename + " is empty.");
458 
460  doTests(v, true);
461  writeFile(testPath + "/" + name + ".json", asBytes(json_spirit::write_string(v, true)));
462  }
463  catch (Exception const& _e)
464  {
465  BOOST_ERROR(TestOutputHelper::testName() + "Failed filling test with Exception: " << diagnostic_information(_e));
466  }
467  catch (std::exception const& _e)
468  {
469  BOOST_ERROR(TestOutputHelper::testName() + "Failed filling test with Exception: " << _e.what());
470  }
471  }
472  try
473  {
474  cnote << "TEST " << name << ":";
476  string s = asString(dev::contents(testPath + "/" + name + ".json"));
477  BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testPath + "/" + name + ".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
479  Listener::notifySuiteStarted(name);
480  doTests(v, false);
481  }
482  catch (Exception const& _e)
483  {
484  BOOST_ERROR(TestOutputHelper::testName() + "Failed test with Exception: " << diagnostic_information(_e));
485  }
486  catch (std::exception const& _e)
487  {
488  BOOST_ERROR(TestOutputHelper::testName() + "Failed test with Exception: " << _e.what());
489  }
490 }
491 
492 void copyFile(std::string const& _source, std::string const& _destination)
493 {
494  std::ifstream src(_source, std::ios::binary);
495  std::ofstream dst(_destination, std::ios::binary);
496  dst << src.rdbuf();
497 }
498 
500 {
501  //Construct Rlp of the given transaction
502  RLPStream rlpStream;
503  rlpStream.appendList(_tObj.size());
504 
505  if (_tObj.count("nonce"))
506  rlpStream << bigint(_tObj.at("nonce").get_str());
507 
508  if (_tObj.count("gasPrice"))
509  rlpStream << bigint(_tObj.at("gasPrice").get_str());
510 
511  if (_tObj.count("gasLimit"))
512  rlpStream << bigint(_tObj.at("gasLimit").get_str());
513 
514  if (_tObj.count("to"))
515  {
516  if (_tObj.at("to").get_str().empty())
517  rlpStream << "";
518  else
519  rlpStream << importByteArray(_tObj.at("to").get_str());
520  }
521 
522  if (_tObj.count("value"))
523  rlpStream << bigint(_tObj.at("value").get_str());
524 
525  if (_tObj.count("data"))
526  rlpStream << importData(_tObj);
527 
528  if (_tObj.count("v"))
529  rlpStream << bigint(_tObj.at("v").get_str());
530 
531  if (_tObj.count("r"))
532  rlpStream << bigint(_tObj.at("r").get_str());
533 
534  if (_tObj.count("s"))
535  rlpStream << bigint(_tObj.at("s").get_str());
536 
537  if (_tObj.count("extrafield"))
538  rlpStream << bigint(_tObj.at("extrafield").get_str());
539 
540  return rlpStream;
541 }
542 
543 
544 LastHashes lastHashes(u256 _currentBlockNumber)
545 {
546  LastHashes ret;
547  for (u256 i = 1; i <= 256 && i <= _currentBlockNumber; ++i)
548  ret.push_back(sha3(toString(_currentBlockNumber - i)));
549  return ret;
550 }
551 
553  h256 const& _parentHash,
554  h256 const& _sha3Uncles,
555  Address const& _author,
556  h256 const& _stateRoot,
557  h256 const& _transactionsRoot,
558  h256 const& _receiptsRoot,
559  dev::eth::LogBloom const& _logBloom,
560  u256 const& _difficulty,
561  u256 const& _number,
562  u256 const& _gasLimit,
563  u256 const& _gasUsed,
564  u256 const& _timestamp,
565  bytes const& _extraData)
566 {
567  RLPStream rlpStream;
568  rlpStream.appendList(15);
569 
570  rlpStream << _parentHash << _sha3Uncles << _author << _stateRoot << _transactionsRoot << _receiptsRoot << _logBloom
571  << _difficulty << _number << _gasLimit << _gasUsed << _timestamp << _extraData << h256{} << Nonce{};
572 
573  return BlockHeader(rlpStream.out(), HeaderData);
574 }
575 
576 void updateEthashSeal(dev::eth::BlockHeader& _header, h256 const& _mixHash, h64 const& _nonce)
577 {
578  Ethash::setNonce(_header, _nonce);
579  Ethash::setMixHash(_header, _mixHash);
580 }
581 
582 namespace
583 {
584  Listener* g_listener;
585 }
586 
587 void Listener::registerListener(Listener& _listener)
588 {
589  g_listener = &_listener;
590 }
591 
592 void Listener::notifySuiteStarted(std::string const& _name)
593 {
594  if (g_listener)
595  g_listener->suiteStarted(_name);
596 }
597 
598 void Listener::notifyTestStarted(std::string const& _name)
599 {
600  if (g_listener)
601  g_listener->testStarted(_name);
602 }
603 
604 void Listener::notifyTestFinished(int64_t _gasUsed)
605 {
606  if (g_listener)
607  g_listener->testFinished(_gasUsed);
608 }
609 
610 
611 
612 } } // namespaces
const Object & get_obj() const
u256 balance(Address const &_id) const
Get an account&#39;s balance.
Definition: State.cpp:266
std::string toCompactHex(u256 val, HexPrefix prefix=HexPrefix::DontAdd, unsigned _min=0)
Definition: CommonData.h:175
void stopSealing() override
Stop sealing.
Definition: Client.h:161
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Definition: CommonData.h:54
#define function(a, b, c, d, k, s)
A modifiable reference to an existing object or vector in memory.
Definition: vector_ref.h:20
string netIdToString(eth::Network _netId)
Definition: TestHelper.cpp:93
uint8_t byte
Definition: Common.h:57
BlockDetails details(h256 const &_hash) const
Get the familial details concerning a block (or the most recent mined if none given). Thread-safe.
Definition: BlockChain.h:156
bytes importData(json_spirit::mObject const &_o)
Definition: TestHelper.cpp:226
Allows observing test execution process.
Definition: TestHelper.h:174
Implements the blockchain database.
Definition: BlockChain.h:105
Fixture class for boost output when running testeth.
Network
The network id.
Definition: GenesisInfo.h:34
void checkOutput(bytesConstRef _output, json_spirit::mObject &_o)
Definition: TestHelper.cpp:318
Encapsulation of a block header.
Definition: BlockHeader.h:95
void writeFile(std::string const &_file, bytesConstRef _data, bool _writeDeleteRename=false)
Write the given binary data into the given file, replacing the file if it pre-exists.
Definition: CommonIO.cpp:107
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
Definition: Common.h:121
bytes const & out() const
Read the byte stream.
Definition: RLP.h:433
virtual void generateSeal(BlockHeader const &_bi)=0
h160 Address
An Ethereum address: 20 bytes.
Definition: Common.h:62
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:121
boost::uint64_t get_uint64() const
#define c(i)
void connectClients(Client &c1, Client &c2)
Definition: TestHelper.cpp:49
void commitToSeal(BlockChain const &_bc, bytes const &_extraData={})
Prepares the current state for mining.
Definition: Block.cpp:695
std::hash for asio::adress
Definition: Common.h:323
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
int Add(word *C, const word *A, const word *B, size_t N)
Definition: integer.cpp:2143
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
json_spirit::mObject fillJsonWithState(State const &_state, eth::AccountMaskMap const &_map)
Definition: TestHelper.cpp:145
bytes code
Definition: SmartVM.cpp:45
Model of an Ethereum state, essentially a facade for the trie.
Definition: State.h:161
bool contentsEqual(std::vector< mutable_value_type > const &_c) const
Definition: vector_ref.h:43
Class for handling testeth custom options.
SignatureStruct const & signature() const
Definition: Transaction.h:143
json_spirit::mObject fillJsonWithTransaction(Transaction const &_txn)
Definition: TestHelper.cpp:124
void updateEthashSeal(dev::eth::BlockHeader &_header, h256 const &_mixHash, h64 const &_nonce)
Definition: TestHelper.cpp:576
void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs)
Definition: TestHelper.cpp:361
#define a(i)
Active model of a block within the block chain.
Definition: Block.h:73
bool isCreation() const
Definition: Transaction.h:101
Value_type type() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
std::vector< h256 > LastHashes
Definition: ExtVMFace.h:191
bool read_string(const String_type &s, Value_type &value)
Base class for all exceptions.
Definition: Exceptions.h:39
void userDefinedTest(std::function< void(json_spirit::mValue &, bool)> doTests)
Definition: TestHelper.cpp:386
mConfig::Array_type mArray
dev::eth::BlockHeader constructHeader(h256 const &_parentHash, h256 const &_sha3Uncles, Address const &_author, h256 const &_stateRoot, h256 const &_transactionsRoot, h256 const &_receiptsRoot, dev::eth::LogBloom const &_logBloom, u256 const &_difficulty, u256 const &_number, u256 const &_gasLimit, u256 const &_gasUsed, u256 const &_timestamp, bytes const &_extraData)
Definition: TestHelper.cpp:552
BlockChain const & blockChain() const
Get the object representing the current canonical blockchain.
Definition: Client.h:125
byte toByte(json_spirit::mValue const &_v)
Definition: TestHelper.cpp:208
const char * name
Definition: rest.cpp:36
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject const &_tObj)
Definition: TestHelper.cpp:499
virtual void onSealGenerated(std::function< void(bytes const &s)> const &_f)=0
bytes const & extraData() const
Definition: BlockHeader.h:164
json_spirit::mArray exportLog(eth::LogEntries _logs)
Definition: TestHelper.cpp:176
std::vector< byte > bytes
Definition: Common.h:75
std::string getTestPath()
Definition: Common.cpp:35
u256 storage(Address const &_contract, u256 const &_memory) const
Get the value of a storage position of an account.
Definition: State.cpp:353
u256 getNonce(Address const &_addr) const
Get the account nonce – the number of transactions it has sent.
Definition: State.cpp:345
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
RLPStream & appendList(size_t _items)
Appends a list.
Definition: RLP.cpp:276
Main API hub for interfacing with Ethereum.
Definition: Client.h:75
bytes const & data() const
Definition: Transaction.h:131
std::unordered_map< Address, u256 > addresses() const
Definition: State.cpp:220
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string&#39;s (byte) data.
Definition: CommonData.h:92
bytes const & code(Address const &_addr) const
Get the code of an account.
Definition: State.cpp:423
FixedHash< 32 > h256
Definition: FixedHash.h:340
#define cwarn
Definition: Log.h:304
const String_type & get_str() const
void checkStorage(map< u256, u256 > _expectedStore, map< u256, u256 > _resultStore, Address _expectedAddr)
Definition: TestHelper.cpp:337
bool sealBlock(bytes const &_header)
Pass in a properly sealed header matching this block.
Definition: Block.h:268
void waitNot(N const &_v) const
Definition: Guards.h:97
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
bytes importCode(json_spirit::mObject &_o)
Definition: TestHelper.cpp:281
void copyFile(std::string const &_source, std::string const &_destination)
Definition: TestHelper.cpp:492
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:84
Temporary changes system&#39;s verbosity for specific function.
Definition: Log.h:80
std::unordered_map< Address, AccountMask > AccountMaskMap
Definition: Account.h:240
size_t size() const
Definition: vector_ref.h:55
mConfig::Object_type mObject
int g_logVerbosity
The logging system&#39;s current verbosity.
Definition: Log.cpp:37
void replaceLLLinState(json_spirit::mObject &_o)
Definition: TestHelper.cpp:237
Value_type::String_type write_string(const Value_type &value, bool pretty)
#define cnote
Definition: Log.h:303
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
LastHashes lastHashes(u256 _currentBlockNumber)
Definition: TestHelper.cpp:544
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Definition: SHA3.cpp:214
string compileLLL(string const &_code)
Definition: TestHelper.cpp:251
void mine(BlockHeader &_bi, SealEngineFace *_sealer, bool _verify)
Definition: TestHelper.cpp:74
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
#define d(i)
Definition: sha.cpp:732
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
bytes importByteArray(std::string const &_str)
Definition: TestHelper.cpp:221
void startSealing() override
Start sealing.
Definition: Client.cpp:583
void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates)
Definition: TestHelper.cpp:373
virtual void suiteStarted(std::string const &)
Definition: TestHelper.h:179
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Class for writing to an RLP bytestream.
Definition: RLP.h:383
bytes contents(std::string const &_file)
Retrieve and returns the contents of the given file.
eth::Network stringToNetId(string const &_netname)
Definition: TestHelper.cpp:107
uint8_t const * data
Definition: sha3.h:19
LogEntries importLog(json_spirit::mArray &_a)
Definition: TestHelper.cpp:298
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Definition: CommonData.h:79
virtual void verify(Strictness _s, BlockHeader const &_bi, BlockHeader const &_parent=BlockHeader(), bytesConstRef _block=bytesConstRef()) const
Don&#39;t forget to call Super::verify when subclassing & overriding.
Definition: SealEngine.cpp:36
u256 toInt(json_spirit::mValue const &_v)
Definition: TestHelper.cpp:195
BlockHeader const & info() const
Get the header information on the present block.
Definition: Block.h:279
std::vector< LogEntry > LogEntries
Definition: ExtVMFace.h:110
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)
Definition: object.cpp:17
Address receiveAddress() const
Definition: Transaction.h:122
Definition: ExtVMFace.h:88