35 namespace dev {
namespace test {
39 TestOutputHelper::initTest(_v);
43 string testname = i.first;
46 if (!TestOutputHelper::passTest(o, testname))
49 BOOST_REQUIRE(o.count(
"blocknumber") > 0);
56 BOOST_REQUIRE(o.count(
"transaction") > 0);
57 mObject tObj = o[
"transaction"].get_obj();
65 Transaction txFromFields(rlpStream.
out(), CheckTransaction::Everything);
66 if (!txFromFields.signature().isValid())
68 se->verifyTransaction(ImportRequirements::Everything, txFromFields, bh);
70 if (o.count(
"sender") > 0)
73 BOOST_CHECK_MESSAGE(
toString(txFromFields.sender()) == expectSender,
"Error filling transaction test " + TestOutputHelper::testName() +
": expected another sender address! (got: " +
toString(txFromFields.sender()) +
"), expected: (" + expectSender +
")");
75 o[
"sender"] =
toString(txFromFields.sender());
76 o[
"transaction"] = ImportTest::makeAllFieldsHex(tObj);
77 o[
"hash"] =
toString(txFromFields.sha3());
82 cnote <<
"Transaction Exception: " << diagnostic_information(_e);
83 o.erase(o.find(
"transaction"));
84 if (o.count(
"expect") > 0)
86 bool expectInValid = (o[
"expect"].get_str() ==
"invalid");
87 if (Options::get().checkstate)
88 BOOST_CHECK_MESSAGE(expectInValid, testname +
"Check state: Transaction '" << i.first <<
"' is expected to be valid!");
90 BOOST_WARN_MESSAGE(expectInValid, testname +
"Check state: Transaction '" << i.first <<
"' is expected to be valid!");
92 o.erase(o.find(
"expect"));
97 if (o.count(
"expect") > 0)
99 bool expectValid = (o[
"expect"].get_str() ==
"valid");
100 if (Options::get().checkstate)
101 BOOST_CHECK_MESSAGE(expectValid, testname +
"Check state: Transaction '" << i.first <<
"' is expected to be invalid!");
103 BOOST_WARN_MESSAGE(expectValid, testname +
"Check state: Transaction '" << i.first <<
"' is expected to be invalid!");
105 o.erase(o.find(
"expect"));
110 BOOST_REQUIRE(o.count(
"rlp") > 0);
117 se->verifyTransaction(ImportRequirements::Everything, txFromRlp, bh);
118 if (!txFromRlp.signature().isValid())
124 cnote <<
"Transaction Exception: " << diagnostic_information(_e);
125 BOOST_CHECK_MESSAGE(o.count(
"transaction") == 0, testname +
"A transaction object should not be defined because the RLP is invalid!");
130 BOOST_CHECK_MESSAGE(o.count(
"transaction") == 0, testname +
"A transaction object should not be defined because the RLP is invalid!");
134 BOOST_REQUIRE_MESSAGE(o.count(
"transaction") > 0, testname +
"Expected a valid transaction!");
136 mObject tObj = o[
"transaction"].get_obj();
141 BOOST_CHECK_MESSAGE(txFromFields.
data() == txFromRlp.data(), testname +
"Data in given RLP not matching the Transaction data!");
142 BOOST_CHECK_MESSAGE(txFromFields.
value() == txFromRlp.value(), testname +
"Value in given RLP not matching the Transaction value!");
143 BOOST_CHECK_MESSAGE(txFromFields.
gasPrice() == txFromRlp.gasPrice(), testname +
"GasPrice in given RLP not matching the Transaction gasPrice!");
144 BOOST_CHECK_MESSAGE(txFromFields.
gas() == txFromRlp.gas(), testname +
"Gas in given RLP not matching the Transaction gas!");
145 BOOST_CHECK_MESSAGE(txFromFields.
nonce() == txFromRlp.nonce(), testname +
"Nonce in given RLP not matching the Transaction nonce!");
146 BOOST_CHECK_MESSAGE(txFromFields.
receiveAddress() == txFromRlp.receiveAddress(), testname +
"Receive address in given RLP not matching the Transaction 'to' address!");
147 BOOST_CHECK_MESSAGE(txFromFields.
sender() == txFromRlp.sender(), testname +
"Transaction sender address in given RLP not matching the Transaction 'vrs' signature!");
148 BOOST_CHECK_MESSAGE(txFromFields.
sha3() == txFromRlp.sha3(), testname +
"Transaction sha3 hash in given RLP not matching the Transaction 'vrs' signature!");
149 BOOST_CHECK_MESSAGE(txFromFields.
sha3() == txSha3Expected, testname +
"Expected different transaction hash!");
150 BOOST_CHECK_MESSAGE(txFromFields == txFromRlp, testname +
"However, txFromFields != txFromRlp!");
151 BOOST_REQUIRE (o.count(
"sender") > 0);
154 BOOST_CHECK_MESSAGE(txFromFields.
sender() == addressReaded || txFromRlp.sender() == addressReaded, testname +
"Signature address of sender does not match given sender address!");
163 BOOST_AUTO_TEST_SUITE(TransactionTests)
226 if (test::Options::get().bigData)
228 auto start = chrono::steady_clock::now();
232 auto end = chrono::steady_clock::now();
233 auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
234 cnote <<
"test duration: " <<
duration.count() <<
" milliseconds.\n";
240 if (test::Options::get().bigData)
242 auto start = chrono::steady_clock::now();
246 auto end = chrono::steady_clock::now();
247 auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
248 cnote <<
"test duration: " <<
duration.count() <<
" milliseconds.\n";
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
BOOST_AUTO_TEST_CASE(ttMetropolisTests)
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
static Options const & get(int argc=0, char **argv=0)
Get reference to options The first time used, options are parsed with argc, argv. ...
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
bytesConstRef data() const
The bare data of the RLP.
bytes const & out() const
Read the byte stream.
h160 Address
An Ethereum address: 20 bytes.
Address const & sender() const
std::hash for asio::adress
int Add(word *C, const word *A, const word *B, size_t N)
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Base class for all exceptions.
void userDefinedTest(std::function< void(json_spirit::mValue &, bool)> doTests)
void doTransactionTests(json_spirit::mValue &_v, bool _fillin)
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject const &_tObj)
std::vector< byte > bytes
std::string getTestPath()
bytes const & data() const
h256 sha3(IncludeSignature _sig=WithSignature) const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
void copyFile(std::string const &_source, std::string const &_destination)
Encodes a transaction, ready to be exported to or freshly imported from RLP.
mConfig::Object_type mObject
std::string const & genesisInfo(Network _n)
boost::error_info< struct tag_comment, std::string > errinfo_comment
#define BOOST_AUTO_TEST_SUITE_END()
void executeTests(const string &_name, const string &_testPathAppendix, const string &_fillerPathAppendix, std::function< void(json_spirit::mValue &, bool)> doTests, bool _addFillerSuffix)
bytes importByteArray(std::string const &_str)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Class for writing to an RLP bytestream.
Class for interpreting Recursive Linear-Prefix Data.
u256 toInt(json_spirit::mValue const &_v)
Helper functions to work with json::spirit and test files.
Address receiveAddress() const
static void initTest(int _maxTests=1)