add valid tx output

This commit is contained in:
CJentzsch 2015-02-12 20:13:44 +01:00
parent 004918d400
commit f3e9c325d1
3 changed files with 266 additions and 75 deletions

View File

@ -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"
}]
}
}

View File

@ -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" : [
]
}
}

122
block.cpp
View File

@ -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)