35 m_testType(testTemplate)
60 m_logs = out.second.second.log();
61 return out.second.first.output;
65 vector<eth::Network> networks;
80 vector<transactionToExecute> transactionResults;
81 for (
size_t j = 0; j < networks.size(); j++)
105 testObj[
"genesisBlockHeader"] = genesisObj;
112 vector<size_t> stateIndexesToPrint;
116 for (
auto const& exp:
m_testObject[
"expect"].get_array())
120 if (search.second.first.addresses().size() != 0)
128 if (adr.second.get_obj().count(
"balance"))
130 u256 expectCoinbaseBalance =
toInt(adr.second.get_obj()[
"balance"]);
131 expectCoinbaseBalance +=
u256(
"5000000000000000000");
136 testObj[
"expect"] = obj;
145 rewriteHeader[
"updatePoW"] =
"1";
151 blocksObj[
"blockHeaderPremine"] = rewriteHeader;
152 blocksObj[
"transactions"] = transcArr;
154 blocksArr.push_back(blocksObj);
155 testObj[
"blocks"] = blocksArr;
156 json[testname] = testObj;
174 BOOST_ERROR(
"Error when executing test ImportTest::executeTest()");
184 bool removeEmptyAccounts =
m_envInfo.
number() >= se->chainParams().u256Param(
"EIP158ForkBlock");
186 initialState.
commit(removeEmptyAccounts ? State::CommitBehaviour::RemoveEmptyAccounts : State::CommitBehaviour::KeepEmptyAccounts);
187 return std::pair<eth::State, ImportTest::execOutput>(initialState, execOut);
191 cnote <<
"Exception: " << diagnostic_information(_e);
193 catch (std::exception
const& _e)
195 cnote <<
"state execution exception: " << _e.what();
198 initialState.
commit(State::CommitBehaviour::KeepEmptyAccounts);
202 return std::pair<eth::State, ImportTest::execOutput>(initialState, execOut);
207 static const set<string> hashes {
"bloom" ,
"coinbase",
"hash",
"mixHash",
"parentHash",
"receiptTrie",
208 "stateRoot",
"transactionsTrie",
"uncleHash",
"currentCoinbase",
209 "previousHash",
"to",
"address",
"caller",
"origin",
"secretKey",
"data"};
213 std::string key = i.first;
214 if (hashes.count(key))
233 BOOST_REQUIRE(_o.count(
"currentGasLimit") > 0);
234 BOOST_REQUIRE(_o.count(
"currentDifficulty") > 0);
235 BOOST_REQUIRE(_o.count(
"currentNumber") > 0);
236 BOOST_REQUIRE(_o.count(
"currentTimestamp") > 0);
237 BOOST_REQUIRE(_o.count(
"currentCoinbase") > 0);
238 auto gasLimit =
toInt(_o[
"currentGasLimit"]);
262 for (
auto const& i: mask)
264 if (!i.second.allSet())
270 if (_o.count(
"secretKey") > 0)
272 BOOST_REQUIRE(_o.count(
"nonce") > 0);
273 BOOST_REQUIRE(_o.count(
"gasPrice") > 0);
274 BOOST_REQUIRE(_o.count(
"gasLimit") > 0);
275 BOOST_REQUIRE(_o.count(
"to") > 0);
276 BOOST_REQUIRE(_o.count(
"value") > 0);
277 BOOST_REQUIRE(_o.count(
"data") > 0);
288 o_tr = _o.at(
"to").get_str().empty() ?
294 BOOST_REQUIRE(_o.count(
"nonce"));
295 BOOST_REQUIRE(_o.count(
"gasPrice"));
296 BOOST_REQUIRE(_o.count(
"gasLimit"));
297 BOOST_REQUIRE(_o.count(
"to"));
298 BOOST_REQUIRE(_o.count(
"value"));
299 BOOST_REQUIRE(_o.count(
"data"));
300 BOOST_REQUIRE(_o.count(
"v"));
301 BOOST_REQUIRE(_o.count(
"r"));
302 BOOST_REQUIRE(_o.count(
"s"));
305 RLP transactionRLP(transactionRLPStream.out());
308 o_tr =
Transaction(transactionRLP.data(), CheckTransaction::Everything);
313 o_tr = _o.at(
"to").get_str().empty() ?
319 cnote <<
"invalid transaction" << boost::diagnostic_information(_e);
330 BOOST_REQUIRE(o_tr.count(
"gasLimit") > 0);
331 size_t dataVectorSize = o_tr.at(
"data").get_array().size();
332 size_t gasVectorSize = o_tr.at(
"gasLimit").get_array().size();
333 size_t valueVectorSize = o_tr.at(
"value").get_array().size();
335 for (
size_t d = 0;
d < dataVectorSize;
d++)
336 for (
size_t g = 0;
g < gasVectorSize;
g++)
337 for (
size_t v = 0; v < valueVectorSize; v++)
344 o_tr_tmp[
"data"] =
data;
345 o_tr_tmp[
"gasLimit"] = gas;
346 o_tr_tmp[
"value"] = value;
358 bool wasError =
false;
361 if (_throw == WhenError::Throw) \ 363 BOOST_CHECK_MESSAGE(a, b); \ 369 BOOST_WARN_MESSAGE(a,b); \ 378 if(_expectedStateOptions.size())
382 addressOptions = _expectedStateOptions.at(
a.first);
384 catch(std::out_of_range
const&)
413 map<h256, pair<u256, u256>> stateStorage = _statePost.
storage(
a.first);
414 for (
auto const& s: _stateExpect.
storage(
a.first))
415 CHECK((stateStorage[s.first] == s.second),
419 map<h256, pair<u256, u256>> expectedStorage = _stateExpect.
storage(
a.first);
420 for (
auto const& s: _statePost.
storage(
a.first))
421 CHECK((expectedStorage[s.first] == s.second),
439 _out.push_back(val.get_str());
442 _out.push_back(_json.
get_str());
450 _out.push_back(val.get_int());
453 _out.push_back(_json.
get_int());
457 bool inArray(vector<T>
const& _array,
const T _val)
459 for (
size_t i = 0; i < _array.size(); i++)
460 if (_array[i] == _val)
475 vector<string> network;
476 if (_network.empty())
479 network.push_back(_network);
484 for(
size_t i=0; i<network.size(); i++)
487 if (_expects.count(
"indexes"))
498 bool foundResults =
false;
499 std::vector<transactionToExecute> lookTransactions;
501 lookTransactions.push_back(_search->first);
504 for(
size_t i = 0; i < lookTransactions.size(); i++)
511 if (_expects.count(
"result"))
523 importState(_expects.at(
"result").get_obj(), expectState, stateMap);
526 _search->second.first = expectState;
527 _search->second.second = stateMap;
533 cerr << trInfo << std::endl;
534 _errorTransactions.push_back(i);
537 else if (_expects.count(
"hash"))
545 if (network[0] !=
"ALL" && d[0] != -1 && g[0] != -1 && v[0] != -1)
546 if (network.size() == 1 && d.size() == 1 && g.size() == 1 && v.size() == 1)
559 vector<size_t> stateIndexesToPrint;
562 for (
auto const& exp:
m_testObject[
"expect"].get_array())
568 std::map<string, json_spirit::mArray> postState;
576 obj2[
"indexes"] = obj;
578 if (stateIndexesToPrint.size())
588 for(std::map<string, json_spirit::mArray>::iterator it = postState.begin(); it != postState.end(); ++it)
589 obj[it->first] = it->second;
602 std::string warning =
"Check State: Error! Unexpected output: " +
m_testObject[
"out"].get_str() +
" Expected: " +
m_testObject[
"expectOut"].get_str();
606 BOOST_CHECK_MESSAGE(statement, warning);
637 m_testObject[
"transaction"] =
makeAllFieldsHex(m_testObject[
"transaction"].get_obj());
bool addressInUse(Address const &_address) const
Check if the address is in use.
u256 balance(Address const &_id) const
Get an account's balance.
std::string toCompactHex(u256 val, HexPrefix prefix=HexPrefix::DontAdd, unsigned _min=0)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Helper class for managing data when running state tests.
string netIdToString(eth::Network _netId)
bytes importData(json_spirit::mObject const &_o)
void commit(CommitBehaviour _commitBehaviour)
Commit all changes waiting in the address cache to the DB.
u256 const & timestamp() const
Homestead + EIP150 Rules active from block 0 For BlockchainTests.
static Options const & get(int argc=0, char **argv=0)
Get reference to options The first time used, options are parsed with argc, argv. ...
Fixture class for boost output when running testeth.
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.
std::pair< transactionToExecute, StateAndMap > TrExpectSection
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
static std::string const & testName()
h160 Address
An Ethereum address: 20 bytes.
Address const & author() const
SecureFixedHash< 32 > Secret
std::pair< eth::ExecutionResult, eth::TransactionReceipt > execOutput
int trValueIndex
GeneralState value.
std::hash for asio::adress
void setGasLimit(int64_t _v)
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
ImportTest(json_spirit::mObject &_o, bool isFiller, testType testTemplate=testType::StateTests)
Description of the result of executing a transaction.
u256 const & number() const
Model of an Ethereum state, essentially a facade for the trie.
void populateFrom(AccountMap const &_map)
Populate the state from the given AccountMap. Just uses dev::eth::commit().
Homestead + EIP150 + EIP158 Rules active from block 0.
static std::string const & caseName()
Class for handling testeth custom options.
void checkGeneralTestSection(json_spirit::mObject const &_expects, std::vector< size_t > &_errorTransactions, std::string const &_network="") const
const Array & get_array() const
json_spirit::mObject fillJsonWithTransaction(Transaction const &_txn)
static int compareStates(eth::State const &_stateExpect, eth::State const &_statePost, eth::AccountMaskMap const _expectedStateOptions=eth::AccountMaskMap(), WhenError _throw=WhenError::Throw)
static void importState(json_spirit::mObject const &_o, eth::State &_state)
Base class for all exceptions.
mConfig::Array_type mArray
std::pair< ExecutionResult, TransactionReceipt > execute(EnvInfo const &_envInfo, SealEngineFace const &_sealEngine, Transaction const &_t, Permanence _p=Permanence::Committed, OnOpFunc const &_onOp=OnOpFunc())
Execute a given transaction.
void parseJsonIntValueIntoVector(json_spirit::mValue const &_json, vector< int > &_out)
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject const &_tObj)
eth::Transaction m_transaction
json_spirit::mArray exportLog(eth::LogEntries _logs)
void setLastHashes(LastHashes &&_lh)
void setTimestamp(u256 const &_v)
std::vector< byte > bytes
std::string getTestPath()
Just test the Homestead-era characteristics "forever" (no Frontier portion).
json_spirit::mObject & m_testObject
u256 storage(Address const &_contract, u256 const &_memory) const
Get the value of a storage position of an account.
u256 getNonce(Address const &_addr) const
Get the account nonce – the number of transactions it has sent.
u256 const & difficulty() const
std::unordered_map< Address, u256 > addresses() const
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
std::pair< eth::State, eth::AccountMaskMap > StateAndMap
void setNumber(u256 const &_v)
bytes const & code(Address const &_addr) const
Get the code of an account.
json_spirit::mObject fillJsonWithState(State const &_state)
const String_type & get_str() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
bool checkstate
Throw error when checking test states.
Just test the Frontier-era characteristics "forever" (no Homestead portion).
Encodes a transaction, ready to be exported to or freshly imported from RLP.
std::unordered_map< Address, AccountMask > AccountMaskMap
int trGasIndex
GeneralState gas.
mConfig::Object_type mObject
h256 rootHash() const
The hash of the root of our state tree.
void replaceLLLinState(json_spirit::mObject &_o)
std::string const & genesisInfo(Network _n)
Value_type::String_type write_string(const Value_type &value, bool pretty)
int trDataIndex
GeneralState data.
static json_spirit::mObject defaultGenesisBlockJson()
void importEnv(json_spirit::mObject &_o)
void parseJsonStrValueIntoVector(json_spirit::mValue const &_json, vector< string > &_out)
LastHashes lastHashes(u256 _currentBlockNumber)
AccountMap jsonToAccountMap(std::string const &_json, u256 const &_defaultNonce=0, AccountMaskMap *o_mask=nullptr, PrecompiledContractMap *o_precompiled=nullptr)
std::vector< transactionToExecute > m_transactions
boost::error_info< struct tag_comment, std::string > errinfo_comment
int exportTest(bytes const &_output)
void setAuthor(Address const &_v)
All fork rules + Metropolis active from block 0.
bool inArray(vector< T > const &_array, const T _val)
void doBlockchainTests(json_spirit::mValue &_v, bool _fillin)
void executeTests(const string &_name, const string &_testPathAppendix, const string &_fillerPathAppendix, std::function< void(json_spirit::mValue &, bool)> doTests, bool _addFillerSuffix)
eth::LogEntries m_logsExpected
void setDifficulty(u256 const &_v)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
static void importTransaction(json_spirit::mObject const &_o, eth::Transaction &o_tr)
Class for writing to an RLP bytestream.
eth::Network stringToNetId(string const &_netname)
bool fulloutput
Replace large output to just it's length.
Class for interpreting Recursive Linear-Prefix Data.
static json_spirit::mObject & makeAllFieldsHex(json_spirit::mObject &_o)
LogEntries importLog(json_spirit::mArray &_a)
void checkGeneralTestSectionSearch(json_spirit::mObject const &_expects, std::vector< size_t > &_errorTransactions, std::string const &_network="", TrExpectSection *_search=NULL) const
Normal Frontier/Homestead/DAO/EIP150/EIP158/Metropolis chain.
u256 toInt(json_spirit::mValue const &_v)
bigint const c_max256plus1
std::vector< LogEntry > LogEntries
Helper functions to work with json::spirit and test files.
std::pair< eth::State, execOutput > executeTransaction(eth::Network const _sealEngineNetwork, eth::EnvInfo const &_env, eth::State const &_preState, eth::Transaction const &_tr)