From 9c34eed9daa73bc3547b0e1c02a4c32cd431272c Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 21 Jan 2015 16:10:06 +0100 Subject: [PATCH 01/20] new file block.cpp --- block.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 block.cpp diff --git a/block.cpp b/block.cpp new file mode 100644 index 000000000..974acbf6d --- /dev/null +++ b/block.cpp @@ -0,0 +1,21 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file state.cpp + * @author Christoph Jentzsch + * @date 2014 + * block test functions. + */ From f7073f84c58649e04b835a6e9206200f621a153c Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 5 Feb 2015 16:34:46 +0100 Subject: [PATCH 02/20] first definition of block tests - header only --- blValidBlockTestFiller.json | 20 ++++ block.cpp | 185 +++++++++++++++++++++++++++++++++++- 2 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 blValidBlockTestFiller.json diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json new file mode 100644 index 000000000..ab0369fa4 --- /dev/null +++ b/blValidBlockTestFiller.json @@ -0,0 +1,20 @@ +{ + "validBlock" : { + "block" : { + "parentHash": "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", + "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1", + "stateRoot": "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "023101", + "number": "62", + "gasLimit": "0x0dddb6", + "gasUsed": "100", + "timestamp": "0x54c98c81", + "extraData": "42", + "nonce": "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" + } + } +} diff --git a/block.cpp b/block.cpp index 974acbf6d..674c7c40d 100644 --- a/block.cpp +++ b/block.cpp @@ -14,8 +14,189 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file state.cpp +/** @file block.cpp * @author Christoph Jentzsch - * @date 2014 + * @date 2015 * block test functions. */ + +#include "TestHelper.h" + +using namespace std; +using namespace json_spirit; +using namespace dev; +using namespace dev::eth; + +namespace dev { namespace test { + +bytes createBlockRLPFromFields(mObject& _tObj) +{ + BOOST_REQUIRE(_tObj.count("parentHash") > 0); + BOOST_REQUIRE(_tObj.count("uncleHash") > 0); + BOOST_REQUIRE(_tObj.count("coinbase") > 0); + BOOST_REQUIRE(_tObj.count("stateRoot") > 0); + BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0); + BOOST_REQUIRE(_tObj.count("receiptTrie") > 0); + BOOST_REQUIRE(_tObj.count("bloom") > 0); + BOOST_REQUIRE(_tObj.count("difficulty") > 0); + BOOST_REQUIRE(_tObj.count("number") > 0); + BOOST_REQUIRE(_tObj.count("gasLimit")> 0); + BOOST_REQUIRE(_tObj.count("gasUsed") > 0); + BOOST_REQUIRE(_tObj.count("timestamp") > 0); + BOOST_REQUIRE(_tObj.count("extraData") > 0); + BOOST_REQUIRE(_tObj.count("nonce") > 0); + + // construct RLP of the given block + cout << "done with require\n"; + RLPStream rlpStream; + rlpStream.appendList(14); + cout << "increate aha1\n"; + rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); + rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << Address(_tObj["receiptTrie"].get_str()); + rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); + rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); + rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); + + return rlpStream.out(); +} + +void doBlockTests(json_spirit::mValue& _v, bool _fillin) +{ + for (auto& i: _v.get_obj()) + { + cerr << i.first << endl; + mObject& o = i.second.get_obj(); + + if (_fillin == false) + { + BOOST_REQUIRE(o.count("rlp") > 0); + const bytes rlpReaded = importByteArray(o["rlp"].get_str()); + RLP myRLP(rlpReaded); + BlockInfo blockFromRlp; + + try + { + blockFromRlp.populateFromHeader(myRLP, false); + //blockFromRlp.verifyInternals(rlpReaded); + } + catch(Exception const& _e) + { + cnote << "block construction did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + BOOST_CHECK_MESSAGE(o.count("block") == 0, "A block object should not be defined because the block RLP is invalid!"); + return; + } + + BOOST_REQUIRE(o.count("block") > 0); + + mObject tObj = o["block"].get_obj(); + BlockInfo blockFromFields; + const bytes rlpreade2 = createBlockRLPFromFields(tObj); + RLP mysecondRLP(rlpreade2); + blockFromFields.populateFromHeader(mysecondRLP, false); + + //Check the fields restored from RLP to original fields + BOOST_CHECK_MESSAGE(blockFromFields.hash == blockFromRlp.hash, "hash in given RLP not matching the block hash!"); + BOOST_CHECK_MESSAGE(blockFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); + BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); + BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); + BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); + BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); + BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); + BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); + BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); + BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); + BOOST_CHECK_MESSAGE(blockFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); + BOOST_CHECK_MESSAGE(blockFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); + BOOST_CHECK_MESSAGE(blockFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); + + BOOST_CHECK_MESSAGE(blockFromFields == blockFromRlp, "However, blockFromFields != blockFromRlp!"); + + } + else + { + BOOST_REQUIRE(o.count("block") > 0); + + // construct Rlp of the given block + bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); + RLP myRLP(blockRLP); + o["rlp"] = toHex(blockRLP); + + try + { + BlockInfo blockFromFields; + blockFromFields.populateFromHeader(myRLP, false); + (void)blockFromFields; + //blockFromFields.verifyInternals(blockRLP); + } + catch (Exception const& _e) + { + cnote << "block construction did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + o.erase(o.find("block")); + } + catch (std::exception const& _e) + { + cnote << "block construction did throw an exception: " << _e.what(); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + o.erase(o.find("block")); + } + catch(...) + { + o.erase(o.find("block")); + } + } + } +} + +} }// Namespace Close + + +BOOST_AUTO_TEST_SUITE(BlockTests) + +BOOST_AUTO_TEST_CASE(blValidBlocksTest) +{ + dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); +} + +BOOST_AUTO_TEST_CASE(ttCreateTest) +{ + for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) + { + string arg = boost::unit_test::framework::master_test_suite().argv[i]; + if (arg == "--createtest") + { + if (boost::unit_test::framework::master_test_suite().argc <= i + 2) + { + cnote << "usage: ./testeth --createtest \n"; + return; + } + try + { + cnote << "Populating tests..."; + json_spirit::mValue v; + string s = asString(dev::contents(boost::unit_test::framework::master_test_suite().argv[i + 1])); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + (string)boost::unit_test::framework::master_test_suite().argv[i + 1] + " is empty."); + json_spirit::read_string(s, v); + dev::test::doBlockTests(v, true); + writeFile(boost::unit_test::framework::master_test_suite().argv[i + 2], asBytes(json_spirit::write_string(v, true))); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed block test with Exception: " << diagnostic_information(_e)); + } + catch (std::exception const& _e) + { + BOOST_ERROR("Failed block test with Exception: " << _e.what()); + } + } + } +} + +BOOST_AUTO_TEST_CASE(userDefinedFileTT) +{ + dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); +} + +BOOST_AUTO_TEST_SUITE_END() From ad1a26c5035481e760cfdaf748fb26bee7e7beb2 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 6 Feb 2015 15:00:06 +0100 Subject: [PATCH 03/20] include transaction list --- block.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block.cpp b/block.cpp index 674c7c40d..40984e8da 100644 --- a/block.cpp +++ b/block.cpp @@ -144,8 +144,30 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) } catch(...) { + cnote << "block construction did throw an unknow exception\n"; o.erase(o.find("block")); } + + BOOST_REQUIRE(o.count("transactions") > 0); + + for (auto const& txObj: o["transactions"].get_array()) + { + mObject tx = txObj.get_obj(); + BOOST_REQUIRE(tx.count("nonce") > 0); + BOOST_REQUIRE(tx.count("gasPrice") > 0); + BOOST_REQUIRE(tx.count("gasLimit") > 0); + BOOST_REQUIRE(tx.count("to") > 0); + BOOST_REQUIRE(tx.count("value") > 0); + BOOST_REQUIRE(tx.count("v") > 0); + BOOST_REQUIRE(tx.count("r") > 0); + BOOST_REQUIRE(tx.count("s") > 0); + BOOST_REQUIRE(tx.count("data") > 0); + + Transaction txFromFields = createTransactionFromFields(tx); + + + + } } } } From 330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 6 Feb 2015 23:43:49 +0100 Subject: [PATCH 04/20] create block from transaction with genesis block as parent --- TestHelper.cpp | 27 ++++++ TestHelper.h | 1 + blFirstTestFiller.json | 15 ++++ block.cpp | 197 ++++++++++++++++++++++++++--------------- transaction.cpp | 30 +------ 5 files changed, 169 insertions(+), 101 deletions(-) create mode 100644 blFirstTestFiller.json diff --git a/TestHelper.cpp b/TestHelper.cpp index 5a579702a..3289305cd 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -487,6 +487,33 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun } } +bytes createTransactionFromFields(json_spirit::mObject& _tObj) +{ + BOOST_REQUIRE(_tObj.count("data") > 0); + BOOST_REQUIRE(_tObj.count("value") > 0); + BOOST_REQUIRE(_tObj.count("gasPrice") > 0); + BOOST_REQUIRE(_tObj.count("gasLimit") > 0); + BOOST_REQUIRE(_tObj.count("nonce")> 0); + BOOST_REQUIRE(_tObj.count("to") > 0); + + BOOST_REQUIRE(_tObj.count("v") > 0); + BOOST_REQUIRE(_tObj.count("r") > 0); + BOOST_REQUIRE(_tObj.count("s") > 0); + + //Construct Rlp of the given transaction + RLPStream rlpStream; + rlpStream.appendList(9); + rlpStream << bigint(_tObj["nonce"].get_str()) << bigint(_tObj["gasPrice"].get_str()) << bigint(_tObj["gasLimit"].get_str()); + if (_tObj["to"].get_str().empty()) + rlpStream << ""; + else + rlpStream << Address(_tObj["to"].get_str()); + rlpStream << bigint(_tObj["value"].get_str()) << importData(_tObj); + rlpStream << bigint(_tObj["v"].get_str()) << bigint(_tObj["r"].get_str()) << bigint(_tObj["s"].get_str()); + + return rlpStream.out(); +} + void processCommandLineOptions() { diff --git a/TestHelper.h b/TestHelper.h index ae6ea20cc..344f61a3f 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -79,6 +79,7 @@ void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _e void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function doTests); std::string getTestPath(); void userDefinedTest(std::string testTypeFlag, std::function doTests); +bytes createTransactionFromFields(json_spirit::mObject& _tObj); void processCommandLineOptions(); eth::LastHashes lastHashes(u256 _currentBlockNumber); diff --git a/blFirstTestFiller.json b/blFirstTestFiller.json new file mode 100644 index 000000000..0084fda13 --- /dev/null +++ b/blFirstTestFiller.json @@ -0,0 +1,15 @@ +{ + "firstBlockTest" : { + "transactions": [{ + "nonce": "0", + "gasPrice": "0x09184e72a000", + "gasLimit": "0x0f3e6f", + "to": "", + "value": "", + "data": "0x60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b56", + "v": "0x1b", + "r": "0xd4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89", + "s": "0xae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942" + }] + } +} diff --git a/block.cpp b/block.cpp index 40984e8da..518b61238 100644 --- a/block.cpp +++ b/block.cpp @@ -20,6 +20,7 @@ * block test functions. */ +#include #include "TestHelper.h" using namespace std; @@ -116,40 +117,42 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) } else { - BOOST_REQUIRE(o.count("block") > 0); +// BOOST_REQUIRE(o.count("block") > 0); - // construct Rlp of the given block - bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); - RLP myRLP(blockRLP); - o["rlp"] = toHex(blockRLP); +// // construct Rlp of the given block +// bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); +// RLP myRLP(blockRLP); +// o["rlp"] = toHex(blockRLP); - try - { - BlockInfo blockFromFields; - blockFromFields.populateFromHeader(myRLP, false); - (void)blockFromFields; - //blockFromFields.verifyInternals(blockRLP); - } - catch (Exception const& _e) - { - cnote << "block construction did throw an exception: " << diagnostic_information(_e); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - o.erase(o.find("block")); - } - catch (std::exception const& _e) - { - cnote << "block construction did throw an exception: " << _e.what(); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - o.erase(o.find("block")); - } - catch(...) - { - cnote << "block construction did throw an unknow exception\n"; - o.erase(o.find("block")); - } +// try +// { +// BlockInfo blockFromFields; +// blockFromFields.populateFromHeader(myRLP, false); +// (void)blockFromFields; +// //blockFromFields.verifyInternals(blockRLP); +// } +// catch (Exception const& _e) +// { +// cnote << "block construction did throw an exception: " << diagnostic_information(_e); +// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); +// o.erase(o.find("block")); +// } +// catch (std::exception const& _e) +// { +// cnote << "block construction did throw an exception: " << _e.what(); +// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); +// o.erase(o.find("block")); +// } +// catch(...) +// { +// cnote << "block construction did throw an unknow exception\n"; +// o.erase(o.find("block")); +// } BOOST_REQUIRE(o.count("transactions") > 0); + TransactionQueue txs; + for (auto const& txObj: o["transactions"].get_array()) { mObject tx = txObj.get_obj(); @@ -162,12 +165,60 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(tx.count("r") > 0); BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("data") > 0); - - Transaction txFromFields = createTransactionFromFields(tx); - - - + cout << "attempt to import transaction\n"; + txs.attemptImport(createTransactionFromFields(tx)); } + cout << "done importing txs\n"; + + + + //BOOST_REQUIRE(o.count("env") > 0); + //BOOST_REQUIRE(o.count("pre") > 0); + +// ImportTest importer; +// importer.importEnv(o["env"].get_obj()); +// importer.importState(o["pre"].get_obj(), m_statePre); + +// State theState = importer.m_statePre; +// bytes output; + + cout << "construct bc\n"; + CanonBlockChain bc(true); + cout << "construct state\n"; + State theState; + + try + { + cout << "sync bc and txs in state\n"; + theState.sync(bc,txs); + // lock + cout << "commit to mine\n"; + theState.commitToMine(bc); // will call uncommitToMine if a repeat. + // unlock + MineInfo info; + cout << "mine...\n"; + for (info.completed = false; !info.completed; info = theState.mine()) {} + cout << "done mining, completeMine\n"; + // lock + theState.completeMine(); + // unlock + + cout << "new block: " << theState.blockData() << endl << theState.info() << endl; + } + catch (Exception const& _e) + { + cnote << "state sync did throw an exception: " << diagnostic_information(_e); + } + catch (std::exception const& _e) + { + cnote << "state sync did throw an exception: " << _e.what(); + } + + // write block and rlp to json + + //TODO if block rlp is invalid, delete transactions, and block + + } } } @@ -177,48 +228,48 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(BlockTests) -BOOST_AUTO_TEST_CASE(blValidBlocksTest) +BOOST_AUTO_TEST_CASE(blFirstTest) { - dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); + dev::test::executeTests("blFirstTest", "/BlockTests", dev::test::doBlockTests); } -BOOST_AUTO_TEST_CASE(ttCreateTest) -{ - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--createtest") - { - if (boost::unit_test::framework::master_test_suite().argc <= i + 2) - { - cnote << "usage: ./testeth --createtest \n"; - return; - } - try - { - cnote << "Populating tests..."; - json_spirit::mValue v; - string s = asString(dev::contents(boost::unit_test::framework::master_test_suite().argv[i + 1])); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + (string)boost::unit_test::framework::master_test_suite().argv[i + 1] + " is empty."); - json_spirit::read_string(s, v); - dev::test::doBlockTests(v, true); - writeFile(boost::unit_test::framework::master_test_suite().argv[i + 2], asBytes(json_spirit::write_string(v, true))); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed block test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) - { - BOOST_ERROR("Failed block test with Exception: " << _e.what()); - } - } - } -} +//BOOST_AUTO_TEST_CASE(ttCreateTest) +//{ +// for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) +// { +// string arg = boost::unit_test::framework::master_test_suite().argv[i]; +// if (arg == "--createtest") +// { +// if (boost::unit_test::framework::master_test_suite().argc <= i + 2) +// { +// cnote << "usage: ./testeth --createtest \n"; +// return; +// } +// try +// { +// cnote << "Populating tests..."; +// json_spirit::mValue v; +// string s = asString(dev::contents(boost::unit_test::framework::master_test_suite().argv[i + 1])); +// BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + (string)boost::unit_test::framework::master_test_suite().argv[i + 1] + " is empty."); +// json_spirit::read_string(s, v); +// dev::test::doBlockTests(v, true); +// writeFile(boost::unit_test::framework::master_test_suite().argv[i + 2], asBytes(json_spirit::write_string(v, true))); +// } +// catch (Exception const& _e) +// { +// BOOST_ERROR("Failed block test with Exception: " << diagnostic_information(_e)); +// } +// catch (std::exception const& _e) +// { +// BOOST_ERROR("Failed block test with Exception: " << _e.what()); +// } +// } +// } +//} -BOOST_AUTO_TEST_CASE(userDefinedFileTT) -{ - dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); -} +//BOOST_AUTO_TEST_CASE(userDefinedFileTT) +//{ +// dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); +//} BOOST_AUTO_TEST_SUITE_END() diff --git a/transaction.cpp b/transaction.cpp index e1e275302..00de5fb23 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -29,33 +29,6 @@ using namespace dev::eth; namespace dev { namespace test { -Transaction createTransactionFromFields(mObject& _tObj) -{ - BOOST_REQUIRE(_tObj.count("data") > 0); - BOOST_REQUIRE(_tObj.count("value") > 0); - BOOST_REQUIRE(_tObj.count("gasPrice") > 0); - BOOST_REQUIRE(_tObj.count("gasLimit") > 0); - BOOST_REQUIRE(_tObj.count("nonce")> 0); - BOOST_REQUIRE(_tObj.count("to") > 0); - - BOOST_REQUIRE(_tObj.count("v") > 0); - BOOST_REQUIRE(_tObj.count("r") > 0); - BOOST_REQUIRE(_tObj.count("s") > 0); - - //Construct Rlp of the given transaction - RLPStream rlpStream; - rlpStream.appendList(9); - rlpStream << bigint(_tObj["nonce"].get_str()) << bigint(_tObj["gasPrice"].get_str()) << bigint(_tObj["gasLimit"].get_str()); - if (_tObj["to"].get_str().empty()) - rlpStream << ""; - else - rlpStream << Address(_tObj["to"].get_str()); - rlpStream << bigint(_tObj["value"].get_str()) << importData(_tObj); - rlpStream << bigint(_tObj["v"].get_str()) << bigint(_tObj["r"].get_str()) << bigint(_tObj["s"].get_str()); - - return Transaction(rlpStream.out(), CheckSignature::Sender); -} - void doTransactionTests(json_spirit::mValue& _v, bool _fillin) { for (auto& i: _v.get_obj()) @@ -84,7 +57,8 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(o.count("transaction") > 0); mObject tObj = o["transaction"].get_obj(); - Transaction txFromFields = createTransactionFromFields(tObj); + bytes txRLP = createTransactionFromFields(tObj); + Transaction txFromFields(txRLP, CheckSignature::Sender); //Check the fields restored from RLP to original fields BOOST_CHECK_MESSAGE(txFromFields.data() == txFromRlp.data(), "Data in given RLP not matching the Transaction data!"); From 84bd14e0a2508c8e966e1fb69a9850cfda59e360 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 9 Feb 2015 08:17:30 +0100 Subject: [PATCH 05/20] write block header and uncle list --- block.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/block.cpp b/block.cpp index 518b61238..adf8a3ad9 100644 --- a/block.cpp +++ b/block.cpp @@ -214,11 +214,33 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cnote << "state sync did throw an exception: " << _e.what(); } - // write block and rlp to json + o["rlp"] = "0x" + toHex(theState.blockData()); - //TODO if block rlp is invalid, delete transactions, and block + // write block header + mObject oBlockHeader; + BlockInfo current_BlockHeader = theState.info(); + oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); + oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); + oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); + oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); + oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); + oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); + oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); + oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); + oBlockHeader["number"] = toString(current_BlockHeader.number); + oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); + oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); + oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); + oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); + oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); + o["blockHeader"] = oBlockHeader; + + // write uncle list + + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. That might change. + o["uncleHeaders"] = aUncleList; } } } From 0779f81e38fd98235a6deffa7c6ae0076d02b545 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 10 Feb 2015 08:35:18 +0100 Subject: [PATCH 06/20] start with test defined genesis block --- TestHelper.h | 3 +- blFirstTestFiller.json | 17 ++ blValidBlockTestFiller.json | 71 +++++-- block.cpp | 363 ++++++++++++++++++++---------------- 4 files changed, 273 insertions(+), 181 deletions(-) diff --git a/TestHelper.h b/TestHelper.h index 344f61a3f..9ac1f0d4d 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -45,7 +45,7 @@ namespace test class ImportTest { public: - ImportTest() = default; + ImportTest(json_spirit::mObject& _o) : m_TestObject(_o) {} ImportTest(json_spirit::mObject& _o, bool isFiller); // imports @@ -53,6 +53,7 @@ public: void importState(json_spirit::mObject& _o, eth::State& _state); void importTransaction(json_spirit::mObject& _o); void exportTest(bytes _output, eth::State& _statePost); + std::map getStateMap(eth::State& _state){return _state.m_cache;} eth::State m_statePre; eth::State m_statePost; diff --git a/blFirstTestFiller.json b/blFirstTestFiller.json index 0084fda13..d4e6d109f 100644 --- a/blFirstTestFiller.json +++ b/blFirstTestFiller.json @@ -1,5 +1,22 @@ { "firstBlockTest" : { + "block" : { + "parentHash": "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", + "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1", + "stateRoot": "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "023101", + "number": "62", + "gasLimit": "0x0dddb6", + "gasUsed": "100", + "timestamp": "0x54c98c81", + "extraData": "42", + "nonce": "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" + }, + "pre" : {}, "transactions": [{ "nonce": "0", "gasPrice": "0x09184e72a000", diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index ab0369fa4..8b951b179 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,20 +1,61 @@ { "validBlock" : { "block" : { - "parentHash": "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", - "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1", - "stateRoot": "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty": "023101", - "number": "62", - "gasLimit": "0x0dddb6", - "gasUsed": "100", - "timestamp": "0x54c98c81", - "extraData": "42", - "nonce": "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" - } + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1024", + "extraData" : "42", + "gasLimit" : "0x0dddb6", + "gasUsed" : "100", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "blockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0000000000000000000000000000000000000000", + "difficulty" : "130944", + "extraData" : "", + "gasLimit" : "999023", + "gasUsed" : "4803", + "nonce" : "62778f62183098b7cc8d221fc199654e613ca47b85696f940de3bd2bb6a2a54e", + "number" : "1", + "parentHash" : "c9cb614fddd89b3bc6e2f0ed1f8e58e8a0d826612a607a6151be6f39c991a941", + "receiptTrie" : "8fd35225dd530f30dc39719f9791583309b5889ad79bff0d31e9b1eb12f55000", + "stateRoot" : "b3ef9fe736086bdf1b3cd235f68097aab5f4c6e40d57f417d39c2cc6fb67f6c7", + "timestamp" : "1423490430", + "transactionsTrie" : "2cb4068eb8ccc9124426a7ed5c445b1353c997fc419031254ff7e2768c4dcd7f", + "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : 0, + "code" : "", + "storage": {} + } + }, + "rlp" : "0xf9033bf9012fa0c9cb614fddd89b3bc6e2f0ed1f8e58e8a0d826612a607a6151be6f39c991a941a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0b3ef9fe736086bdf1b3cd235f68097aab5f4c6e40d57f417d39c2cc6fb67f6c7a02cb4068eb8ccc9124426a7ed5c445b1353c997fc419031254ff7e2768c4dcd7fa08fd35225dd530f30dc39719f9791583309b5889ad79bff0d31e9b1eb12f55000b840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008301ff8001830f3e6f8212c38454d8bd7e80a062778f62183098b7cc8d221fc199654e613ca47b85696f940de3bd2bb6a2a54ef90205f90202808609184e72a000830f3e6f8080b901ae60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b561ba0d4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89a0ae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942c0", + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] } } + diff --git a/block.cpp b/block.cpp index adf8a3ad9..9b598bbca 100644 --- a/block.cpp +++ b/block.cpp @@ -32,168 +32,194 @@ namespace dev { namespace test { bytes createBlockRLPFromFields(mObject& _tObj) { - BOOST_REQUIRE(_tObj.count("parentHash") > 0); - BOOST_REQUIRE(_tObj.count("uncleHash") > 0); - BOOST_REQUIRE(_tObj.count("coinbase") > 0); - BOOST_REQUIRE(_tObj.count("stateRoot") > 0); - BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0); - BOOST_REQUIRE(_tObj.count("receiptTrie") > 0); - BOOST_REQUIRE(_tObj.count("bloom") > 0); - BOOST_REQUIRE(_tObj.count("difficulty") > 0); - BOOST_REQUIRE(_tObj.count("number") > 0); - BOOST_REQUIRE(_tObj.count("gasLimit")> 0); - BOOST_REQUIRE(_tObj.count("gasUsed") > 0); - BOOST_REQUIRE(_tObj.count("timestamp") > 0); - BOOST_REQUIRE(_tObj.count("extraData") > 0); - BOOST_REQUIRE(_tObj.count("nonce") > 0); + BOOST_REQUIRE(_tObj.count("parentHash") > 0); + BOOST_REQUIRE(_tObj.count("uncleHash") > 0); + BOOST_REQUIRE(_tObj.count("coinbase") > 0); + BOOST_REQUIRE(_tObj.count("stateRoot") > 0); + BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0); + BOOST_REQUIRE(_tObj.count("receiptTrie") > 0); + BOOST_REQUIRE(_tObj.count("bloom") > 0); + BOOST_REQUIRE(_tObj.count("difficulty") > 0); + BOOST_REQUIRE(_tObj.count("number") > 0); + BOOST_REQUIRE(_tObj.count("gasLimit")> 0); + BOOST_REQUIRE(_tObj.count("gasUsed") > 0); + BOOST_REQUIRE(_tObj.count("timestamp") > 0); + BOOST_REQUIRE(_tObj.count("extraData") > 0); + BOOST_REQUIRE(_tObj.count("nonce") > 0); - // construct RLP of the given block - cout << "done with require\n"; - RLPStream rlpStream; - rlpStream.appendList(14); - cout << "increate aha1\n"; - rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); - rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << Address(_tObj["receiptTrie"].get_str()); - rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); - rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); - rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); + // construct RLP of the given block + cout << "done with require\n"; + RLPStream rlpStream; + rlpStream.appendList(14); + cout << "increate aha1\n"; + rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); + rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << Address(_tObj["receiptTrie"].get_str()); + rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); + rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); + rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); - return rlpStream.out(); + return rlpStream.out(); } void doBlockTests(json_spirit::mValue& _v, bool _fillin) { - for (auto& i: _v.get_obj()) - { - cerr << i.first << endl; - mObject& o = i.second.get_obj(); + for (auto& i: _v.get_obj()) + { + cerr << i.first << endl; + mObject& o = i.second.get_obj(); - if (_fillin == false) - { - BOOST_REQUIRE(o.count("rlp") > 0); - const bytes rlpReaded = importByteArray(o["rlp"].get_str()); - RLP myRLP(rlpReaded); - BlockInfo blockFromRlp; + if (_fillin == false) + { + // TODO - try - { - blockFromRlp.populateFromHeader(myRLP, false); - //blockFromRlp.verifyInternals(rlpReaded); - } - catch(Exception const& _e) - { - cnote << "block construction did throw an exception: " << diagnostic_information(_e); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - BOOST_CHECK_MESSAGE(o.count("block") == 0, "A block object should not be defined because the block RLP is invalid!"); - return; - } + // BOOST_REQUIRE(o.count("rlp") > 0); + // const bytes rlpReaded = importByteArray(o["rlp"].get_str()); + // RLP myRLP(rlpReaded); + // BlockInfo blockFromRlp; - BOOST_REQUIRE(o.count("block") > 0); + // try + // { + // blockFromRlp.populateFromHeader(myRLP, false); + // //blockFromRlp.verifyInternals(rlpReaded); + // } + // catch(Exception const& _e) + // { + // cnote << "block construction did throw an exception: " << diagnostic_information(_e); + // BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + // BOOST_CHECK_MESSAGE(o.count("block") == 0, "A block object should not be defined because the block RLP is invalid!"); + // return; + // } - mObject tObj = o["block"].get_obj(); - BlockInfo blockFromFields; - const bytes rlpreade2 = createBlockRLPFromFields(tObj); - RLP mysecondRLP(rlpreade2); - blockFromFields.populateFromHeader(mysecondRLP, false); + // BOOST_REQUIRE(o.count("block") > 0); - //Check the fields restored from RLP to original fields - BOOST_CHECK_MESSAGE(blockFromFields.hash == blockFromRlp.hash, "hash in given RLP not matching the block hash!"); - BOOST_CHECK_MESSAGE(blockFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); - BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); - BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); - BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); - BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); - BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); - BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); - BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); - BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); - BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); - BOOST_CHECK_MESSAGE(blockFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); - BOOST_CHECK_MESSAGE(blockFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); - BOOST_CHECK_MESSAGE(blockFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); + // mObject tObj = o["block"].get_obj(); + // BlockInfo blockFromFields; + // const bytes rlpreade2 = createBlockRLPFromFields(tObj); + // RLP mysecondRLP(rlpreade2); + // blockFromFields.populateFromHeader(mysecondRLP, false); - BOOST_CHECK_MESSAGE(blockFromFields == blockFromRlp, "However, blockFromFields != blockFromRlp!"); + // //Check the fields restored from RLP to original fields + // BOOST_CHECK_MESSAGE(blockFromFields.hash == blockFromRlp.hash, "hash in given RLP not matching the block hash!"); + // BOOST_CHECK_MESSAGE(blockFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); + // BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); + // BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); + // BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); + // BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); + // BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + // BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); + // BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); + // BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); + // BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); + // BOOST_CHECK_MESSAGE(blockFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); + // BOOST_CHECK_MESSAGE(blockFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); + // BOOST_CHECK_MESSAGE(blockFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); - } - else - { -// BOOST_REQUIRE(o.count("block") > 0); + // BOOST_CHECK_MESSAGE(blockFromFields == blockFromRlp, "However, blockFromFields != blockFromRlp!"); -// // construct Rlp of the given block -// bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); -// RLP myRLP(blockRLP); -// o["rlp"] = toHex(blockRLP); + } + else + { + BOOST_REQUIRE(o.count("block") > 0); -// try -// { -// BlockInfo blockFromFields; -// blockFromFields.populateFromHeader(myRLP, false); -// (void)blockFromFields; -// //blockFromFields.verifyInternals(blockRLP); -// } -// catch (Exception const& _e) -// { -// cnote << "block construction did throw an exception: " << diagnostic_information(_e); -// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); -// o.erase(o.find("block")); -// } -// catch (std::exception const& _e) -// { -// cnote << "block construction did throw an exception: " << _e.what(); -// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); -// o.erase(o.find("block")); -// } -// catch(...) -// { -// cnote << "block construction did throw an unknow exception\n"; -// o.erase(o.find("block")); -// } - - BOOST_REQUIRE(o.count("transactions") > 0); - - TransactionQueue txs; - - for (auto const& txObj: o["transactions"].get_array()) - { - mObject tx = txObj.get_obj(); - BOOST_REQUIRE(tx.count("nonce") > 0); - BOOST_REQUIRE(tx.count("gasPrice") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); - BOOST_REQUIRE(tx.count("to") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("v") > 0); - BOOST_REQUIRE(tx.count("r") > 0); - BOOST_REQUIRE(tx.count("s") > 0); - BOOST_REQUIRE(tx.count("data") > 0); - cout << "attempt to import transaction\n"; - txs.attemptImport(createTransactionFromFields(tx)); - } - cout << "done importing txs\n"; - - - - //BOOST_REQUIRE(o.count("env") > 0); - //BOOST_REQUIRE(o.count("pre") > 0); - -// ImportTest importer; -// importer.importEnv(o["env"].get_obj()); -// importer.importState(o["pre"].get_obj(), m_statePre); - -// State theState = importer.m_statePre; -// bytes output; - - cout << "construct bc\n"; - CanonBlockChain bc(true); - cout << "construct state\n"; - State theState; + // construct Rlp of the given block + bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); + RLP myRLP(blockRLP); + BlockInfo blockFromFields; + cout << "blockFromFields diff:" << blockFromFields.difficulty << endl; try { + + blockFromFields.populateFromHeader(myRLP, false); + //blockFromFields.verifyInternals(blockRLP); + } + catch (Exception const& _e) + { + cnote << "block construction did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + o.erase(o.find("block")); + } + catch (std::exception const& _e) + { + cnote << "block construction did throw an exception: " << _e.what(); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + o.erase(o.find("block")); + } + catch(...) + { + cnote << "block construction did throw an unknown exception\n"; + o.erase(o.find("block")); + } + + BOOST_REQUIRE(o.count("transactions") > 0); + + TransactionQueue txs; + + for (auto const& txObj: o["transactions"].get_array()) + { + mObject tx = txObj.get_obj(); + BOOST_REQUIRE(tx.count("nonce") > 0); + BOOST_REQUIRE(tx.count("gasPrice") > 0); + BOOST_REQUIRE(tx.count("gasLimit") > 0); + BOOST_REQUIRE(tx.count("to") > 0); + BOOST_REQUIRE(tx.count("value") > 0); + BOOST_REQUIRE(tx.count("v") > 0); + BOOST_REQUIRE(tx.count("r") > 0); + BOOST_REQUIRE(tx.count("s") > 0); + BOOST_REQUIRE(tx.count("data") > 0); + cout << "attempt to import transaction\n"; + txs.attemptImport(createTransactionFromFields(tx)); + } + cout << "done importing txs\n"; + + BOOST_REQUIRE(o.count("pre") > 0); + // create state + + ImportTest importer(o["pre"].get_obj()); + State theState(Address(), OverlayDB(), BaseState::Empty); + importer.importState(o["pre"].get_obj(), theState); + + cout << "current state diff 1 : " << theState.info().difficulty << endl; + cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; + theState.commit(); + cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; + blockFromFields.stateRoot = theState.rootHash(); + cout << "stateRoot: " << blockFromFields.stateRoot << endl; + + // find new nonce + ProofOfWork pow; + MineInfo ret; + tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, false); + + // create new "genesis" block" + + RLPStream rlpStream; + blockFromFields.streamRLP(rlpStream, WithNonce); + + RLPStream block(3); + block.appendRaw(rlpStream.out()); + block.appendRaw(RLPEmptyList); + block.appendRaw(RLPEmptyList); + //return block.out(); + cout << "my genesis hash: " << sha3(RLP(block.out())[0].data()) << endl; + + cout << "construct bc\n"; + BlockChain bc(block.out(), std::string(), true); + cout << "pre difficulty: " << blockFromFields.difficulty << endl; + + try + { + //cout << "sync state with pre block" << endl; + theState.sync(bc); cout << "sync bc and txs in state\n"; + cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; + cout << "current state diff: " << theState.info().difficulty << endl; theState.sync(bc,txs); + cout << "current state diff: " << theState.info().difficulty << endl; // lock cout << "commit to mine\n"; theState.commitToMine(bc); // will call uncommitToMine if a repeat. + cout << "current state diff: " << theState.info().difficulty << endl; // unlock MineInfo info; cout << "mine...\n"; @@ -201,9 +227,11 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cout << "done mining, completeMine\n"; // lock theState.completeMine(); + cout << "current state diff: " << theState.info().difficulty << endl; // unlock cout << "new block: " << theState.blockData() << endl << theState.info() << endl; + cout << "current diff: " << theState.info().difficulty << endl; } catch (Exception const& _e) { @@ -214,35 +242,35 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cnote << "state sync did throw an exception: " << _e.what(); } - o["rlp"] = "0x" + toHex(theState.blockData()); + o["rlp"] = "0x" + toHex(theState.blockData()); - // write block header + // write block header - mObject oBlockHeader; - BlockInfo current_BlockHeader = theState.info(); - oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); - oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); - oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); - oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); - oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); - oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); - oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); - oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); - oBlockHeader["number"] = toString(current_BlockHeader.number); - oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); - oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); - oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); - oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); - oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); + mObject oBlockHeader; + BlockInfo current_BlockHeader = theState.info(); + oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); + oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); + oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); + oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); + oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); + oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); + oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); + oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); + oBlockHeader["number"] = toString(current_BlockHeader.number); + oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); + oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); + oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); + oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); + oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); - o["blockHeader"] = oBlockHeader; + o["blockHeader"] = oBlockHeader; - // write uncle list + // write uncle list - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. That might change. - o["uncleHeaders"] = aUncleList; - } - } + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. That will change. + o["uncleHeaders"] = aUncleList; + } + } } } }// Namespace Close @@ -250,9 +278,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(BlockTests) -BOOST_AUTO_TEST_CASE(blFirstTest) +//BOOST_AUTO_TEST_CASE(blFirstTest) +//{ +// dev::test::executeTests("blFirstTest", "/BlockTests", dev::test::doBlockTests); +//} + +BOOST_AUTO_TEST_CASE(blValidBlockTest) { - dev::test::executeTests("blFirstTest", "/BlockTests", dev::test::doBlockTests); + dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); } //BOOST_AUTO_TEST_CASE(ttCreateTest) From 4578732556684b3c7f24793d0459e2e8b40fe458 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 11 Feb 2015 08:37:54 +0100 Subject: [PATCH 07/20] validate block (the not fill tests path) --- blValidBlockTestFiller.json | 27 +-- block.cpp | 321 ++++++++++++++++++++---------------- 2 files changed, 182 insertions(+), 166 deletions(-) diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index 8b951b179..75ad8452e 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,37 +1,21 @@ { - "validBlock" : { - "block" : { + "lowGasLimitBoundary" : { + "genesisBlockHeader" : { "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "1024", + "difficulty" : "10000", "extraData" : "42", - "gasLimit" : "0x0dddb6", + "gasLimit" : "100000", "gasUsed" : "100", "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", "number" : "0", - "parentHash" : "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", "timestamp" : "0x54c98c81", "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" }, - "blockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0000000000000000000000000000000000000000", - "difficulty" : "130944", - "extraData" : "", - "gasLimit" : "999023", - "gasUsed" : "4803", - "nonce" : "62778f62183098b7cc8d221fc199654e613ca47b85696f940de3bd2bb6a2a54e", - "number" : "1", - "parentHash" : "c9cb614fddd89b3bc6e2f0ed1f8e58e8a0d826612a607a6151be6f39c991a941", - "receiptTrie" : "8fd35225dd530f30dc39719f9791583309b5889ad79bff0d31e9b1eb12f55000", - "stateRoot" : "b3ef9fe736086bdf1b3cd235f68097aab5f4c6e40d57f417d39c2cc6fb67f6c7", - "timestamp" : "1423490430", - "transactionsTrie" : "2cb4068eb8ccc9124426a7ed5c445b1353c997fc419031254ff7e2768c4dcd7f", - "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, "pre" : { "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { "balance" : "10000000000", @@ -40,7 +24,6 @@ "storage": {} } }, - "rlp" : "0xf9033bf9012fa0c9cb614fddd89b3bc6e2f0ed1f8e58e8a0d826612a607a6151be6f39c991a941a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0b3ef9fe736086bdf1b3cd235f68097aab5f4c6e40d57f417d39c2cc6fb67f6c7a02cb4068eb8ccc9124426a7ed5c445b1353c997fc419031254ff7e2768c4dcd7fa08fd35225dd530f30dc39719f9791583309b5889ad79bff0d31e9b1eb12f55000b840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008301ff8001830f3e6f8212c38454d8bd7e80a062778f62183098b7cc8d221fc199654e613ca47b85696f940de3bd2bb6a2a54ef90205f90202808609184e72a000830f3e6f8080b901ae60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b561ba0d4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89a0ae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942c0", "transactions" : [ { "data" : "", diff --git a/block.cpp b/block.cpp index 9b598bbca..f72e7001d 100644 --- a/block.cpp +++ b/block.cpp @@ -70,87 +70,175 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) if (_fillin == false) { - // TODO + BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); - // BOOST_REQUIRE(o.count("rlp") > 0); - // const bytes rlpReaded = importByteArray(o["rlp"].get_str()); - // RLP myRLP(rlpReaded); - // BlockInfo blockFromRlp; - - // try - // { - // blockFromRlp.populateFromHeader(myRLP, false); - // //blockFromRlp.verifyInternals(rlpReaded); - // } - // catch(Exception const& _e) - // { - // cnote << "block construction did throw an exception: " << diagnostic_information(_e); - // BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - // BOOST_CHECK_MESSAGE(o.count("block") == 0, "A block object should not be defined because the block RLP is invalid!"); - // return; - // } - - // BOOST_REQUIRE(o.count("block") > 0); - - // mObject tObj = o["block"].get_obj(); - // BlockInfo blockFromFields; - // const bytes rlpreade2 = createBlockRLPFromFields(tObj); - // RLP mysecondRLP(rlpreade2); - // blockFromFields.populateFromHeader(mysecondRLP, false); - - // //Check the fields restored from RLP to original fields - // BOOST_CHECK_MESSAGE(blockFromFields.hash == blockFromRlp.hash, "hash in given RLP not matching the block hash!"); - // BOOST_CHECK_MESSAGE(blockFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); - // BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); - // BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); - // BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); - // BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); - // BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); - // BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); - // BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); - // BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); - // BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); - // BOOST_CHECK_MESSAGE(blockFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); - // BOOST_CHECK_MESSAGE(blockFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); - // BOOST_CHECK_MESSAGE(blockFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); - - // BOOST_CHECK_MESSAGE(blockFromFields == blockFromRlp, "However, blockFromFields != blockFromRlp!"); - - } - else - { - BOOST_REQUIRE(o.count("block") > 0); - - // construct Rlp of the given block - bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj()); + // construct RLP of the genesis block + bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); RLP myRLP(blockRLP); BlockInfo blockFromFields; - cout << "blockFromFields diff:" << blockFromFields.difficulty << endl; try { - blockFromFields.populateFromHeader(myRLP, false); - //blockFromFields.verifyInternals(blockRLP); } catch (Exception const& _e) { cnote << "block construction did throw an exception: " << diagnostic_information(_e); BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - o.erase(o.find("block")); + return; } catch (std::exception const& _e) { cnote << "block construction did throw an exception: " << _e.what(); BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - o.erase(o.find("block")); + return; } catch(...) { cnote << "block construction did throw an unknown exception\n"; - o.erase(o.find("block")); + return; } + BOOST_REQUIRE(o.count("pre") > 0); + + ImportTest importer(o["pre"].get_obj()); + State theState(Address(), OverlayDB(), BaseState::Empty); + importer.importState(o["pre"].get_obj(), theState); + + // commit changes to DB + theState.commit(); + + BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == theState.rootHash(), "root hash do not match"); + cout << "root hash - no fill in : " << theState.rootHash() << endl; + cout << "root hash - no fill in - from block: " << blockFromFields.stateRoot << endl; + + // create new "genesis" block + RLPStream rlpStream; + blockFromFields.streamRLP(rlpStream, WithNonce); + + RLPStream block(3); + block.appendRaw(rlpStream.out()); + block.appendRaw(RLPEmptyList); + block.appendRaw(RLPEmptyList); + + blockFromFields.verifyInternals(&block.out()); + + // construc blockchain + BlockChain bc(block.out(), string(), true); + + try + { + theState.sync(bc); + bytes blockRLP = importByteArray(o["rlp"].get_str()); + cout << "import block rlp\n"; + bc.import(blockRLP, theState.db()); + cout << "sync with the state\n"; + theState.sync(bc); + } + // if exception is thrown, RLP is invalid and not blockHeader, Transaction list, and Uncle list should be given + catch (Exception const& _e) + { + cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e); + BOOST_CHECK(o.count("blockHeader") == 0); + BOOST_CHECK(o.count("transactions") == 0); + BOOST_CHECK(o.count("uncleHeaders") == 0); + } + catch (std::exception const& _e) + { + cnote << "state sync or block import did throw an exception: " << _e.what(); + BOOST_CHECK(o.count("blockHeader") == 0); + BOOST_CHECK(o.count("transactions") == 0); + BOOST_CHECK(o.count("uncleHeaders") == 0); + } + catch(...) + { + cnote << "state sync or block import did throw an exception\n"; + BOOST_CHECK(o.count("blockHeader") == 0); + BOOST_CHECK(o.count("transactions") == 0); + BOOST_CHECK(o.count("uncleHeaders") == 0); + } + + + // if yes, check parameters in blockHeader + // check transaction list + // check uncle list + + BOOST_REQUIRE(o.count("blockHeader") > 0); + + mObject tObj = o["blockHeader"].get_obj(); + BlockInfo blockHeaderFromFields; + const bytes rlpBytesBlockHeader = createBlockRLPFromFields(tObj); + RLP blockHeaderRLP(rlpBytesBlockHeader); + blockHeaderFromFields.populateFromHeader(blockHeaderRLP, false); + + BlockInfo blockFromRlp = bc.info(); + + cout << "root hash - no fill in - from state : " << theState.rootHash() << endl; + cout << " hash - no fill in - from rlp : " << blockFromRlp.hash << endl; + cout << " hash - no fill in - from block: " << blockHeaderFromFields.hash << endl; + + //Check the fields restored from RLP to original fields + BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash() == blockFromRlp.headerHash(), "hash in given RLP not matching the block hash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); + + BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); + + } + else + { + BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); + + // construct RLP of the genesis block + bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); + RLP myRLP(blockRLP); + BlockInfo blockFromFields; + + try + { + blockFromFields.populateFromHeader(myRLP, false); + } + catch (Exception const& _e) + { + cnote << "block construction did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + return; + } + catch (std::exception const& _e) + { + cnote << "block construction did throw an exception: " << _e.what(); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + return; + } + catch(...) + { + cnote << "block construction did throw an unknown exception\n"; + return; + } + + BOOST_REQUIRE(o.count("pre") > 0); + + ImportTest importer(o["pre"].get_obj()); + State theState(Address(), OverlayDB(), BaseState::Empty); + importer.importState(o["pre"].get_obj(), theState); + + // commit changes to DB + theState.commit(); + + + // fillin specific --- start + BOOST_REQUIRE(o.count("transactions") > 0); TransactionQueue txs; @@ -167,32 +255,27 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(tx.count("r") > 0); BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("data") > 0); - cout << "attempt to import transaction\n"; - txs.attemptImport(createTransactionFromFields(tx)); + + if (!txs.attemptImport(createTransactionFromFields(tx))) + cnote << "failed importing transaction\n"; } - cout << "done importing txs\n"; - BOOST_REQUIRE(o.count("pre") > 0); - // create state - - ImportTest importer(o["pre"].get_obj()); - State theState(Address(), OverlayDB(), BaseState::Empty); - importer.importState(o["pre"].get_obj(), theState); - - cout << "current state diff 1 : " << theState.info().difficulty << endl; - cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; - theState.commit(); - cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; + // update stateRootHash blockFromFields.stateRoot = theState.rootHash(); - cout << "stateRoot: " << blockFromFields.stateRoot << endl; + cout << "root hash1: " << theState.rootHash() << endl; - // find new nonce + // find new valid nonce ProofOfWork pow; MineInfo ret; tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, false); + //---stop - // create new "genesis" block" + //update genesis block in json file + o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot); + o["genesisBlockHeader"].get_obj()["nonce"] = toString(blockFromFields.nonce); + + // create new "genesis" block RLPStream rlpStream; blockFromFields.streamRLP(rlpStream, WithNonce); @@ -200,46 +283,35 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) block.appendRaw(rlpStream.out()); block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); - //return block.out(); - cout << "my genesis hash: " << sha3(RLP(block.out())[0].data()) << endl; - cout << "construct bc\n"; - BlockChain bc(block.out(), std::string(), true); - cout << "pre difficulty: " << blockFromFields.difficulty << endl; + blockFromFields.verifyInternals(&block.out()); + + // construct blockchain + BlockChain bc(block.out(), string(), true); + + try { - //cout << "sync state with pre block" << endl; theState.sync(bc); - cout << "sync bc and txs in state\n"; - cout << "balance of a94f5374fce5edbc8e2a8697c15331677e6ebf0b: " << theState.balance(Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) << endl; - cout << "current state diff: " << theState.info().difficulty << endl; + cout << "root hash2: " << theState.rootHash() << endl; theState.sync(bc,txs); - cout << "current state diff: " << theState.info().difficulty << endl; - // lock - cout << "commit to mine\n"; - theState.commitToMine(bc); // will call uncommitToMine if a repeat. - cout << "current state diff: " << theState.info().difficulty << endl; - // unlock + cout << "root hash3: " << theState.rootHash() << endl; + theState.commitToMine(bc); + cout << "root hash4: " << theState.rootHash() << endl; MineInfo info; - cout << "mine...\n"; for (info.completed = false; !info.completed; info = theState.mine()) {} - cout << "done mining, completeMine\n"; - // lock + cout << "root hash5: " << theState.rootHash() << endl; theState.completeMine(); - cout << "current state diff: " << theState.info().difficulty << endl; - // unlock - - cout << "new block: " << theState.blockData() << endl << theState.info() << endl; - cout << "current diff: " << theState.info().difficulty << endl; + cout << "root hash6: " << theState.rootHash() << endl; } catch (Exception const& _e) { - cnote << "state sync did throw an exception: " << diagnostic_information(_e); + cnote << "state sync or mining did throw an exception: " << diagnostic_information(_e); } catch (std::exception const& _e) { - cnote << "state sync did throw an exception: " << _e.what(); + cnote << "state sync or mining did throw an exception: " << _e.what(); } o["rlp"] = "0x" + toHex(theState.blockData()); @@ -267,7 +339,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // write uncle list - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. That will change. + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. o["uncleHeaders"] = aUncleList; } } @@ -278,53 +350,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(BlockTests) -//BOOST_AUTO_TEST_CASE(blFirstTest) -//{ -// dev::test::executeTests("blFirstTest", "/BlockTests", dev::test::doBlockTests); -//} - BOOST_AUTO_TEST_CASE(blValidBlockTest) { dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); } -//BOOST_AUTO_TEST_CASE(ttCreateTest) -//{ -// for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) -// { -// string arg = boost::unit_test::framework::master_test_suite().argv[i]; -// if (arg == "--createtest") -// { -// if (boost::unit_test::framework::master_test_suite().argc <= i + 2) -// { -// cnote << "usage: ./testeth --createtest \n"; -// return; -// } -// try -// { -// cnote << "Populating tests..."; -// json_spirit::mValue v; -// string s = asString(dev::contents(boost::unit_test::framework::master_test_suite().argv[i + 1])); -// BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + (string)boost::unit_test::framework::master_test_suite().argv[i + 1] + " is empty."); -// json_spirit::read_string(s, v); -// dev::test::doBlockTests(v, true); -// writeFile(boost::unit_test::framework::master_test_suite().argv[i + 2], asBytes(json_spirit::write_string(v, true))); -// } -// catch (Exception const& _e) -// { -// BOOST_ERROR("Failed block test with Exception: " << diagnostic_information(_e)); -// } -// catch (std::exception const& _e) -// { -// BOOST_ERROR("Failed block test with Exception: " << _e.what()); -// } -// } -// } -//} - -//BOOST_AUTO_TEST_CASE(userDefinedFileTT) -//{ -// dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); -//} +BOOST_AUTO_TEST_CASE(userDefinedFileBl) +{ + dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); +} BOOST_AUTO_TEST_SUITE_END() From f0b2d0f30b2233509ea520984fdde174692f6cfb Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 11 Feb 2015 16:36:00 +0100 Subject: [PATCH 08/20] check transactions --- TestHelper.cpp | 59 +++++++++++++++--------- TestHelper.h | 2 +- blValidBlockTestFiller.json | 2 +- block.cpp | 91 +++++++++++++++++++++++++++++-------- transaction.cpp | 44 ------------------ 5 files changed, 113 insertions(+), 85 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 43e6106da..ec284d480 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -504,31 +504,48 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun } } -bytes createTransactionFromFields(json_spirit::mObject& _tObj) +RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj) { - BOOST_REQUIRE(_tObj.count("data") > 0); - BOOST_REQUIRE(_tObj.count("value") > 0); - BOOST_REQUIRE(_tObj.count("gasPrice") > 0); - BOOST_REQUIRE(_tObj.count("gasLimit") > 0); - BOOST_REQUIRE(_tObj.count("nonce")> 0); - BOOST_REQUIRE(_tObj.count("to") > 0); - - BOOST_REQUIRE(_tObj.count("v") > 0); - BOOST_REQUIRE(_tObj.count("r") > 0); - BOOST_REQUIRE(_tObj.count("s") > 0); - //Construct Rlp of the given transaction RLPStream rlpStream; - rlpStream.appendList(9); - rlpStream << bigint(_tObj["nonce"].get_str()) << bigint(_tObj["gasPrice"].get_str()) << bigint(_tObj["gasLimit"].get_str()); - if (_tObj["to"].get_str().empty()) - rlpStream << ""; - else - rlpStream << Address(_tObj["to"].get_str()); - rlpStream << bigint(_tObj["value"].get_str()) << importData(_tObj); - rlpStream << bigint(_tObj["v"].get_str()) << bigint(_tObj["r"].get_str()) << bigint(_tObj["s"].get_str()); + rlpStream.appendList(_tObj.size()); - return rlpStream.out(); + if (_tObj.count("nonce") > 0) + rlpStream << bigint(_tObj["nonce"].get_str()); + + if (_tObj.count("gasPrice") > 0) + rlpStream << bigint(_tObj["gasPrice"].get_str()); + + if (_tObj.count("gasLimit") > 0) + rlpStream << bigint(_tObj["gasLimit"].get_str()); + + if (_tObj.count("to") > 0) + { + if (_tObj["to"].get_str().empty()) + rlpStream << ""; + else + rlpStream << importByteArray(_tObj["to"].get_str()); + } + + if (_tObj.count("value") > 0) + rlpStream << bigint(_tObj["value"].get_str()); + + if (_tObj.count("data") > 0) + rlpStream << importData(_tObj); + + if (_tObj.count("v") > 0) + rlpStream << bigint(_tObj["v"].get_str()); + + if (_tObj.count("r") > 0) + rlpStream << bigint(_tObj["r"].get_str()); + + if (_tObj.count("s") > 0) + rlpStream << bigint(_tObj["s"].get_str()); + + if (_tObj.count("extrafield") > 0) + rlpStream << bigint(_tObj["extrafield"].get_str()); + + return rlpStream; } diff --git a/TestHelper.h b/TestHelper.h index 9ac1f0d4d..f7df3a2c0 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -80,7 +80,7 @@ void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _e void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function doTests); std::string getTestPath(); void userDefinedTest(std::string testTypeFlag, std::function doTests); -bytes createTransactionFromFields(json_spirit::mObject& _tObj); +RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj); void processCommandLineOptions(); eth::LastHashes lastHashes(u256 _currentBlockNumber); diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index 75ad8452e..99f1d32af 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -19,7 +19,7 @@ "pre" : { "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { "balance" : "10000000000", - "nonce" : 0, + "nonce" : "0", "code" : "", "storage": {} } diff --git a/block.cpp b/block.cpp index f72e7001d..5d9192a26 100644 --- a/block.cpp +++ b/block.cpp @@ -53,10 +53,11 @@ bytes createBlockRLPFromFields(mObject& _tObj) rlpStream.appendList(14); cout << "increate aha1\n"; rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); - rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << Address(_tObj["receiptTrie"].get_str()); + rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << h256(_tObj["receiptTrie"].get_str()); rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); + cout << "done createBlockRLPFromFields" << endl; return rlpStream.out(); } @@ -105,12 +106,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) State theState(Address(), OverlayDB(), BaseState::Empty); importer.importState(o["pre"].get_obj(), theState); - // commit changes to DB + // commit changes to DB theState.commit(); BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == theState.rootHash(), "root hash do not match"); - cout << "root hash - no fill in : " << theState.rootHash() << endl; - cout << "root hash - no fill in - from block: " << blockFromFields.stateRoot << endl; // create new "genesis" block RLPStream rlpStream; @@ -123,17 +122,15 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) blockFromFields.verifyInternals(&block.out()); - // construc blockchain + // construct blockchain BlockChain bc(block.out(), string(), true); try { theState.sync(bc); - bytes blockRLP = importByteArray(o["rlp"].get_str()); - cout << "import block rlp\n"; + bytes blockRLP = importByteArray(o["rlp"].get_str()); bc.import(blockRLP, theState.db()); - cout << "sync with the state\n"; - theState.sync(bc); + theState.sync(bc); } // if exception is thrown, RLP is invalid and not blockHeader, Transaction list, and Uncle list should be given catch (Exception const& _e) @@ -173,18 +170,15 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BlockInfo blockFromRlp = bc.info(); - cout << "root hash - no fill in - from state : " << theState.rootHash() << endl; - cout << " hash - no fill in - from rlp : " << blockFromRlp.hash << endl; - cout << " hash - no fill in - from block: " << blockHeaderFromFields.hash << endl; - //Check the fields restored from RLP to original fields - BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash() == blockFromRlp.headerHash(), "hash in given RLP not matching the block hash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); @@ -195,6 +189,65 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); + //Check transaction list + + Transactions txsFromField; + + for (auto const& txObj: o["transactions"].get_array()) + { + mObject tx = txObj.get_obj(); + BOOST_REQUIRE(tx.count("nonce") > 0); + BOOST_REQUIRE(tx.count("gasPrice") > 0); + BOOST_REQUIRE(tx.count("gasLimit") > 0); + BOOST_REQUIRE(tx.count("to") > 0); + BOOST_REQUIRE(tx.count("value") > 0); + BOOST_REQUIRE(tx.count("v") > 0); + BOOST_REQUIRE(tx.count("r") > 0); + BOOST_REQUIRE(tx.count("s") > 0); + BOOST_REQUIRE(tx.count("data") > 0); + + Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); + txsFromField.push_back(t); + } + + Transactions txsFromRlp; + bytes blockRLP2 = importByteArray(o["rlp"].get_str()); + RLP root(blockRLP2); + for (auto const& tr: root[1]) + { + Transaction tx(tr.data(), CheckSignature::Sender); + txsFromRlp.push_back(tx); + } + + cout << "size of pending transactions: " << txsFromRlp.size() << endl; + + BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); + + for (size_t i = 0; i < txsFromField.size(); ++i) + { + BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); + + BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "however, transactions in rlp and in field do not match"); + } + + // check uncle list + + BOOST_CHECK_MESSAGE(o["uncleList"].get_array().size() == 0, "Uncle list is not empty, but the genesis block can not have uncles"); + + + + + + + } else { @@ -256,7 +309,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("data") > 0); - if (!txs.attemptImport(createTransactionFromFields(tx))) + //Transaction txFromFields(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); + + if (!txs.attemptImport(&createRLPStreamFromTransactionFields(tx).out())) cnote << "failed importing transaction\n"; } @@ -339,8 +394,8 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // write uncle list - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. - o["uncleHeaders"] = aUncleList; + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. + o["uncleHeaders"] = aUncleList; } } } diff --git a/transaction.cpp b/transaction.cpp index 6a1aa0d84..7ced5a6f4 100644 --- a/transaction.cpp +++ b/transaction.cpp @@ -29,50 +29,6 @@ using namespace dev::eth; namespace dev { namespace test { -RLPStream createRLPStreamFromTransactionFields(mObject& _tObj) -{ - //Construct Rlp of the given transaction - RLPStream rlpStream; - rlpStream.appendList(_tObj.size()); - - if (_tObj.count("nonce") > 0) - rlpStream << bigint(_tObj["nonce"].get_str()); - - if (_tObj.count("gasPrice") > 0) - rlpStream << bigint(_tObj["gasPrice"].get_str()); - - if (_tObj.count("gasLimit") > 0) - rlpStream << bigint(_tObj["gasLimit"].get_str()); - - if (_tObj.count("to") > 0) - { - if (_tObj["to"].get_str().empty()) - rlpStream << ""; - else - rlpStream << importByteArray(_tObj["to"].get_str()); - } - - if (_tObj.count("value") > 0) - rlpStream << bigint(_tObj["value"].get_str()); - - if (_tObj.count("data") > 0) - rlpStream << importData(_tObj); - - if (_tObj.count("v") > 0) - rlpStream << bigint(_tObj["v"].get_str()); - - if (_tObj.count("r") > 0) - rlpStream << bigint(_tObj["r"].get_str()); - - if (_tObj.count("s") > 0) - rlpStream << bigint(_tObj["s"].get_str()); - - if (_tObj.count("extrafield") > 0) - rlpStream << bigint(_tObj["extrafield"].get_str()); - - return rlpStream; -} - void doTransactionTests(json_spirit::mValue& _v, bool _fillin) { for (auto& i: _v.get_obj()) From 9e63ab10ca963f997cdf929dfb069ed42e1256a4 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 11 Feb 2015 18:17:01 +0100 Subject: [PATCH 09/20] avoid code doubling --- block.cpp | 472 +++++++++++++++++++++++------------------------------- 1 file changed, 202 insertions(+), 270 deletions(-) diff --git a/block.cpp b/block.cpp index 5d9192a26..bfc7c01d6 100644 --- a/block.cpp +++ b/block.cpp @@ -69,96 +69,183 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cerr << i.first << endl; mObject& o = i.second.get_obj(); - if (_fillin == false) - { - BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); + BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); - // construct RLP of the genesis block - bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); - RLP myRLP(blockRLP); - BlockInfo blockFromFields; + // construct RLP of the genesis block + bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); + RLP myRLP(blockRLP); + BlockInfo blockFromFields; - try - { - blockFromFields.populateFromHeader(myRLP, false); - } - catch (Exception const& _e) - { - cnote << "block construction did throw an exception: " << diagnostic_information(_e); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - return; - } - catch (std::exception const& _e) - { - cnote << "block construction did throw an exception: " << _e.what(); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - return; - } - catch(...) - { - cnote << "block construction did throw an unknown exception\n"; - return; - } + try + { + blockFromFields.populateFromHeader(myRLP, false); + } + catch (Exception const& _e) + { + cnote << "block construction did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + return; + } + catch (std::exception const& _e) + { + cnote << "block construction did throw an exception: " << _e.what(); + BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + return; + } + catch(...) + { + cnote << "block construction did throw an unknown exception\n"; + return; + } - BOOST_REQUIRE(o.count("pre") > 0); + BOOST_REQUIRE(o.count("pre") > 0); - ImportTest importer(o["pre"].get_obj()); - State theState(Address(), OverlayDB(), BaseState::Empty); - importer.importState(o["pre"].get_obj(), theState); + ImportTest importer(o["pre"].get_obj()); + State theState(Address(), OverlayDB(), BaseState::Empty); + importer.importState(o["pre"].get_obj(), theState); - // commit changes to DB - theState.commit(); + // commit changes to DB + theState.commit(); - BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == theState.rootHash(), "root hash do not match"); + if (_fillin) + blockFromFields.stateRoot = theState.rootHash(); + else + BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == theState.rootHash(), "root hash do not match"); - // create new "genesis" block - RLPStream rlpStream; - blockFromFields.streamRLP(rlpStream, WithNonce); + if (_fillin) + { + // find new valid nonce + ProofOfWork pow; + MineInfo ret; + tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, false); - RLPStream block(3); - block.appendRaw(rlpStream.out()); - block.appendRaw(RLPEmptyList); - block.appendRaw(RLPEmptyList); + //update genesis block in json file + o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot); + o["genesisBlockHeader"].get_obj()["nonce"] = toString(blockFromFields.nonce); + } - blockFromFields.verifyInternals(&block.out()); + // create new "genesis" block + RLPStream rlpStream; + blockFromFields.streamRLP(rlpStream, WithNonce); - // construct blockchain - BlockChain bc(block.out(), string(), true); + RLPStream block(3); + block.appendRaw(rlpStream.out()); + block.appendRaw(RLPEmptyList); + block.appendRaw(RLPEmptyList); - try - { - theState.sync(bc); - bytes blockRLP = importByteArray(o["rlp"].get_str()); + blockFromFields.verifyInternals(&block.out()); + + // construct blockchain + BlockChain bc(block.out(), string(), true); + + if (_fillin) + { + BOOST_REQUIRE(o.count("transactions") > 0); + + TransactionQueue txs; + + for (auto const& txObj: o["transactions"].get_array()) + { + mObject tx = txObj.get_obj(); + BOOST_REQUIRE(tx.count("nonce") > 0); + BOOST_REQUIRE(tx.count("gasPrice") > 0); + BOOST_REQUIRE(tx.count("gasLimit") > 0); + BOOST_REQUIRE(tx.count("to") > 0); + BOOST_REQUIRE(tx.count("value") > 0); + BOOST_REQUIRE(tx.count("v") > 0); + BOOST_REQUIRE(tx.count("r") > 0); + BOOST_REQUIRE(tx.count("s") > 0); + BOOST_REQUIRE(tx.count("data") > 0); + + //Transaction txFromFields(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); + + if (!txs.attemptImport(&createRLPStreamFromTransactionFields(tx).out())) + cnote << "failed importing transaction\n"; + } + + try + { + theState.sync(bc); + theState.sync(bc,txs); + theState.commitToMine(bc); + MineInfo info; + for (info.completed = false; !info.completed; info = theState.mine()) {} + theState.completeMine(); + } + catch (Exception const& _e) + { + cnote << "state sync or mining did throw an exception: " << diagnostic_information(_e); + } + catch (std::exception const& _e) + { + cnote << "state sync or mining did throw an exception: " << _e.what(); + } + + o["rlp"] = "0x" + toHex(theState.blockData()); + + // write block header + + mObject oBlockHeader; + BlockInfo current_BlockHeader = theState.info(); + oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); + oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); + oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); + oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); + oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); + oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); + oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); + oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); + oBlockHeader["number"] = toString(current_BlockHeader.number); + oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); + oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); + oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); + oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); + oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); + + o["blockHeader"] = oBlockHeader; + + // write uncle list + + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. + o["uncleHeaders"] = aUncleList; + } + + else + { + try + { + theState.sync(bc); + bytes blockRLP = importByteArray(o["rlp"].get_str()); bc.import(blockRLP, theState.db()); - theState.sync(bc); - } + theState.sync(bc); + } // if exception is thrown, RLP is invalid and not blockHeader, Transaction list, and Uncle list should be given - catch (Exception const& _e) - { - cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e); + catch (Exception const& _e) + { + cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e); BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); - } - catch (std::exception const& _e) - { - cnote << "state sync or block import did throw an exception: " << _e.what(); + } + catch (std::exception const& _e) + { + cnote << "state sync or block import did throw an exception: " << _e.what(); BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); - } - catch(...) - { + } + catch(...) + { cnote << "state sync or block import did throw an exception\n"; - BOOST_CHECK(o.count("blockHeader") == 0); - BOOST_CHECK(o.count("transactions") == 0); - BOOST_CHECK(o.count("uncleHeaders") == 0); - } + BOOST_CHECK(o.count("blockHeader") == 0); + BOOST_CHECK(o.count("transactions") == 0); + BOOST_CHECK(o.count("uncleHeaders") == 0); + } - // if yes, check parameters in blockHeader - // check transaction list - // check uncle list + // if yes, check parameters in blockHeader + // check transaction list + // check uncle list BOOST_REQUIRE(o.count("blockHeader") > 0); @@ -171,14 +258,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BlockInfo blockFromRlp = bc.info(); //Check the fields restored from RLP to original fields - BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!"); - BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!"); + BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); @@ -189,215 +276,60 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); - //Check transaction list + //Check transaction list - Transactions txsFromField; + Transactions txsFromField; - for (auto const& txObj: o["transactions"].get_array()) - { - mObject tx = txObj.get_obj(); - BOOST_REQUIRE(tx.count("nonce") > 0); - BOOST_REQUIRE(tx.count("gasPrice") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); - BOOST_REQUIRE(tx.count("to") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("v") > 0); - BOOST_REQUIRE(tx.count("r") > 0); - BOOST_REQUIRE(tx.count("s") > 0); - BOOST_REQUIRE(tx.count("data") > 0); + for (auto const& txObj: o["transactions"].get_array()) + { + mObject tx = txObj.get_obj(); + BOOST_REQUIRE(tx.count("nonce") > 0); + BOOST_REQUIRE(tx.count("gasPrice") > 0); + BOOST_REQUIRE(tx.count("gasLimit") > 0); + BOOST_REQUIRE(tx.count("to") > 0); + BOOST_REQUIRE(tx.count("value") > 0); + BOOST_REQUIRE(tx.count("v") > 0); + BOOST_REQUIRE(tx.count("r") > 0); + BOOST_REQUIRE(tx.count("s") > 0); + BOOST_REQUIRE(tx.count("data") > 0); - Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); - txsFromField.push_back(t); - } + Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); + txsFromField.push_back(t); + } - Transactions txsFromRlp; - bytes blockRLP2 = importByteArray(o["rlp"].get_str()); - RLP root(blockRLP2); - for (auto const& tr: root[1]) - { - Transaction tx(tr.data(), CheckSignature::Sender); - txsFromRlp.push_back(tx); - } + Transactions txsFromRlp; + bytes blockRLP2 = importByteArray(o["rlp"].get_str()); + RLP root(blockRLP2); + for (auto const& tr: root[1]) + { + Transaction tx(tr.data(), CheckSignature::Sender); + txsFromRlp.push_back(tx); + } - cout << "size of pending transactions: " << txsFromRlp.size() << endl; + cout << "size of pending transactions: " << txsFromRlp.size() << endl; - BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); + BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); - for (size_t i = 0; i < txsFromField.size(); ++i) - { - BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); + for (size_t i = 0; i < txsFromField.size(); ++i) + { + BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "however, transactions in rlp and in field do not match"); - } - - // check uncle list + BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "however, transactions in rlp and in field do not match"); + } - BOOST_CHECK_MESSAGE(o["uncleList"].get_array().size() == 0, "Uncle list is not empty, but the genesis block can not have uncles"); + // check uncle list - - - - - - - } - else - { - BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); - - // construct RLP of the genesis block - bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); - RLP myRLP(blockRLP); - BlockInfo blockFromFields; - - try - { - blockFromFields.populateFromHeader(myRLP, false); - } - catch (Exception const& _e) - { - cnote << "block construction did throw an exception: " << diagnostic_information(_e); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - return; - } - catch (std::exception const& _e) - { - cnote << "block construction did throw an exception: " << _e.what(); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); - return; - } - catch(...) - { - cnote << "block construction did throw an unknown exception\n"; - return; - } - - BOOST_REQUIRE(o.count("pre") > 0); - - ImportTest importer(o["pre"].get_obj()); - State theState(Address(), OverlayDB(), BaseState::Empty); - importer.importState(o["pre"].get_obj(), theState); - - // commit changes to DB - theState.commit(); - - - // fillin specific --- start - - BOOST_REQUIRE(o.count("transactions") > 0); - - TransactionQueue txs; - - for (auto const& txObj: o["transactions"].get_array()) - { - mObject tx = txObj.get_obj(); - BOOST_REQUIRE(tx.count("nonce") > 0); - BOOST_REQUIRE(tx.count("gasPrice") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); - BOOST_REQUIRE(tx.count("to") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("v") > 0); - BOOST_REQUIRE(tx.count("r") > 0); - BOOST_REQUIRE(tx.count("s") > 0); - BOOST_REQUIRE(tx.count("data") > 0); - - //Transaction txFromFields(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); - - if (!txs.attemptImport(&createRLPStreamFromTransactionFields(tx).out())) - cnote << "failed importing transaction\n"; - } - - // update stateRootHash - blockFromFields.stateRoot = theState.rootHash(); - cout << "root hash1: " << theState.rootHash() << endl; - - // find new valid nonce - ProofOfWork pow; - MineInfo ret; - tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, false); - //---stop - - //update genesis block in json file - o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot); - o["genesisBlockHeader"].get_obj()["nonce"] = toString(blockFromFields.nonce); - - - // create new "genesis" block - RLPStream rlpStream; - blockFromFields.streamRLP(rlpStream, WithNonce); - - RLPStream block(3); - block.appendRaw(rlpStream.out()); - block.appendRaw(RLPEmptyList); - block.appendRaw(RLPEmptyList); - - blockFromFields.verifyInternals(&block.out()); - - // construct blockchain - BlockChain bc(block.out(), string(), true); - - - - try - { - theState.sync(bc); - cout << "root hash2: " << theState.rootHash() << endl; - theState.sync(bc,txs); - cout << "root hash3: " << theState.rootHash() << endl; - theState.commitToMine(bc); - cout << "root hash4: " << theState.rootHash() << endl; - MineInfo info; - for (info.completed = false; !info.completed; info = theState.mine()) {} - cout << "root hash5: " << theState.rootHash() << endl; - theState.completeMine(); - cout << "root hash6: " << theState.rootHash() << endl; - } - catch (Exception const& _e) - { - cnote << "state sync or mining did throw an exception: " << diagnostic_information(_e); - } - catch (std::exception const& _e) - { - cnote << "state sync or mining did throw an exception: " << _e.what(); - } - - o["rlp"] = "0x" + toHex(theState.blockData()); - - // write block header - - mObject oBlockHeader; - BlockInfo current_BlockHeader = theState.info(); - oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); - oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); - oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); - oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); - oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); - oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); - oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); - oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); - oBlockHeader["number"] = toString(current_BlockHeader.number); - oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); - oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); - oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); - oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); - oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); - - o["blockHeader"] = oBlockHeader; - - // write uncle list - - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. - o["uncleHeaders"] = aUncleList; - } - } + BOOST_CHECK_MESSAGE((o["uncleList"].type() == json_spirit::null_type ? 0 : o["uncleList"].get_array().size()) == 0, "Uncle list is not empty, but the genesis block can not have uncles"); + } + } } } }// Namespace Close From 0e634cb1fc3d80abcdeaf4c4cb6d31e8464693ed Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 11 Feb 2015 22:05:34 +0100 Subject: [PATCH 10/20] style --- block.cpp | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/block.cpp b/block.cpp index bfc7c01d6..88f7de634 100644 --- a/block.cpp +++ b/block.cpp @@ -48,16 +48,13 @@ bytes createBlockRLPFromFields(mObject& _tObj) BOOST_REQUIRE(_tObj.count("nonce") > 0); // construct RLP of the given block - cout << "done with require\n"; RLPStream rlpStream; rlpStream.appendList(14); - cout << "increate aha1\n"; rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << h256(_tObj["receiptTrie"].get_str()); rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); - cout << "done createBlockRLPFromFields" << endl; return rlpStream.out(); } @@ -72,45 +69,44 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); // construct RLP of the genesis block - bytes blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); - RLP myRLP(blockRLP); + const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); BlockInfo blockFromFields; try { - blockFromFields.populateFromHeader(myRLP, false); + blockFromFields.populateFromHeader(c_bRLP, false); } catch (Exception const& _e) { - cnote << "block construction did throw an exception: " << diagnostic_information(_e); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + cnote << "block population did throw an exception: " << diagnostic_information(_e); + BOOST_ERROR("Failed block population with Exception: " << _e.what()); return; } catch (std::exception const& _e) { - cnote << "block construction did throw an exception: " << _e.what(); - BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); + BOOST_ERROR("Failed block population with Exception: " << _e.what()); return; } catch(...) { - cnote << "block construction did throw an unknown exception\n"; + cnote << "block population did throw an unknown exception\n"; return; } BOOST_REQUIRE(o.count("pre") > 0); ImportTest importer(o["pre"].get_obj()); - State theState(Address(), OverlayDB(), BaseState::Empty); - importer.importState(o["pre"].get_obj(), theState); + State state(Address(), OverlayDB(), BaseState::Empty); + importer.importState(o["pre"].get_obj(), state); // commit changes to DB - theState.commit(); + state.commit(); if (_fillin) - blockFromFields.stateRoot = theState.rootHash(); + blockFromFields.stateRoot = state.rootHash(); else - BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == theState.rootHash(), "root hash do not match"); + BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == state.rootHash(), "root hash does not match"); if (_fillin) { @@ -165,12 +161,12 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) try { - theState.sync(bc); - theState.sync(bc,txs); - theState.commitToMine(bc); + state.sync(bc); + state.sync(bc,txs); + state.commitToMine(bc); MineInfo info; - for (info.completed = false; !info.completed; info = theState.mine()) {} - theState.completeMine(); + for (info.completed = false; !info.completed; info = state.mine()) {} + state.completeMine(); } catch (Exception const& _e) { @@ -181,12 +177,12 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cnote << "state sync or mining did throw an exception: " << _e.what(); } - o["rlp"] = "0x" + toHex(theState.blockData()); + o["rlp"] = "0x" + toHex(state.blockData()); // write block header mObject oBlockHeader; - BlockInfo current_BlockHeader = theState.info(); + BlockInfo current_BlockHeader = state.info(); oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); @@ -214,10 +210,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) { try { - theState.sync(bc); + state.sync(bc); bytes blockRLP = importByteArray(o["rlp"].get_str()); - bc.import(blockRLP, theState.db()); - theState.sync(bc); + bc.import(blockRLP, state.db()); + state.sync(bc); } // if exception is thrown, RLP is invalid and not blockHeader, Transaction list, and Uncle list should be given catch (Exception const& _e) From f3e9c325d1160b11d0bde3185d7a6181ee13bffa Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 12 Feb 2015 20:13:44 +0100 Subject: [PATCH 11/20] add valid tx output --- blFirstTestFiller.json | 32 ------ blValidBlockTestFiller.json | 187 +++++++++++++++++++++++++++++++++++- block.cpp | 122 +++++++++++++++-------- 3 files changed, 266 insertions(+), 75 deletions(-) delete mode 100644 blFirstTestFiller.json diff --git a/blFirstTestFiller.json b/blFirstTestFiller.json deleted file mode 100644 index d4e6d109f..000000000 --- a/blFirstTestFiller.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "firstBlockTest" : { - "block" : { - "parentHash": "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", - "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1", - "stateRoot": "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty": "023101", - "number": "62", - "gasLimit": "0x0dddb6", - "gasUsed": "100", - "timestamp": "0x54c98c81", - "extraData": "42", - "nonce": "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" - }, - "pre" : {}, - "transactions": [{ - "nonce": "0", - "gasPrice": "0x09184e72a000", - "gasLimit": "0x0f3e6f", - "to": "", - "value": "", - "data": "0x60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b56", - "v": "0x1b", - "r": "0xd4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89", - "s": "0xae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942" - }] - } -} diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index 99f1d32af..da2625ea6 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,12 +1,12 @@ { - "lowGasLimitBoundary" : { + "diffTooLow" : { "genesisBlockHeader" : { "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", + "difficulty" : "1023", "extraData" : "42", "gasLimit" : "100000", - "gasUsed" : "100", + "gasUsed" : "0", "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", "number" : "0", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -39,6 +39,187 @@ ], "uncleHeaders" : [ ] + }, + + "diff1024" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1024", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "gasPrice0" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "0", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "tx" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "0", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "txOrder" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "7000000000" + }, + + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", + "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "v" : "27", + "value" : "1000000000" + }, + + ], + "uncleHeaders" : [ + ] } } diff --git a/block.cpp b/block.cpp index 88f7de634..c701cb979 100644 --- a/block.cpp +++ b/block.cpp @@ -32,29 +32,50 @@ namespace dev { namespace test { bytes createBlockRLPFromFields(mObject& _tObj) { - BOOST_REQUIRE(_tObj.count("parentHash") > 0); - BOOST_REQUIRE(_tObj.count("uncleHash") > 0); - BOOST_REQUIRE(_tObj.count("coinbase") > 0); - BOOST_REQUIRE(_tObj.count("stateRoot") > 0); - BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0); - BOOST_REQUIRE(_tObj.count("receiptTrie") > 0); - BOOST_REQUIRE(_tObj.count("bloom") > 0); - BOOST_REQUIRE(_tObj.count("difficulty") > 0); - BOOST_REQUIRE(_tObj.count("number") > 0); - BOOST_REQUIRE(_tObj.count("gasLimit")> 0); - BOOST_REQUIRE(_tObj.count("gasUsed") > 0); - BOOST_REQUIRE(_tObj.count("timestamp") > 0); - BOOST_REQUIRE(_tObj.count("extraData") > 0); - BOOST_REQUIRE(_tObj.count("nonce") > 0); - - // construct RLP of the given block RLPStream rlpStream; - rlpStream.appendList(14); - rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); - rlpStream << h256(_tObj["stateRoot"].get_str()) << h256(_tObj["transactionsTrie"].get_str()) << h256(_tObj["receiptTrie"].get_str()); - rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].get_str()); - rlpStream << u256(_tObj["gasLimit"].get_str()) << u256(_tObj["gasUsed"].get_str()) << u256(_tObj["timestamp"].get_str()); - rlpStream << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str()); + rlpStream.appendList(_tObj.size()); + + if (_tObj.count("parentHash") > 0) + rlpStream << importByteArray(_tObj["parentHash"].get_str()); + + if (_tObj.count("uncleHash") > 0) + rlpStream << importByteArray(_tObj["uncleHash"].get_str()); + + if (_tObj.count("coinbase") > 0) + rlpStream << importByteArray(_tObj["coinbase"].get_str()); + + if (_tObj.count("stateRoot") > 0) + rlpStream << importByteArray(_tObj["stateRoot"].get_str()); + + if (_tObj.count("transactionsTrie") > 0) + rlpStream << importByteArray(_tObj["transactionsTrie"].get_str()); + + if (_tObj.count("receiptTrie") > 0) + rlpStream << importByteArray(_tObj["receiptTrie"].get_str()); + + if (_tObj.count("bloom") > 0) + rlpStream << importByteArray(_tObj["bloom"].get_str()); + + if (_tObj.count("difficulty") > 0) + rlpStream << bigint(_tObj["difficulty"].get_str()); + + if (_tObj.count("number") > 0) + rlpStream << bigint(_tObj["number"].get_str()); + + if (_tObj.count("gasLimit") > 0) + rlpStream << bigint(_tObj["gasLimit"].get_str()); + + if (_tObj.count("gasUsed") > 0) + rlpStream << bigint(_tObj["gasUsed"].get_str()); + + if (_tObj.count("timestamp") > 0) + rlpStream << bigint(_tObj["timestamp"].get_str()); + + if (_tObj.count("extraData") > 0) + rlpStream << importByteArray(_tObj["extraData"].get_str()); + + if (_tObj.count("nonce") > 0) + rlpStream << importByteArray(_tObj["nonce"].get_str()); return rlpStream.out(); } @@ -67,6 +88,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) mObject& o = i.second.get_obj(); BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); + cout << "construc genesis\n"; // construct RLP of the genesis block const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); @@ -95,6 +117,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) } BOOST_REQUIRE(o.count("pre") > 0); + cout << "read state\n"; ImportTest importer(o["pre"].get_obj()); State state(Address(), OverlayDB(), BaseState::Empty); @@ -137,6 +160,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) if (_fillin) { BOOST_REQUIRE(o.count("transactions") > 0); + cout << "read transactions\n"; TransactionQueue txs; @@ -152,17 +176,18 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(tx.count("r") > 0); BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("data") > 0); - - //Transaction txFromFields(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); - + cout << "import tx\n"; if (!txs.attemptImport(&createRLPStreamFromTransactionFields(tx).out())) cnote << "failed importing transaction\n"; } try { - state.sync(bc); - state.sync(bc,txs); + cout << "sync state: " << state.sync(bc) << endl; + TransactionReceipts txReceipts = state.sync(bc,txs); + cout << "sync state done\n"; + //if (syncSuccess) + // throw Exception(); state.commitToMine(bc); MineInfo info; for (info.completed = false; !info.completed; info = state.mine()) {} @@ -171,12 +196,36 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) catch (Exception const& _e) { cnote << "state sync or mining did throw an exception: " << diagnostic_information(_e); + return; } catch (std::exception const& _e) { cnote << "state sync or mining did throw an exception: " << _e.what(); + return; } + // write valid txs + cout << "number of valid txs: " << txs.transactions().size(); + mArray txArray; + for (auto const& txi: txs.transactions()) + { + Transaction tx(txi.second, CheckSignature::Sender); + mObject txObject; + txObject["nonce"] = toString(tx.nonce()); + txObject["data"] = toHex(tx.data()); + txObject["gasLimit"] = toString(tx.gas()); + txObject["gasPrice"] = toString(tx.gasPrice()); + txObject["r"] = toString(tx.signature().r); + txObject["s"] = toString(tx.signature().s); + txObject["v"] = to_string(tx.signature().v + 27); + txObject["to"] = toString(tx.receiveAddress()); + txObject["value"] = toString(tx.value()); + + txArray.push_back(txObject); + } + + o["transactions"] = txArray; + o["rlp"] = "0x" + toHex(state.blockData()); // write block header @@ -215,7 +264,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) bc.import(blockRLP, state.db()); state.sync(bc); } - // if exception is thrown, RLP is invalid and not blockHeader, Transaction list, and Uncle list should be given + // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (Exception const& _e) { cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e); @@ -238,18 +287,13 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("uncleHeaders") == 0); } - - // if yes, check parameters in blockHeader - // check transaction list - // check uncle list - BOOST_REQUIRE(o.count("blockHeader") > 0); mObject tObj = o["blockHeader"].get_obj(); BlockInfo blockHeaderFromFields; - const bytes rlpBytesBlockHeader = createBlockRLPFromFields(tObj); - RLP blockHeaderRLP(rlpBytesBlockHeader); - blockHeaderFromFields.populateFromHeader(blockHeaderRLP, false); + const bytes c_rlpBytesBlockHeader = createBlockRLPFromFields(tObj); + const RLP c_blockHeaderRLP(c_rlpBytesBlockHeader); + blockHeaderFromFields.populateFromHeader(c_blockHeaderRLP, false); BlockInfo blockFromRlp = bc.info(); @@ -294,16 +338,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) } Transactions txsFromRlp; - bytes blockRLP2 = importByteArray(o["rlp"].get_str()); - RLP root(blockRLP2); + bytes blockRLP = importByteArray(o["rlp"].get_str()); + RLP root(blockRLP); for (auto const& tr: root[1]) { Transaction tx(tr.data(), CheckSignature::Sender); txsFromRlp.push_back(tx); } - cout << "size of pending transactions: " << txsFromRlp.size() << endl; - BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match"); for (size_t i = 0; i < txsFromField.size(); ++i) From fa5c4c8857803620b976e781a31d743e04a48f95 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 10:59:47 +0100 Subject: [PATCH 12/20] fix import transaction --- block.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/block.cpp b/block.cpp index c701cb979..69c236606 100644 --- a/block.cpp +++ b/block.cpp @@ -157,6 +157,8 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // construct blockchain BlockChain bc(block.out(), string(), true); + cout << "constructed bc\n"; + if (_fillin) { BOOST_REQUIRE(o.count("transactions") > 0); @@ -260,9 +262,13 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) try { state.sync(bc); + cout << "synced bc\n"; bytes blockRLP = importByteArray(o["rlp"].get_str()); + cout << "imported rlp bc\n"; bc.import(blockRLP, state.db()); + cout << "imported rlp to bc bc\n"; state.sync(bc); + cout << "synced state bc\n"; } // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (Exception const& _e) @@ -316,6 +322,8 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); + cout << "checked block header bc\n"; + //Check transaction list Transactions txsFromField; @@ -323,6 +331,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) for (auto const& txObj: o["transactions"].get_array()) { mObject tx = txObj.get_obj(); + + cout << "read single tx\n"; + BOOST_REQUIRE(tx.count("nonce") > 0); BOOST_REQUIRE(tx.count("gasPrice") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0); @@ -333,10 +344,25 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("data") > 0); - Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); - txsFromField.push_back(t); + cout << "construct single tx\n"; + try + { + Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); + txsFromField.push_back(t); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e)); + + } + catch (exception const& _e) + { + cout << _e.what() << endl; + } } + cout << "read txs bc\n"; + Transactions txsFromRlp; bytes blockRLP = importByteArray(o["rlp"].get_str()); RLP root(blockRLP); @@ -362,6 +388,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "however, transactions in rlp and in field do not match"); } + cout << "checked txs bc\n"; // check uncle list From 6902084231dbe9a3752afb167d7a6be07218f0cd Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 11:24:20 +0100 Subject: [PATCH 13/20] fix tx output --- block.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.cpp b/block.cpp index 69c236606..3544a3f8e 100644 --- a/block.cpp +++ b/block.cpp @@ -217,8 +217,8 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) txObject["data"] = toHex(tx.data()); txObject["gasLimit"] = toString(tx.gas()); txObject["gasPrice"] = toString(tx.gasPrice()); - txObject["r"] = toString(tx.signature().r); - txObject["s"] = toString(tx.signature().s); + txObject["r"] = "0x" + toString(tx.signature().r); + txObject["s"] = "0x" + toString(tx.signature().s); txObject["v"] = to_string(tx.signature().v + 27); txObject["to"] = toString(tx.receiveAddress()); txObject["value"] = toString(tx.value()); From 7abf1f6c93dd0d76404697cf780456fbd2875c8f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 12:38:38 +0100 Subject: [PATCH 14/20] switch to secretKey in fillers --- TestHelper.cpp | 1 - blValidBlockTestFiller.json | 84 +++++++++++++++++++++++++++---------- block.cpp | 24 ++--------- 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index ec284d480..907447aba 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -548,7 +548,6 @@ RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj) return rlpStream; } - void processCommandLineOptions() { auto argc = boost::unit_test::framework::master_test_suite().argc; diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index da2625ea6..d19c8104d 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -30,10 +30,8 @@ "gasLimit" : "850", "gasPrice" : "1", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", "value" : "10" } ], @@ -72,10 +70,8 @@ "gasLimit" : "850", "gasPrice" : "1", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", "value" : "10" } ], @@ -111,13 +107,11 @@ "transactions" : [ { "data" : "", - "gasLimit" : "500", + "gasLimit" : "850", "gasPrice" : "0", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", "value" : "10" } ], @@ -154,12 +148,10 @@ { "data" : "", "gasLimit" : "500", - "gasPrice" : "0", + "gasPrice" : "10", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", "value" : "10" } ], @@ -198,28 +190,74 @@ "gasLimit" : "500", "gasPrice" : "10", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", "value" : "7000000000" }, - { "data" : "", "gasLimit" : "500", "gasPrice" : "10", "nonce" : "0", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "27", - "value" : "1000000000" - }, + "value" : "8000000000" + } + ], + "uncleHeaders" : [ + ] + }, + "txEqualValue" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + }, + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "9", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } ], "uncleHeaders" : [ ] } + + + } diff --git a/block.cpp b/block.cpp index 3544a3f8e..2d44e8d71 100644 --- a/block.cpp +++ b/block.cpp @@ -169,27 +169,15 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) for (auto const& txObj: o["transactions"].get_array()) { mObject tx = txObj.get_obj(); - BOOST_REQUIRE(tx.count("nonce") > 0); - BOOST_REQUIRE(tx.count("gasPrice") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); - BOOST_REQUIRE(tx.count("to") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("v") > 0); - BOOST_REQUIRE(tx.count("r") > 0); - BOOST_REQUIRE(tx.count("s") > 0); - BOOST_REQUIRE(tx.count("data") > 0); - cout << "import tx\n"; - if (!txs.attemptImport(&createRLPStreamFromTransactionFields(tx).out())) + importer.importTransaction(tx); + if (!txs.attemptImport(importer.m_transaction.rlp())) cnote << "failed importing transaction\n"; } try { - cout << "sync state: " << state.sync(bc) << endl; - TransactionReceipts txReceipts = state.sync(bc,txs); - cout << "sync state done\n"; - //if (syncSuccess) - // throw Exception(); + state.sync(bc); + state.sync(bc,txs); state.commitToMine(bc); MineInfo info; for (info.completed = false; !info.completed; info = state.mine()) {} @@ -262,13 +250,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) try { state.sync(bc); - cout << "synced bc\n"; bytes blockRLP = importByteArray(o["rlp"].get_str()); - cout << "imported rlp bc\n"; bc.import(blockRLP, state.db()); - cout << "imported rlp to bc bc\n"; state.sync(bc); - cout << "synced state bc\n"; } // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (Exception const& _e) From 7e0e2bb196d3e4139f3221aa44218fd895b6b67f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 13 Feb 2015 18:25:47 +0100 Subject: [PATCH 15/20] add possibility to create bad blocks in fillers --- blValidBlockTestFiller.json | 228 ++--------------------------- block.cpp | 231 +++++++++++++++++++++++------- stSystemOperationsTestFiller.json | 4 +- 3 files changed, 186 insertions(+), 277 deletions(-) diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index d19c8104d..db7138b5b 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,85 +1,8 @@ { - "diffTooLow" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "1023", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - - "diff1024" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "1024", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - - "gasPrice0" : { + "log1" : { + "blockHeader" : { + "number" : "2" + }, "genesisBlockHeader" : { "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", @@ -102,162 +25,27 @@ "nonce" : "0", "code" : "", "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "0", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - - "tx" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, - - "txOrder" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "7000000000" }, - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "8000000000" - } - ], - "uncleHeaders" : [ - ] - }, - - "txEqualValue" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", "storage": {} } }, "transactions" : [ { "data" : "", - "gasLimit" : "500", + "gasLimit" : "5000", "gasPrice" : "10", "nonce" : "0", "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", "value" : "5000000000" - }, - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "9", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" } ], "uncleHeaders" : [ ] } - - - } diff --git a/block.cpp b/block.cpp index 2d44e8d71..4d1f5accc 100644 --- a/block.cpp +++ b/block.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of cpp-ethereum. - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . */ /** @file block.cpp * @author Christoph Jentzsch @@ -32,60 +32,60 @@ namespace dev { namespace test { bytes createBlockRLPFromFields(mObject& _tObj) { - RLPStream rlpStream; - rlpStream.appendList(_tObj.size()); + RLPStream rlpStream; + rlpStream.appendList(_tObj.size()); - if (_tObj.count("parentHash") > 0) - rlpStream << importByteArray(_tObj["parentHash"].get_str()); + if (_tObj.count("parentHash") > 0) + rlpStream << importByteArray(_tObj["parentHash"].get_str()); - if (_tObj.count("uncleHash") > 0) - rlpStream << importByteArray(_tObj["uncleHash"].get_str()); + if (_tObj.count("uncleHash") > 0) + rlpStream << importByteArray(_tObj["uncleHash"].get_str()); - if (_tObj.count("coinbase") > 0) - rlpStream << importByteArray(_tObj["coinbase"].get_str()); + if (_tObj.count("coinbase") > 0) + rlpStream << importByteArray(_tObj["coinbase"].get_str()); - if (_tObj.count("stateRoot") > 0) - rlpStream << importByteArray(_tObj["stateRoot"].get_str()); + if (_tObj.count("stateRoot") > 0) + rlpStream << importByteArray(_tObj["stateRoot"].get_str()); - if (_tObj.count("transactionsTrie") > 0) - rlpStream << importByteArray(_tObj["transactionsTrie"].get_str()); + if (_tObj.count("transactionsTrie") > 0) + rlpStream << importByteArray(_tObj["transactionsTrie"].get_str()); - if (_tObj.count("receiptTrie") > 0) - rlpStream << importByteArray(_tObj["receiptTrie"].get_str()); + if (_tObj.count("receiptTrie") > 0) + rlpStream << importByteArray(_tObj["receiptTrie"].get_str()); - if (_tObj.count("bloom") > 0) - rlpStream << importByteArray(_tObj["bloom"].get_str()); + if (_tObj.count("bloom") > 0) + rlpStream << importByteArray(_tObj["bloom"].get_str()); - if (_tObj.count("difficulty") > 0) - rlpStream << bigint(_tObj["difficulty"].get_str()); + if (_tObj.count("difficulty") > 0) + rlpStream << bigint(_tObj["difficulty"].get_str()); - if (_tObj.count("number") > 0) - rlpStream << bigint(_tObj["number"].get_str()); + if (_tObj.count("number") > 0) + rlpStream << bigint(_tObj["number"].get_str()); - if (_tObj.count("gasLimit") > 0) - rlpStream << bigint(_tObj["gasLimit"].get_str()); + if (_tObj.count("gasLimit") > 0) + rlpStream << bigint(_tObj["gasLimit"].get_str()); - if (_tObj.count("gasUsed") > 0) - rlpStream << bigint(_tObj["gasUsed"].get_str()); + if (_tObj.count("gasUsed") > 0) + rlpStream << bigint(_tObj["gasUsed"].get_str()); - if (_tObj.count("timestamp") > 0) - rlpStream << bigint(_tObj["timestamp"].get_str()); + if (_tObj.count("timestamp") > 0) + rlpStream << bigint(_tObj["timestamp"].get_str()); - if (_tObj.count("extraData") > 0) - rlpStream << importByteArray(_tObj["extraData"].get_str()); + if (_tObj.count("extraData") > 0) + rlpStream << importByteArray(_tObj["extraData"].get_str()); - if (_tObj.count("nonce") > 0) - rlpStream << importByteArray(_tObj["nonce"].get_str()); + if (_tObj.count("nonce") > 0) + rlpStream << importByteArray(_tObj["nonce"].get_str()); - return rlpStream.out(); + return rlpStream.out(); } void doBlockTests(json_spirit::mValue& _v, bool _fillin) { - for (auto& i: _v.get_obj()) - { - cerr << i.first << endl; - mObject& o = i.second.get_obj(); + for (auto& i: _v.get_obj()) + { + cerr << i.first << endl; + mObject& o = i.second.get_obj(); BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); cout << "construc genesis\n"; @@ -197,9 +197,12 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // write valid txs cout << "number of valid txs: " << txs.transactions().size(); mArray txArray; + Transactions txList; for (auto const& txi: txs.transactions()) { + cout << "AHA0" << endl; Transaction tx(txi.second, CheckSignature::Sender); + txList.push_back(tx); mObject txObject; txObject["nonce"] = toString(tx.nonce()); txObject["data"] = toHex(tx.data()); @@ -210,10 +213,11 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) txObject["v"] = to_string(tx.signature().v + 27); txObject["to"] = toString(tx.receiveAddress()); txObject["value"] = toString(tx.value()); + cout << "AHA0.5" << endl; txArray.push_back(txObject); } - + cout << "AHA1" << endl; o["transactions"] = txArray; o["rlp"] = "0x" + toHex(state.blockData()); @@ -237,12 +241,125 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); - o["blockHeader"] = oBlockHeader; - // write uncle list - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. - o["uncleHeaders"] = aUncleList; + // overwrite (wrong) data from blockheader in filler" << endl; + + if (o.count("blockHeader") > 0) + { + if (o["blockHeader"].get_obj().size() != 14) + { + + BlockInfo tmp = current_BlockHeader; + + if (o["blockHeader"].get_obj().count("parentHash") > 0) + tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); + + if (o["blockHeader"].get_obj().count("sha3Uncles") > 0) + tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); + + if (o["blockHeader"].get_obj().count("coinbase") > 0) + tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str()); + + if (o["blockHeader"].get_obj().count("stateRoot") > 0) + tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str()); + + if (o["blockHeader"].get_obj().count("transactionsTrie") > 0) + tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("receiptTrie") > 0) + tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("bloom") > 0) + tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str()); + + if (o["blockHeader"].get_obj().count("difficulty") > 0) + tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]); + + if (o["blockHeader"].get_obj().count("number") > 0) + tmp.number = toInt(o["blockHeader"].get_obj()["number"]); + + if (o["blockHeader"].get_obj().count("gasLimit") > 0) + tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]); + + if (o["blockHeader"].get_obj().count("gasUsed") > 0) + tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]); + + if (o["blockHeader"].get_obj().count("timestamp") > 0) + tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]); + + if (o["blockHeader"].get_obj().count("extraData") > 0) + tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str()); + + // find new valid nonce + + if (tmp != current_BlockHeader) + { + current_BlockHeader = tmp; + cout << "new header!\n"; + ProofOfWork pow; + MineInfo ret; + while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty)) + tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true); + oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); + } + } + else + { + // take the blockheader as is + const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); + current_BlockHeader.populateFromHeader(c_bRLP, false); + } + } + + //txs: + + RLPStream txStream; + txStream.appendList(txList.size()); + for (unsigned i = 0; i < txList.size(); ++i) + { + RLPStream txrlp; + txList[i].streamRLP(txrlp); + txStream.appendRaw(txrlp.out()); + } + + cout << "create block:" << endl; + + RLPStream rlpStream2; + current_BlockHeader.streamRLP(rlpStream2, WithNonce); + + RLPStream block2(3); + block2.appendRaw(rlpStream2.out()); + block2.appendRaw(txStream.out()); + block2.appendRaw(RLPEmptyList); + + if (sha3(RLP(state.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) + cout << "block 0 wrong" << endl; + + if (sha3(RLP(state.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) + cout << "block 1 wrong" << endl; + + if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) + cout << "block 2 wrong" << endl; + + + if (sha3(state.blockData()) != sha3(block2.out())) + { + cout << "blocks do not match!" << endl; + o["rlp"] = "0x" + toHex(block2.out()); + o.erase(o.find("blockHeader")); + o.erase(o.find("uncleHeaders")); + o.erase(o.find("transactions")); + } + else + { + o["blockHeader"] = oBlockHeader; + + // write uncle list + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. + o["uncleHeaders"] = aUncleList; + } } else @@ -254,13 +371,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) bc.import(blockRLP, state.db()); state.sync(bc); } - // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given + // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given catch (Exception const& _e) { cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e); BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); + return; } catch (std::exception const& _e) { @@ -268,6 +386,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); + return; } catch(...) { @@ -275,8 +394,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); + return; } - + cout << "valid block header\n"; + //cout << "block number: " << BOOST_REQUIRE(o.count("blockHeader") > 0); mObject tObj = o["blockHeader"].get_obj(); @@ -388,12 +509,12 @@ BOOST_AUTO_TEST_SUITE(BlockTests) BOOST_AUTO_TEST_CASE(blValidBlockTest) { - dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); + dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); } BOOST_AUTO_TEST_CASE(userDefinedFileBl) { - dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); + dev::test::userDefinedTest("--bltest", dev::test::doBlockTests); } BOOST_AUTO_TEST_SUITE_END() diff --git a/stSystemOperationsTestFiller.json b/stSystemOperationsTestFiller.json index eae393645..9f47b2fef 100644 --- a/stSystemOperationsTestFiller.json +++ b/stSystemOperationsTestFiller.json @@ -81,13 +81,13 @@ "pre" : { "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { "balance" : "1000000000000000000", - "nonce" : 0, + "nonce" : "0", "code" : "0x444242424245434253f0", "storage": {} }, "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { "balance" : "1000000000000000000", - "nonce" : 0, + "nonce" : "0", "code" : "", "storage": {} } From 968564f21dc547105a4814e27c7715c05a75ad20 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 11:04:05 +0100 Subject: [PATCH 16/20] extra data fix --- TestHelper.cpp | 20 +-- blInvalidHeaderTestFiller.json | 0 block.cpp | 302 ++++++++++++++++----------------- 3 files changed, 155 insertions(+), 167 deletions(-) create mode 100644 blInvalidHeaderTestFiller.json diff --git a/TestHelper.cpp b/TestHelper.cpp index 1e6b97f07..ff6939a5f 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -510,16 +510,16 @@ RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj) RLPStream rlpStream; rlpStream.appendList(_tObj.size()); - if (_tObj.count("nonce") > 0) + if (_tObj.count("nonce")) rlpStream << bigint(_tObj["nonce"].get_str()); - if (_tObj.count("gasPrice") > 0) + if (_tObj.count("gasPrice")) rlpStream << bigint(_tObj["gasPrice"].get_str()); - if (_tObj.count("gasLimit") > 0) + if (_tObj.count("gasLimit")) rlpStream << bigint(_tObj["gasLimit"].get_str()); - if (_tObj.count("to") > 0) + if (_tObj.count("to")) { if (_tObj["to"].get_str().empty()) rlpStream << ""; @@ -527,22 +527,22 @@ RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj) rlpStream << importByteArray(_tObj["to"].get_str()); } - if (_tObj.count("value") > 0) + if (_tObj.count("value")) rlpStream << bigint(_tObj["value"].get_str()); - if (_tObj.count("data") > 0) + if (_tObj.count("data")) rlpStream << importData(_tObj); - if (_tObj.count("v") > 0) + if (_tObj.count("v")) rlpStream << bigint(_tObj["v"].get_str()); - if (_tObj.count("r") > 0) + if (_tObj.count("r")) rlpStream << bigint(_tObj["r"].get_str()); - if (_tObj.count("s") > 0) + if (_tObj.count("s")) rlpStream << bigint(_tObj["s"].get_str()); - if (_tObj.count("extrafield") > 0) + if (_tObj.count("extrafield")) rlpStream << bigint(_tObj["extrafield"].get_str()); return rlpStream; diff --git a/blInvalidHeaderTestFiller.json b/blInvalidHeaderTestFiller.json new file mode 100644 index 000000000..e69de29bb diff --git a/block.cpp b/block.cpp index 4d1f5accc..891d89931 100644 --- a/block.cpp +++ b/block.cpp @@ -35,46 +35,46 @@ bytes createBlockRLPFromFields(mObject& _tObj) RLPStream rlpStream; rlpStream.appendList(_tObj.size()); - if (_tObj.count("parentHash") > 0) + if (_tObj.count("parentHash")) rlpStream << importByteArray(_tObj["parentHash"].get_str()); - if (_tObj.count("uncleHash") > 0) + if (_tObj.count("uncleHash")) rlpStream << importByteArray(_tObj["uncleHash"].get_str()); - if (_tObj.count("coinbase") > 0) + if (_tObj.count("coinbase")) rlpStream << importByteArray(_tObj["coinbase"].get_str()); - if (_tObj.count("stateRoot") > 0) + if (_tObj.count("stateRoot")) rlpStream << importByteArray(_tObj["stateRoot"].get_str()); - if (_tObj.count("transactionsTrie") > 0) + if (_tObj.count("transactionsTrie")) rlpStream << importByteArray(_tObj["transactionsTrie"].get_str()); - if (_tObj.count("receiptTrie") > 0) + if (_tObj.count("receiptTrie")) rlpStream << importByteArray(_tObj["receiptTrie"].get_str()); - if (_tObj.count("bloom") > 0) + if (_tObj.count("bloom")) rlpStream << importByteArray(_tObj["bloom"].get_str()); - if (_tObj.count("difficulty") > 0) + if (_tObj.count("difficulty")) rlpStream << bigint(_tObj["difficulty"].get_str()); - if (_tObj.count("number") > 0) + if (_tObj.count("number")) rlpStream << bigint(_tObj["number"].get_str()); - if (_tObj.count("gasLimit") > 0) + if (_tObj.count("gasLimit")) rlpStream << bigint(_tObj["gasLimit"].get_str()); - if (_tObj.count("gasUsed") > 0) + if (_tObj.count("gasUsed")) rlpStream << bigint(_tObj["gasUsed"].get_str()); - if (_tObj.count("timestamp") > 0) + if (_tObj.count("timestamp")) rlpStream << bigint(_tObj["timestamp"].get_str()); - if (_tObj.count("extraData") > 0) + if (_tObj.count("extraData")) rlpStream << importByteArray(_tObj["extraData"].get_str()); - if (_tObj.count("nonce") > 0) + if (_tObj.count("nonce")) rlpStream << importByteArray(_tObj["nonce"].get_str()); return rlpStream.out(); @@ -87,43 +87,37 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) cerr << i.first << endl; mObject& o = i.second.get_obj(); - BOOST_REQUIRE(o.count("genesisBlockHeader") > 0); - cout << "construc genesis\n"; - - // construct RLP of the genesis block - const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); - const RLP c_bRLP(c_blockRLP); + BOOST_REQUIRE(o.count("genesisBlockHeader")); BlockInfo blockFromFields; - try { + // construct genesis block + const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); blockFromFields.populateFromHeader(c_bRLP, false); } catch (Exception const& _e) { cnote << "block population did throw an exception: " << diagnostic_information(_e); BOOST_ERROR("Failed block population with Exception: " << _e.what()); - return; + continue; } catch (std::exception const& _e) { BOOST_ERROR("Failed block population with Exception: " << _e.what()); - return; + continue; } catch(...) { cnote << "block population did throw an unknown exception\n"; - return; + continue; } - BOOST_REQUIRE(o.count("pre") > 0); - cout << "read state\n"; + BOOST_REQUIRE(o.count("pre")); ImportTest importer(o["pre"].get_obj()); State state(Address(), OverlayDB(), BaseState::Empty); importer.importState(o["pre"].get_obj(), state); - - // commit changes to DB state.commit(); if (_fillin) @@ -136,7 +130,8 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // find new valid nonce ProofOfWork pow; MineInfo ret; - tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, false); + while (!ProofOfWork::verify(blockFromFields.headerHash(WithoutNonce), blockFromFields.nonce, blockFromFields.difficulty)) + tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, true); //update genesis block in json file o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot); @@ -157,12 +152,9 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) // construct blockchain BlockChain bc(block.out(), string(), true); - cout << "constructed bc\n"; - if (_fillin) { - BOOST_REQUIRE(o.count("transactions") > 0); - cout << "read transactions\n"; + BOOST_REQUIRE(o.count("transactions")); TransactionQueue txs; @@ -195,12 +187,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) } // write valid txs - cout << "number of valid txs: " << txs.transactions().size(); mArray txArray; Transactions txList; for (auto const& txi: txs.transactions()) { - cout << "AHA0" << endl; Transaction tx(txi.second, CheckSignature::Sender); txList.push_back(tx); mObject txObject; @@ -213,19 +203,87 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) txObject["v"] = to_string(tx.signature().v + 27); txObject["to"] = toString(tx.receiveAddress()); txObject["value"] = toString(tx.value()); - cout << "AHA0.5" << endl; txArray.push_back(txObject); } - cout << "AHA1" << endl; - o["transactions"] = txArray; + o["transactions"] = txArray; o["rlp"] = "0x" + toHex(state.blockData()); + BlockInfo current_BlockHeader = state.info(); + + // overwrite blockheader with (possible wrong) data from "blockheader" in filler; + + if (o.count("blockHeader")) + { + if (o["blockHeader"].get_obj().size() != 14) + { + + BlockInfo tmp = current_BlockHeader; + + if (o["blockHeader"].get_obj().count("parentHash")) + tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); + + if (o["blockHeader"].get_obj().count("sha3Uncles")) + tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); + + if (o["blockHeader"].get_obj().count("coinbase")) + tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str()); + + if (o["blockHeader"].get_obj().count("stateRoot")) + tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str()); + + if (o["blockHeader"].get_obj().count("transactionsTrie")) + tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("receiptTrie")) + tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str()); + + if (o["blockHeader"].get_obj().count("bloom")) + tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str()); + + if (o["blockHeader"].get_obj().count("difficulty")) + tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]); + + if (o["blockHeader"].get_obj().count("number")) + tmp.number = toInt(o["blockHeader"].get_obj()["number"]); + + if (o["blockHeader"].get_obj().count("gasLimit")) + tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]); + + if (o["blockHeader"].get_obj().count("gasUsed")) + tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]); + + if (o["blockHeader"].get_obj().count("timestamp")) + tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]); + + if (o["blockHeader"].get_obj().count("extraData")) + tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str()); + + // find new valid nonce + + if (tmp != current_BlockHeader) + { + current_BlockHeader = tmp; + cout << "new header!\n"; + ProofOfWork pow; + MineInfo ret; + while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty)) + tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true); + } + } + else + { + // take the blockheader as is + const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj()); + const RLP c_bRLP(c_blockRLP); + current_BlockHeader.populateFromHeader(c_bRLP, false); + } + } + // write block header mObject oBlockHeader; - BlockInfo current_BlockHeader = state.info(); oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); @@ -241,77 +299,11 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); + o["blockHeader"] = oBlockHeader; - - // overwrite (wrong) data from blockheader in filler" << endl; - - if (o.count("blockHeader") > 0) - { - if (o["blockHeader"].get_obj().size() != 14) - { - - BlockInfo tmp = current_BlockHeader; - - if (o["blockHeader"].get_obj().count("parentHash") > 0) - tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); - - if (o["blockHeader"].get_obj().count("sha3Uncles") > 0) - tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); - - if (o["blockHeader"].get_obj().count("coinbase") > 0) - tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str()); - - if (o["blockHeader"].get_obj().count("stateRoot") > 0) - tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str()); - - if (o["blockHeader"].get_obj().count("transactionsTrie") > 0) - tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str()); - - if (o["blockHeader"].get_obj().count("receiptTrie") > 0) - tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str()); - - if (o["blockHeader"].get_obj().count("bloom") > 0) - tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str()); - - if (o["blockHeader"].get_obj().count("difficulty") > 0) - tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]); - - if (o["blockHeader"].get_obj().count("number") > 0) - tmp.number = toInt(o["blockHeader"].get_obj()["number"]); - - if (o["blockHeader"].get_obj().count("gasLimit") > 0) - tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]); - - if (o["blockHeader"].get_obj().count("gasUsed") > 0) - tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]); - - if (o["blockHeader"].get_obj().count("timestamp") > 0) - tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]); - - if (o["blockHeader"].get_obj().count("extraData") > 0) - tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str()); - - // find new valid nonce - - if (tmp != current_BlockHeader) - { - current_BlockHeader = tmp; - cout << "new header!\n"; - ProofOfWork pow; - MineInfo ret; - while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty)) - tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true); - oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); - } - } - else - { - // take the blockheader as is - const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj()); - const RLP c_bRLP(c_blockRLP); - current_BlockHeader.populateFromHeader(c_bRLP, false); - } - } + // write uncle list + mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. + o["uncleHeaders"] = aUncleList; //txs: @@ -324,8 +316,6 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) txStream.appendRaw(txrlp.out()); } - cout << "create block:" << endl; - RLPStream rlpStream2; current_BlockHeader.streamRLP(rlpStream2, WithNonce); @@ -334,40 +324,45 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) block2.appendRaw(txStream.out()); block2.appendRaw(RLPEmptyList); + o["rlp"] = "0x" + toHex(block2.out()); + if (sha3(RLP(state.blockData())[0].data()) != sha3(RLP(block2.out())[0].data())) - cout << "block 0 wrong" << endl; + cnote << "block header mismatch\n"; if (sha3(RLP(state.blockData())[1].data()) != sha3(RLP(block2.out())[1].data())) - cout << "block 1 wrong" << endl; + cnote << "txs mismatch\n"; if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data())) - cout << "block 2 wrong" << endl; + cnote << "uncle list mismatch\n"; - - if (sha3(state.blockData()) != sha3(block2.out())) + try { - cout << "blocks do not match!" << endl; - o["rlp"] = "0x" + toHex(block2.out()); + ImportTest importerTmp(o["pre"].get_obj()); + State stateTmp(Address(), OverlayDB(), BaseState::Empty); + importerTmp.importState(o["pre"].get_obj(), stateTmp); + stateTmp.commit(); + BlockChain bcTmp(block.out(), "/tmp/", true); + stateTmp.sync(bcTmp); + bc.import(block2.out(), stateTmp.db()); + stateTmp.sync(bcTmp); + } + // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given + catch (...) + { + cnote << "block is invalid!\n"; o.erase(o.find("blockHeader")); o.erase(o.find("uncleHeaders")); o.erase(o.find("transactions")); } - else - { - o["blockHeader"] = oBlockHeader; - - // write uncle list - mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. - o["uncleHeaders"] = aUncleList; - } } else { + bytes blockRLP; try { state.sync(bc); - bytes blockRLP = importByteArray(o["rlp"].get_str()); + blockRLP = importByteArray(o["rlp"].get_str()); bc.import(blockRLP, state.db()); state.sync(bc); } @@ -378,7 +373,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); - return; + continue; } catch (std::exception const& _e) { @@ -386,7 +381,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); - return; + continue; } catch(...) { @@ -394,11 +389,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK(o.count("blockHeader") == 0); BOOST_CHECK(o.count("transactions") == 0); BOOST_CHECK(o.count("uncleHeaders") == 0); - return; + continue; } - cout << "valid block header\n"; - //cout << "block number: " << - BOOST_REQUIRE(o.count("blockHeader") > 0); + + BOOST_REQUIRE(o.count("blockHeader")); mObject tObj = o["blockHeader"].get_obj(); BlockInfo blockHeaderFromFields; @@ -427,8 +421,6 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!"); - cout << "checked block header bc\n"; - //Check transaction list Transactions txsFromField; @@ -437,19 +429,16 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) { mObject tx = txObj.get_obj(); - cout << "read single tx\n"; + BOOST_REQUIRE(tx.count("nonce")); + BOOST_REQUIRE(tx.count("gasPrice")); + BOOST_REQUIRE(tx.count("gasLimit")); + BOOST_REQUIRE(tx.count("to")); + BOOST_REQUIRE(tx.count("value")); + BOOST_REQUIRE(tx.count("v")); + BOOST_REQUIRE(tx.count("r")); + BOOST_REQUIRE(tx.count("s")); + BOOST_REQUIRE(tx.count("data")); - BOOST_REQUIRE(tx.count("nonce") > 0); - BOOST_REQUIRE(tx.count("gasPrice") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); - BOOST_REQUIRE(tx.count("to") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("v") > 0); - BOOST_REQUIRE(tx.count("r") > 0); - BOOST_REQUIRE(tx.count("s") > 0); - BOOST_REQUIRE(tx.count("data") > 0); - - cout << "construct single tx\n"; try { Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender); @@ -458,18 +447,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) catch (Exception const& _e) { BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e)); - } catch (exception const& _e) { - cout << _e.what() << endl; + cnote << _e.what(); } } - cout << "read txs bc\n"; - Transactions txsFromRlp; - bytes blockRLP = importByteArray(o["rlp"].get_str()); RLP root(blockRLP); for (auto const& tr: root[1]) { @@ -491,12 +476,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match"); BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match"); - BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "however, transactions in rlp and in field do not match"); + BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions in rlp and in transaction field do not match"); } - cout << "checked txs bc\n"; // check uncle list - BOOST_CHECK_MESSAGE((o["uncleList"].type() == json_spirit::null_type ? 0 : o["uncleList"].get_array().size()) == 0, "Uncle list is not empty, but the genesis block can not have uncles"); } } @@ -507,9 +490,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(BlockTests) -BOOST_AUTO_TEST_CASE(blValidBlockTest) +//BOOST_AUTO_TEST_CASE(blValidBlockTest) +//{ +// dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); +//} + +BOOST_AUTO_TEST_CASE(blInvalidHeaderTest) { - dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); + dev::test::executeTests("blInvalidHeaderTest", "/BlockTests", dev::test::doBlockTests); } BOOST_AUTO_TEST_CASE(userDefinedFileBl) From 1ea2f0f66534a554073887ecd1973aad3af69a9a Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 11:06:22 +0100 Subject: [PATCH 17/20] add invalid block header tests --- blInvalidHeaderTestFiller.json | 736 +++++++++++++++++++++++++++++++++ blValidBlockTestFiller.json | 391 +++++++++++++++--- block.cpp | 8 +- 3 files changed, 1083 insertions(+), 52 deletions(-) diff --git a/blInvalidHeaderTestFiller.json b/blInvalidHeaderTestFiller.json index e69de29bb..0a8000d0f 100644 --- a/blInvalidHeaderTestFiller.json +++ b/blInvalidHeaderTestFiller.json @@ -0,0 +1,736 @@ +{ + "log1_wrongBlockNumber" : { + "blockHeader" : { + "number" : "2" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "log1_wrongBloom" : { + "blockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongCoinbase" : { + "blockHeader" : { + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongDifficulty" : { + "blockHeader" : { + "difficulty" : "10000" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongExtraData" : { + "blockHeader" : { + "extraData" : "42" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongGasLimit" : { + "blockHeader" : { + "gasLimit" : "100000" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongGasUsed" : { + "blockHeader" : { + "gasUsed" : "0" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongNonce" : { + "blockHeader" : { + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongNumber" : { + "blockHeader" : { + "number" : "0" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongParentHash" : { + "blockHeader" : { + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongReceiptTrie" : { + "blockHeader" : { + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongStateRoot" : { + "blockHeader" : { + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongTimestamp" : { + "blockHeader" : { + "timestamp" : "0x54c98c80" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongTransactionsTrie" : { + "blockHeader" : { + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "wrongUncleHash" : { + "blockHeader" : { + "uncleHash" : "0x0dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + } +} diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index db7138b5b..b84573789 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,51 +1,346 @@ { - "log1" : { - "blockHeader" : { - "number" : "2" - }, - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - }, - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "100", - "nonce" : "0", - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "5000", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" - } - ], - "uncleHeaders" : [ - ] - } + "diffTooLowToChange" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1023", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "diff1024" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1024", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "gasPrice0" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "0", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "gasLimitTooHigh" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "1000000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "0", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "SimpleTx" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, + + "txOrder" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7000000000" + }, + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "8000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "txEqualValue" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + }, + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "9", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, + + "log1_correct" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + } } diff --git a/block.cpp b/block.cpp index 891d89931..aa1790f71 100644 --- a/block.cpp +++ b/block.cpp @@ -490,10 +490,10 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) BOOST_AUTO_TEST_SUITE(BlockTests) -//BOOST_AUTO_TEST_CASE(blValidBlockTest) -//{ -// dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); -//} +BOOST_AUTO_TEST_CASE(blValidBlockTest) +{ + dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); +} BOOST_AUTO_TEST_CASE(blInvalidHeaderTest) { From 4417975699240b3ce3608f0e7dd84f721c297410 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 11:49:15 +0100 Subject: [PATCH 18/20] fix typo --- blInvalidHeaderTestFiller.json | 51 +--------------------------------- block.cpp | 2 +- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/blInvalidHeaderTestFiller.json b/blInvalidHeaderTestFiller.json index 0a8000d0f..482eafc56 100644 --- a/blInvalidHeaderTestFiller.json +++ b/blInvalidHeaderTestFiller.json @@ -195,7 +195,7 @@ ] }, - "wrongExtraData" : { + "DifferentExtraData" : { "blockHeader" : { "extraData" : "42" }, @@ -342,55 +342,6 @@ ] }, - "wrongNonce" : { - "blockHeader" : { - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" - }, - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - }, - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "100", - "nonce" : "0", - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "5000", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" - } - ], - "uncleHeaders" : [ - ] - }, - "wrongNumber" : { "blockHeader" : { "number" : "0" diff --git a/block.cpp b/block.cpp index aa1790f71..19dcdf84b 100644 --- a/block.cpp +++ b/block.cpp @@ -224,7 +224,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) if (o["blockHeader"].get_obj().count("parentHash")) tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str()); - if (o["blockHeader"].get_obj().count("sha3Uncles")) + if (o["blockHeader"].get_obj().count("uncleHash")) tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str()); if (o["blockHeader"].get_obj().count("coinbase")) From 3fae0daed96802e34d77437dd58f56bc7d7f804d Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 12:23:08 +0100 Subject: [PATCH 19/20] remove unnecessary function --- TestHelper.h | 1 - 1 file changed, 1 deletion(-) diff --git a/TestHelper.h b/TestHelper.h index f7df3a2c0..c4dde1a60 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -53,7 +53,6 @@ public: void importState(json_spirit::mObject& _o, eth::State& _state); void importTransaction(json_spirit::mObject& _o); void exportTest(bytes _output, eth::State& _statePost); - std::map getStateMap(eth::State& _state){return _state.m_cache;} eth::State m_statePre; eth::State m_statePost; From 2391b42b95e8f5030094f72b7b4f908f312f96e2 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 16 Feb 2015 13:04:28 +0100 Subject: [PATCH 20/20] OS independency by using file system --- blValidBlockTestFiller.json | 707 +++++++++++++++++++----------------- block.cpp | 3 +- 2 files changed, 373 insertions(+), 337 deletions(-) diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json index b84573789..8099c0dd6 100644 --- a/blValidBlockTestFiller.json +++ b/blValidBlockTestFiller.json @@ -1,346 +1,381 @@ { - "diffTooLowToChange" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "1023", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, + "diffTooLowToChange" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1023", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, - "diff1024" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "1024", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "1", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, + "diff1024" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "1024", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, - "gasPrice0" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "0", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, + "gasPrice0" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "0", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, - "gasLimitTooHigh" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "1000000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "850", - "gasPrice" : "0", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, + "gasLimitTooHigh" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "1000000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "850", + "gasPrice" : "0", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, - "SimpleTx" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "10" - } - ], - "uncleHeaders" : [ - ] - }, + "SimpleTx" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "10" + } + ], + "uncleHeaders" : [ + ] + }, - "txOrder" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "7000000000" - }, - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "8000000000" - } - ], - "uncleHeaders" : [ - ] - }, + "txOrder" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "7000000000" + }, + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "8000000000" + } + ], + "uncleHeaders" : [ + ] + }, - "txEqualValue" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" - }, - { - "data" : "", - "gasLimit" : "500", - "gasPrice" : "9", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" - } - ], - "uncleHeaders" : [ - ] - }, + "txEqualValue" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + }, + { + "data" : "", + "gasLimit" : "500", + "gasPrice" : "9", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ] + }, - "log1_correct" : { - "genesisBlockHeader" : { - "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", - "difficulty" : "10000", - "extraData" : "42", - "gasLimit" : "100000", - "gasUsed" : "0", - "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", - "number" : "0", - "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", - "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", - "timestamp" : "0x54c98c81", - "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - }, - "pre" : { - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "10000000000", - "nonce" : "0", - "code" : "", - "storage": {} - }, - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "100", - "nonce" : "0", - "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", - "storage": {} - } - }, - "transactions" : [ - { - "data" : "", - "gasLimit" : "5000", - "gasPrice" : "10", - "nonce" : "0", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "5000000000" - } - ], - "uncleHeaders" : [ - ] - } + "log1_correct" : { + "genesisBlockHeader" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "10000", + "extraData" : "42", + "gasLimit" : "100000", + "gasUsed" : "0", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "0", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "10000000000", + "nonce" : "0", + "code" : "", + "storage": {} + }, + "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "100", + "nonce" : "0", + "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }", + "storage": {} + } + }, + "transactions" : [ + { + "data" : "", + "gasLimit" : "5000", + "gasPrice" : "10", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "5000000000" + } + ], + "uncleHeaders" : [ + ], + + "firstBlockTest" : { + "block" : { + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1", + "difficulty" : "023101", + "extraData" : "42", + "gasLimit" : "0x0dddb6", + "gasUsed" : "100", + "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d", + "number" : "62", + "parentHash" : "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", + "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", + "timestamp" : "0x54c98c81", + "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + }, + "pre" : { + }, + "transactions" : [ + { + "data" : "0x60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b56", + "gasLimit" : "0x0f3e6f", + "gasPrice" : "0x09184e72a000", + "nonce" : "0", + "r" : "0xd4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89", + "s" : "0xae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942", + "to" : "", + "v" : "0x1b", + "value" : "" + } + ], + } + + } } diff --git a/block.cpp b/block.cpp index 19dcdf84b..ce165bc42 100644 --- a/block.cpp +++ b/block.cpp @@ -20,6 +20,7 @@ * block test functions. */ +#include #include #include "TestHelper.h" @@ -341,7 +342,7 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin) State stateTmp(Address(), OverlayDB(), BaseState::Empty); importerTmp.importState(o["pre"].get_obj(), stateTmp); stateTmp.commit(); - BlockChain bcTmp(block.out(), "/tmp/", true); + BlockChain bcTmp(block.out(), getDataDir() + "/tmpBlockChain.bc", true); stateTmp.sync(bcTmp); bc.import(block2.out(), stateTmp.db()); stateTmp.sync(bcTmp);