diff options
author | CJentzsch <jentzsch.software@gmail.com> | 2015-02-07 06:43:49 +0800 |
---|---|---|
committer | CJentzsch <jentzsch.software@gmail.com> | 2015-02-07 06:43:49 +0800 |
commit | 330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972 (patch) | |
tree | 520162b75f1512c6fa0b81a703b664d4eb1226b9 /block.cpp | |
parent | ad1a26c5035481e760cfdaf748fb26bee7e7beb2 (diff) | |
download | dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar.gz dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar.bz2 dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar.lz dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar.xz dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.tar.zst dexon-solidity-330caf3f40e4ceb3fea792e8ce3cd1bcd4a85972.zip |
create block from transaction with genesis block as parent
Diffstat (limited to 'block.cpp')
-rw-r--r-- | block.cpp | 197 |
1 files changed, 124 insertions, 73 deletions
@@ -20,6 +20,7 @@ * block test functions. */ +#include <libethereum/CanonBlockChain.h> #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); - - // 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")); - } +// 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(...) +// { +// 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); + cout << "attempt to import transaction\n"; + txs.attemptImport(createTransactionFromFields(tx)); + } + cout << "done importing txs\n"; - Transaction txFromFields = createTransactionFromFields(tx); + //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) -{ - dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests); -} - -BOOST_AUTO_TEST_CASE(ttCreateTest) +BOOST_AUTO_TEST_CASE(blFirstTest) { - 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 <PathToConstructor> <PathToDestiny>\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()); - } - } - } + dev::test::executeTests("blFirstTest", "/BlockTests", dev::test::doBlockTests); } -BOOST_AUTO_TEST_CASE(userDefinedFileTT) -{ - dev::test::userDefinedTest("--bltest", 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 <PathToConstructor> <PathToDestiny>\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() |