42 namespace dev {
namespace test {
45 std::string testSuite;
46 std::string testFillString;
48 bool checktest =
false;
49 bool filldebug =
false;
51 bool filltest =
false;
56 if (testSuite !=
"BlockChainTests" && testSuite !=
"TransactionTests" && testSuite !=
"StateTests" 57 && testSuite !=
"VMTests")
60 for (
size_t i = 0; i < _parameters.size(); ++i)
62 auto arg = std::string{_parameters.at(i)};
64 if (arg ==
"--fulloutput")
67 if (arg ==
"--checktest" || arg ==
"--filltest")
70 BOOST_REQUIRE_MESSAGE(s.length() > 0,
"Error! Content of argument is empty! (Usage -checktest textstream)");
72 if (arg ==
"--filltest")
79 if (s.find(
".json") != std::string::npos)
81 boost::filesystem::path p(__FILE__);
92 if (arg ==
"--filldebug")
98 std::cerr <<
"Error! Test suite not supported! (Usage -t TestSuite)" << std::endl;
104 std::cout <<
"Testing: " << testSuite.substr(0, testSuite.length() - 1) <<
"... ";
106 if (testSuite ==
"BlockChainTests")
114 if (testSuite ==
"TransactionTests")
122 if (testSuite ==
"VMTests")
144 std::ostringstream strCout;
148 std::cout.rdbuf( strCout.rdbuf() );
149 std::cerr.rdbuf( strCout.rdbuf() );
152 _doTests(_value,
false);
157 std::cout.rdbuf(oldCoutStreamBuf);
158 std::cerr.rdbuf(oldCoutStreamBuf);
163 std::cout <<
"Failed test with Exception: " << diagnostic_information(_e) << std::endl;
166 catch (std::exception
const& _e)
168 std::cout <<
"Failed test with Exception: " << _e.what() << std::endl;
177 std::ostringstream strCout;
181 std::cout.rdbuf( strCout.rdbuf() );
182 std::cerr.rdbuf( strCout.rdbuf() );
188 std::string newTest = _testString;
189 std::map<std::string, std::string> nullReplaceMap;
196 std::cerr <<
"Test fill exception!";
202 std::cout.rdbuf(oldCoutStreamBuf);
203 std::cerr.rdbuf(oldCoutStreamBuf);
228 std::vector<std::string> types = getTypes();
230 for (std::map<std::string, std::string>::const_iterator it = _varMap.begin(); it != _varMap.end(); it++)
231 types.push_back(it->first);
233 for (
unsigned i = 0; i < types.size(); i++)
235 std::size_t pos = _test.find(types.at(i));
236 while (pos != std::string::npos)
238 if (types.at(i) ==
"[RLP]")
246 if (types.at(i) ==
"[CODE]")
249 if (types.at(i) ==
"[HEX]")
252 if (types.at(i) ==
"[HEX32]")
255 if (types.at(i) ==
"[GASLIMIT]")
258 if (types.at(i) ==
"[HASH20]")
261 if (types.at(i) ==
"[0xHASH32]")
264 if (types.at(i) ==
"[HASH32]")
267 if (types.at(i) ==
"[V]")
271 _test.replace(pos, 3,
"0x1c");
274 _test.replace(pos, 3,
"0x1d");
279 _test.replace(pos, types.at(i).size(), _varMap.at(types.at(i)));
281 pos = _test.find(types.at(i));
288 return {
"[RLP]",
"[CODE]",
"[HEX]",
"[HEX32]",
"[HASH20]",
"[HASH32]",
"[0xHASH32]",
"[V]",
"[GASLIMIT]"};
293 "randomTransactionTest" : { 297 "gasLimit" : "[HEX]", 298 "gasPrice" : "[HEX]", 312 "randomStatetest" : { 314 "currentCoinbase" : "[HASH20]", 315 "currentDifficulty" : "[HEX]", 316 "currentGasLimit" : "[GASLIMIT]", 317 "currentNumber" : "[HEX32]", 318 "currentTimestamp" : "[HEX]", 319 "previousHash" : "[HASH32]" 322 "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { 329 "945304eb96065b2a98b57a48a06ae28d285a71b5" : { 336 "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { 346 "gasLimit" : "[HEX]", 347 "gasPrice" : "[HEX32]", 349 "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", 350 "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", 361 "previousHash" : "[HASH32]", 362 "currentNumber" : "[HEX]", 363 "currentGasLimit" : "[GASLIMIT]", 364 "currentDifficulty" : "[HEX]", 365 "currentTimestamp" : "[HEX]", 366 "currentCoinbase" : "[HASH20]" 369 "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { 377 "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", 378 "origin" : "[HASH20]", 379 "caller" : "[HASH20]", 399 "randomBlockTest" : { 400 "genesisBlockHeader" : { 401 "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 402 "coinbase" : "[HASH20]", 403 "difficulty" : "131072", 404 "extraData" : "[CODE]", 405 "gasLimit" : "4712388", 407 "mixHash" : "[0xHASH32]", 408 "nonce" : "0x0102030405060708", 410 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 411 "receiptTrie" : "[0xHASH32]", 412 "stateRoot" : "[0xHASH32]", 413 "timestamp" : "[HEX]", 414 "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", 415 "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" 418 "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { 424 "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { 436 "gasLimit" : "[HEX]", 439 "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", 440 "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", std::string const c_testExampleBlockchainTest
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string const c_testExampleTransactionTest
#define function(a, b, c, d, k, s)
static Options const & get(int argc=0, char **argv=0)
Get reference to options The first time used, options are parsed with argc, argv. ...
static void setKind(VMKind _kind)
Set global VM kind.
EXPORT void debug(uint64_t a, uint64_t b, uint64_t c, uint64_t d, char z)
static std::vector< std::string > getTypes()
std::string const c_testExampleStateTest
void addAddress(dev::Address const &_address)
std::string rCurrentTestSuite
Remember test suite before boost overwrite (for random tests)
bool read_string(const String_type &s, Value_type &value)
Base class for all exceptions.
static std::string rndRLPSequence(int _depth, std::string &_debug)
Generate random rlp byte sequence of a given depth (e.g [[[]],[]]).
void doTransactionTests(json_spirit::mValue &_v, bool _fillin)
void setWeight(dev::eth::Instruction _opCode, int _weight)
std::string const c_testExampleRLPTest
message-call with another account's code only
std::string rCheckTest
Test Input (for random tests)
static void parseTestWithTypes(std::string &_test, std::map< std::string, std::string > const &_varMap)
Replace keywords in given string with values.
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
std::string const c_testExampleVMTest
void fillRandomTest(std::function< void(json_spirit::mValue &, bool)> _doTests, std::string const &_testString, bool _debug=false)
void doVMTests(json_spirit::mValue &_v, bool _fillin)
int checkRandomTest(std::function< void(json_spirit::mValue &, bool)> _doTests, json_spirit::mValue &_value, bool _debug=false)
std::streambuf * oldCoutStreamBuf
Value_type::String_type write_string(const Value_type &value, bool pretty)
static u256 randomUniInt(u256 _maxVal=0)
static std::string rndByteSequence(int _length=1, SizeStrictness _sizeType=SizeStrictness::Strict)
Generate random byte string of a given length.
static std::string randomUniIntHex(u256 _maxVal=0)
Generate random int64.
static std::string generate(int _maxOpNumber=1, RandomCodeOptions _options=RandomCodeOptions())
Generate random vm code.
message-call into an account
void doBlockchainTests(json_spirit::mValue &_v, bool _fillin)
int createRandomTest(std::vector< char * > const &_parameters)
bytes contents(std::string const &_file)
Retrieve and returns the contents of the given file.
bool fulloutput
Replace large output to just it's length.
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Helper functions to work with json::spirit and test files.