Browse Source

start with test defined genesis block

cl-refactor
CJentzsch 10 years ago
parent
commit
6a8c6cba61
  1. 2
      libdevcore/RLP.cpp
  2. 3
      test/TestHelper.h
  3. 17
      test/blFirstTestFiller.json
  4. 71
      test/blValidBlockTestFiller.json
  5. 365
      test/block.cpp

2
libdevcore/RLP.cpp

@ -177,7 +177,7 @@ void RLPStream::noteAppended(unsigned _itemCount)
while (m_listStack.size()) while (m_listStack.size())
{ {
if (m_listStack.back().first < _itemCount) if (m_listStack.back().first < _itemCount)
BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("itemCount too large")); BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("itemCount too large") << RequirementError((bigint)m_listStack.back().first, (bigint)_itemCount));
m_listStack.back().first -= _itemCount; m_listStack.back().first -= _itemCount;
if (m_listStack.back().first) if (m_listStack.back().first)
break; break;

3
test/TestHelper.h

@ -45,7 +45,7 @@ namespace test
class ImportTest class ImportTest
{ {
public: public:
ImportTest() = default; ImportTest(json_spirit::mObject& _o) : m_TestObject(_o) {}
ImportTest(json_spirit::mObject& _o, bool isFiller); ImportTest(json_spirit::mObject& _o, bool isFiller);
// imports // imports
@ -53,6 +53,7 @@ public:
void importState(json_spirit::mObject& _o, eth::State& _state); void importState(json_spirit::mObject& _o, eth::State& _state);
void importTransaction(json_spirit::mObject& _o); void importTransaction(json_spirit::mObject& _o);
void exportTest(bytes _output, eth::State& _statePost); void exportTest(bytes _output, eth::State& _statePost);
std::map<Address, eth::Account> getStateMap(eth::State& _state){return _state.m_cache;}
eth::State m_statePre; eth::State m_statePre;
eth::State m_statePost; eth::State m_statePost;

17
test/blFirstTestFiller.json

@ -1,5 +1,22 @@
{ {
"firstBlockTest" : { "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": [{ "transactions": [{
"nonce": "0", "nonce": "0",
"gasPrice": "0x09184e72a000", "gasPrice": "0x09184e72a000",

71
test/blValidBlockTestFiller.json

@ -1,20 +1,61 @@
{ {
"validBlock" : { "validBlock" : {
"block" : { "block" : {
"parentHash": "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5", "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"coinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1", "difficulty" : "1024",
"stateRoot": "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a", "extraData" : "42",
"transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "gasLimit" : "0x0dddb6",
"receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "gasUsed" : "100",
"bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
"difficulty": "023101", "number" : "0",
"number": "62", "parentHash" : "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5",
"gasLimit": "0x0dddb6", "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"gasUsed": "100", "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
"timestamp": "0x54c98c81", "timestamp" : "0x54c98c81",
"extraData": "42", "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"nonce": "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d" "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" : [
]
} }
} }

365
test/block.cpp

@ -32,168 +32,194 @@ namespace dev { namespace test {
bytes createBlockRLPFromFields(mObject& _tObj) bytes createBlockRLPFromFields(mObject& _tObj)
{ {
BOOST_REQUIRE(_tObj.count("parentHash") > 0); BOOST_REQUIRE(_tObj.count("parentHash") > 0);
BOOST_REQUIRE(_tObj.count("uncleHash") > 0); BOOST_REQUIRE(_tObj.count("uncleHash") > 0);
BOOST_REQUIRE(_tObj.count("coinbase") > 0); BOOST_REQUIRE(_tObj.count("coinbase") > 0);
BOOST_REQUIRE(_tObj.count("stateRoot") > 0); BOOST_REQUIRE(_tObj.count("stateRoot") > 0);
BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0); BOOST_REQUIRE(_tObj.count("transactionsTrie")> 0);
BOOST_REQUIRE(_tObj.count("receiptTrie") > 0); BOOST_REQUIRE(_tObj.count("receiptTrie") > 0);
BOOST_REQUIRE(_tObj.count("bloom") > 0); BOOST_REQUIRE(_tObj.count("bloom") > 0);
BOOST_REQUIRE(_tObj.count("difficulty") > 0); BOOST_REQUIRE(_tObj.count("difficulty") > 0);
BOOST_REQUIRE(_tObj.count("number") > 0); BOOST_REQUIRE(_tObj.count("number") > 0);
BOOST_REQUIRE(_tObj.count("gasLimit")> 0); BOOST_REQUIRE(_tObj.count("gasLimit")> 0);
BOOST_REQUIRE(_tObj.count("gasUsed") > 0); BOOST_REQUIRE(_tObj.count("gasUsed") > 0);
BOOST_REQUIRE(_tObj.count("timestamp") > 0); BOOST_REQUIRE(_tObj.count("timestamp") > 0);
BOOST_REQUIRE(_tObj.count("extraData") > 0); BOOST_REQUIRE(_tObj.count("extraData") > 0);
BOOST_REQUIRE(_tObj.count("nonce") > 0); BOOST_REQUIRE(_tObj.count("nonce") > 0);
// construct RLP of the given block // construct RLP of the given block
cout << "done with require\n"; cout << "done with require\n";
RLPStream rlpStream; RLPStream rlpStream;
rlpStream.appendList(14); rlpStream.appendList(14);
cout << "increate aha1\n"; cout << "increate aha1\n";
rlpStream << h256(_tObj["parentHash"].get_str()) << h256(_tObj["uncleHash"].get_str()) << Address(_tObj["coinbase"].get_str()); 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()) << Address(_tObj["receiptTrie"].get_str());
rlpStream << LogBloom(_tObj["bloom"].get_str()) << u256(_tObj["difficulty"].get_str()) << u256(_tObj["number"].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 << 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 << importByteArray(_tObj["extraData"].get_str()) << h256(_tObj["nonce"].get_str());
return rlpStream.out(); return rlpStream.out();
} }
void doBlockTests(json_spirit::mValue& _v, bool _fillin) void doBlockTests(json_spirit::mValue& _v, bool _fillin)
{ {
for (auto& i: _v.get_obj()) for (auto& i: _v.get_obj())
{ {
cerr << i.first << endl; cerr << i.first << endl;
mObject& o = i.second.get_obj(); mObject& o = i.second.get_obj();
if (_fillin == false) if (_fillin == false)
{ {
BOOST_REQUIRE(o.count("rlp") > 0); // TODO
const bytes rlpReaded = importByteArray(o["rlp"].get_str());
RLP myRLP(rlpReaded); // BOOST_REQUIRE(o.count("rlp") > 0);
BlockInfo blockFromRlp; // const bytes rlpReaded = importByteArray(o["rlp"].get_str());
// RLP myRLP(rlpReaded);
try // BlockInfo blockFromRlp;
{
blockFromRlp.populateFromHeader(myRLP, false); // try
//blockFromRlp.verifyInternals(rlpReaded); // {
} // blockFromRlp.populateFromHeader(myRLP, false);
catch(Exception const& _e) // //blockFromRlp.verifyInternals(rlpReaded);
{ // }
cnote << "block construction did throw an exception: " << diagnostic_information(_e); // catch(Exception const& _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!"); // cnote << "block construction did throw an exception: " << diagnostic_information(_e);
return; // 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(); // BOOST_REQUIRE(o.count("block") > 0);
BlockInfo blockFromFields;
const bytes rlpreade2 = createBlockRLPFromFields(tObj); // mObject tObj = o["block"].get_obj();
RLP mysecondRLP(rlpreade2); // BlockInfo blockFromFields;
blockFromFields.populateFromHeader(mysecondRLP, false); // const bytes rlpreade2 = createBlockRLPFromFields(tObj);
// RLP mysecondRLP(rlpreade2);
//Check the fields restored from RLP to original fields // blockFromFields.populateFromHeader(mysecondRLP, false);
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!"); // //Check the fields restored from RLP to original fields
BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!"); // BOOST_CHECK_MESSAGE(blockFromFields.hash == blockFromRlp.hash, "hash in given RLP not matching the block hash!");
BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!"); // BOOST_CHECK_MESSAGE(blockFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!");
BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!"); // BOOST_CHECK_MESSAGE(blockFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!");
BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!"); // BOOST_CHECK_MESSAGE(blockFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!");
BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!"); // BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!");
BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!"); // BOOST_CHECK_MESSAGE(blockFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!");
BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!"); // BOOST_CHECK_MESSAGE(blockFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!");
BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!"); // BOOST_CHECK_MESSAGE(blockFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!");
BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!"); // BOOST_CHECK_MESSAGE(blockFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!");
BOOST_CHECK_MESSAGE(blockFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!"); // BOOST_CHECK_MESSAGE(blockFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!");
BOOST_CHECK_MESSAGE(blockFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!"); // BOOST_CHECK_MESSAGE(blockFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!");
BOOST_CHECK_MESSAGE(blockFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!"); // 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 == blockFromRlp, "However, blockFromFields != blockFromRlp!"); // 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); else
{
// // construct Rlp of the given block BOOST_REQUIRE(o.count("block") > 0);
// bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj());
// RLP myRLP(blockRLP); // construct Rlp of the given block
// o["rlp"] = toHex(blockRLP); bytes blockRLP = createBlockRLPFromFields(o["block"].get_obj());
RLP myRLP(blockRLP);
BlockInfo blockFromFields;
cout << "blockFromFields diff:" << blockFromFields.difficulty << endl;
// try try
// { {
// BlockInfo blockFromFields;
// blockFromFields.populateFromHeader(myRLP, false); blockFromFields.populateFromHeader(myRLP, false);
// (void)blockFromFields; //blockFromFields.verifyInternals(blockRLP);
// //blockFromFields.verifyInternals(blockRLP); }
// } catch (Exception const& _e)
// catch (Exception const& _e) {
// { cnote << "block construction did throw an exception: " << diagnostic_information(_e);
// cnote << "block construction did throw an exception: " << diagnostic_information(_e); BOOST_ERROR("Failed block construction Test with Exception: " << _e.what());
// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); o.erase(o.find("block"));
// o.erase(o.find("block")); }
// } catch (std::exception const& _e)
// catch (std::exception const& _e) {
// { cnote << "block construction did throw an exception: " << _e.what();
// cnote << "block construction did throw an exception: " << _e.what(); BOOST_ERROR("Failed block construction Test with Exception: " << _e.what());
// BOOST_ERROR("Failed block construction Test with Exception: " << _e.what()); o.erase(o.find("block"));
// o.erase(o.find("block")); }
// } catch(...)
// catch(...) {
// { cnote << "block construction did throw an unknown exception\n";
// cnote << "block construction did throw an unknow exception\n"; o.erase(o.find("block"));
// o.erase(o.find("block")); }
// }
BOOST_REQUIRE(o.count("transactions") > 0); BOOST_REQUIRE(o.count("transactions") > 0);
TransactionQueue txs; TransactionQueue txs;
for (auto const& txObj: o["transactions"].get_array()) for (auto const& txObj: o["transactions"].get_array())
{ {
mObject tx = txObj.get_obj(); mObject tx = txObj.get_obj();
BOOST_REQUIRE(tx.count("nonce") > 0); BOOST_REQUIRE(tx.count("nonce") > 0);
BOOST_REQUIRE(tx.count("gasPrice") > 0); BOOST_REQUIRE(tx.count("gasPrice") > 0);
BOOST_REQUIRE(tx.count("gasLimit") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0);
BOOST_REQUIRE(tx.count("to") > 0); BOOST_REQUIRE(tx.count("to") > 0);
BOOST_REQUIRE(tx.count("value") > 0); BOOST_REQUIRE(tx.count("value") > 0);
BOOST_REQUIRE(tx.count("v") > 0); BOOST_REQUIRE(tx.count("v") > 0);
BOOST_REQUIRE(tx.count("r") > 0); BOOST_REQUIRE(tx.count("r") > 0);
BOOST_REQUIRE(tx.count("s") > 0); BOOST_REQUIRE(tx.count("s") > 0);
BOOST_REQUIRE(tx.count("data") > 0); BOOST_REQUIRE(tx.count("data") > 0);
cout << "attempt to import transaction\n"; cout << "attempt to import transaction\n";
txs.attemptImport(createTransactionFromFields(tx)); txs.attemptImport(createTransactionFromFields(tx));
} }
cout << "done importing txs\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;
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);
//BOOST_REQUIRE(o.count("env") > 0); // create new "genesis" block"
//BOOST_REQUIRE(o.count("pre") > 0);
// ImportTest importer; RLPStream rlpStream;
// importer.importEnv(o["env"].get_obj()); blockFromFields.streamRLP(rlpStream, WithNonce);
// importer.importState(o["pre"].get_obj(), m_statePre);
// State theState = importer.m_statePre; RLPStream block(3);
// bytes output; 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"; cout << "construct bc\n";
CanonBlockChain bc(true); BlockChain bc(block.out(), std::string(), true);
cout << "construct state\n"; cout << "pre difficulty: " << blockFromFields.difficulty << endl;
State theState;
try try
{ {
//cout << "sync state with pre block" << endl;
theState.sync(bc);
cout << "sync bc and txs in state\n"; 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); theState.sync(bc,txs);
cout << "current state diff: " << theState.info().difficulty << endl;
// lock // lock
cout << "commit to mine\n"; cout << "commit to mine\n";
theState.commitToMine(bc); // will call uncommitToMine if a repeat. theState.commitToMine(bc); // will call uncommitToMine if a repeat.
cout << "current state diff: " << theState.info().difficulty << endl;
// unlock // unlock
MineInfo info; MineInfo info;
cout << "mine...\n"; cout << "mine...\n";
@ -201,9 +227,11 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
cout << "done mining, completeMine\n"; cout << "done mining, completeMine\n";
// lock // lock
theState.completeMine(); theState.completeMine();
cout << "current state diff: " << theState.info().difficulty << endl;
// unlock // unlock
cout << "new block: " << theState.blockData() << endl << theState.info() << endl; cout << "new block: " << theState.blockData() << endl << theState.info() << endl;
cout << "current diff: " << theState.info().difficulty << endl;
} }
catch (Exception const& _e) 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(); 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; mObject oBlockHeader;
BlockInfo current_BlockHeader = theState.info(); BlockInfo current_BlockHeader = theState.info();
oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash); oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash);
oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles); oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles);
oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress); oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress);
oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot); oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot);
oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot); oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot);
oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot); oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot);
oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom); oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom);
oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty); oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty);
oBlockHeader["number"] = toString(current_BlockHeader.number); oBlockHeader["number"] = toString(current_BlockHeader.number);
oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit); oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit);
oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed); oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed);
oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp); oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp);
oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData); oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData);
oBlockHeader["nonce"] = toString(current_BlockHeader.nonce); 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. mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles. That will change.
o["uncleHeaders"] = aUncleList; o["uncleHeaders"] = aUncleList;
} }
} }
} }
} }// Namespace Close } }// Namespace Close
@ -250,9 +278,14 @@ void doBlockTests(json_spirit::mValue& _v, bool _fillin)
BOOST_AUTO_TEST_SUITE(BlockTests) 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) //BOOST_AUTO_TEST_CASE(ttCreateTest)

Loading…
Cancel
Save