Check State: Block Test + Transaction

This commit is contained in:
winsvega 2015-04-10 20:49:29 +03:00
parent e54952c8cf
commit 47849db473
3 changed files with 96 additions and 63 deletions

View File

@ -53,6 +53,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BOOST_REQUIRE(o.count("pre")); BOOST_REQUIRE(o.count("pre"));
ImportTest importer(o["pre"].get_obj()); ImportTest importer(o["pre"].get_obj());
State state(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); State state(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress);
State stateTemp(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress);
importer.importState(o["pre"].get_obj(), state); importer.importState(o["pre"].get_obj(), state);
o["pre"] = fillJsonWithState(state); o["pre"] = fillJsonWithState(state);
state.commit(); state.commit();
@ -89,7 +90,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
for (auto const& bl: o["blocks"].get_array()) for (auto const& bl: o["blocks"].get_array())
{ {
mObject blObj = bl.get_obj(); mObject blObj = bl.get_obj();
stateTemp = state;
// get txs // get txs
TransactionQueue txs; TransactionQueue txs;
ZeroGasPricer gp; ZeroGasPricer gp;
@ -180,7 +181,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
} }
uncleHeaderObj_pre = uncleHeaderObj; uncleHeaderObj_pre = uncleHeaderObj;
} } //for blObj["uncleHeaders"].get_array()
blObj["uncleHeaders"] = aUncleList; blObj["uncleHeaders"] = aUncleList;
bc.sync(uncleBlockQueue, state.db(), 4); bc.sync(uncleBlockQueue, state.db(), 4);
@ -288,11 +289,10 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
blObj.erase(blObj.find("blockHeader")); blObj.erase(blObj.find("blockHeader"));
blObj.erase(blObj.find("uncleHeaders")); blObj.erase(blObj.find("uncleHeaders"));
blObj.erase(blObj.find("transactions")); blObj.erase(blObj.find("transactions"));
state = State(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); state = stateTemp; //revert state as if it was before executing this block
importer.importState(o["pre"].get_obj(), state);
} }
blArray.push_back(blObj); blArray.push_back(blObj);
} } //for blocks
if (o.count("expect") > 0) if (o.count("expect") > 0)
{ {

View File

@ -36,7 +36,53 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
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)
{
BOOST_REQUIRE(o.count("transaction") > 0);
mObject tObj = o["transaction"].get_obj();
//Construct Rlp of the given transaction
RLPStream rlpStream = createRLPStreamFromTransactionFields(tObj);
o["rlp"] = "0x" + toHex(rlpStream.out());
try
{
Transaction txFromFields(rlpStream.out(), CheckTransaction::Everything);
if (!txFromFields.signature().isValid())
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") );
o["sender"] = toString(txFromFields.sender());
}
catch(Exception const& _e)
{
//Transaction is InValid
cnote << "Transaction Exception: " << diagnostic_information(_e);
o.erase(o.find("transaction"));
if (o.count("expect") > 0)
{
bool expectInValid = (o["expect"].get_str() == "invalid");
if (Options::get().checkState)
BOOST_CHECK_MESSAGE(expectInValid, "Check state: Transaction " << i.first << " is not expected to be invalid!");
else
BOOST_WARN_MESSAGE(expectInValid, "Check state: Transaction " << i.first << " is not expected to be invalid!");
o.erase(o.find("expect"));
}
}
//Transaction is Valid
if (o.count("expect") > 0)
{
bool expectValid = (o["expect"].get_str() == "valid");
if (Options::get().checkState)
BOOST_CHECK_MESSAGE(expectValid, "Check state: Transaction " << i.first << " is not expected to be valid!");
else
BOOST_WARN_MESSAGE(expectValid, "Check state: Transaction " << i.first << " is not expected to be valid!");
o.erase(o.find("expect"));
}
}
else
{ {
BOOST_REQUIRE(o.count("rlp") > 0); BOOST_REQUIRE(o.count("rlp") > 0);
Transaction txFromRlp; Transaction txFromRlp;
@ -80,29 +126,6 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
Address addressReaded = Address(o["sender"].get_str()); Address addressReaded = Address(o["sender"].get_str());
BOOST_CHECK_MESSAGE(txFromFields.sender() == addressReaded || txFromRlp.sender() == addressReaded, "Signature address of sender does not match given sender address!"); BOOST_CHECK_MESSAGE(txFromFields.sender() == addressReaded || txFromRlp.sender() == addressReaded, "Signature address of sender does not match given sender address!");
} }
else
{
BOOST_REQUIRE(o.count("transaction") > 0);
mObject tObj = o["transaction"].get_obj();
//Construct Rlp of the given transaction
RLPStream rlpStream = createRLPStreamFromTransactionFields(tObj);
o["rlp"] = "0x" + toHex(rlpStream.out());
try
{
Transaction txFromFields(rlpStream.out(), CheckTransaction::Everything);
if (!txFromFields.signature().isValid())
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") );
o["sender"] = toString(txFromFields.sender());
}
catch(Exception const& _e)
{
cnote << "Transaction Exception: " << diagnostic_information(_e);
o.erase(o.find("transaction"));
}
}
}//for }//for
}//doTransactionTests }//doTransactionTests

View File

@ -1,5 +1,6 @@
{ {
"RightVRSTest" : { "RightVRSTest" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",
@ -15,6 +16,7 @@
}, },
"V_overflow32bit" : { "V_overflow32bit" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",
@ -30,6 +32,7 @@
}, },
"V_overflow32bitSigned" : { "V_overflow32bitSigned" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",
@ -45,6 +48,7 @@
}, },
"V_overflow64bit" : { "V_overflow64bit" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",
@ -60,6 +64,7 @@
}, },
"V_overflow64bitSigned" : { "V_overflow64bitSigned" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",
@ -75,6 +80,7 @@
}, },
"WrongVRSTestVEqual26" : { "WrongVRSTestVEqual26" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -90,6 +96,7 @@
}, },
"WrongVRSTestVEqual29" : { "WrongVRSTestVEqual29" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -105,6 +112,7 @@
}, },
"WrongVRSTestVEqual31" : { "WrongVRSTestVEqual31" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -120,6 +128,7 @@
}, },
"WrongVRSTestVOverflow" : { "WrongVRSTestVOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -135,6 +144,7 @@
}, },
"WrongVRSTestIncorrectSize" : { "WrongVRSTestIncorrectSize" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -151,6 +161,7 @@
"SenderTest" : { "SenderTest" : {
"//" : "sender a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "//" : "sender a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -167,6 +178,7 @@
}, },
"DataTest" : { "DataTest" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "0x0358ac39584bc98a7c979f984b03", "data" : "0x0358ac39584bc98a7c979f984b03",
@ -183,6 +195,7 @@
}, },
"TransactionWithTooManyRLPElements" : { "TransactionWithTooManyRLPElements" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -199,6 +212,7 @@
}, },
"TransactionWithTooFewRLPElements" : { "TransactionWithTooFewRLPElements" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -212,6 +226,7 @@
}, },
"TransactionWithHihghValue" : { "TransactionWithHihghValue" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -228,6 +243,7 @@
"TransactionWithHihghValueOverflow" : { "TransactionWithHihghValueOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -243,6 +259,7 @@
}, },
"TransactionWithSvalueHigh" : { "TransactionWithSvalueHigh" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -258,6 +275,7 @@
}, },
"TransactionWithSvalueTooHigh" : { "TransactionWithSvalueTooHigh" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -273,6 +291,7 @@
}, },
"TransactionWithSvalueOverflow" : { "TransactionWithSvalueOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -288,6 +307,7 @@
}, },
"TransactionWithRvalueOverflow" : { "TransactionWithRvalueOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -303,6 +323,7 @@
}, },
"TransactionWithRvalueHigh" : { "TransactionWithRvalueHigh" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -318,6 +339,7 @@
}, },
"TransactionWithRvalueTooHigh" : { "TransactionWithRvalueTooHigh" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -333,6 +355,7 @@
}, },
"TransactionWithRvalueWrongSize" : { "TransactionWithRvalueWrongSize" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -348,6 +371,7 @@
}, },
"TransactionWithSvalueWrongSize" : { "TransactionWithSvalueWrongSize" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -363,6 +387,7 @@
}, },
"TransactionWithHihghNonce" : { "TransactionWithHihghNonce" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -378,6 +403,7 @@
}, },
"TransactionWithNonceOverflow" : { "TransactionWithNonceOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -393,6 +419,7 @@
}, },
"TransactionWithHihghGas" : { "TransactionWithHihghGas" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -408,6 +435,7 @@
}, },
"TransactionWithHihghGasPrice" : { "TransactionWithHihghGasPrice" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -423,6 +451,7 @@
}, },
"TransactionWithGasLimitxPriceOverflow" : { "TransactionWithGasLimitxPriceOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -438,6 +467,7 @@
}, },
"TransactionWithGasPriceOverflow" : { "TransactionWithGasPriceOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -453,6 +483,7 @@
}, },
"TransactionWithGasLimitOverflow" : { "TransactionWithGasLimitOverflow" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -468,6 +499,7 @@
}, },
"AddressMoreThan20PrefixedBy0" : { "AddressMoreThan20PrefixedBy0" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "0x12", "data" : "0x12",
@ -483,14 +515,15 @@
}, },
"EmptyTransaction" : { "EmptyTransaction" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
"gasLimit" : "", "gasLimit" : "0",
"gasPrice" : "", "gasPrice" : "0",
"nonce" : "", "nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "", "value" : "0",
"v" : "27", "v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" "s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
@ -498,6 +531,7 @@
}, },
"AddressMoreThan20" : { "AddressMoreThan20" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -513,6 +547,7 @@
}, },
"AddressLessThan20" : { "AddressLessThan20" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -528,6 +563,7 @@
}, },
"AddressLessThan20Prefixed0" : { "AddressLessThan20Prefixed0" : {
"expect" : "invalid",
"transaction" : "transaction" :
{ {
"data" : "", "data" : "",
@ -542,37 +578,8 @@
} }
}, },
"ValuesAsHex" : {
"transaction" :
{
"data" : "",
"gasLimit" : "0xadc053",
"gasPrice" : "1",
"nonce" : "0xffdc5",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "4294820140",
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"ValuesAsDec" : {
"transaction" :
{
"data" : "",
"gasLimit" : "11386963",
"gasPrice" : "1",
"nonce" : "1048005",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "4501151495864620",
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"unpadedRValue": { "unpadedRValue": {
"expect" : "valid",
"transaction": { "transaction": {
"nonce": "13", "nonce": "13",
"gasPrice": "0x09184e72a000", "gasPrice": "0x09184e72a000",
@ -587,6 +594,7 @@
}, },
"libsecp256k1test": { "libsecp256k1test": {
"expect" : "valid",
"transaction": { "transaction": {
"nonce": "", "nonce": "",
"gasPrice": "0x09184e72a000", "gasPrice": "0x09184e72a000",
@ -601,6 +609,7 @@
}, },
"dataTx_bcValidBlockTest": { "dataTx_bcValidBlockTest": {
"expect" : "valid",
"transaction": { "transaction": {
"nonce": "0", "nonce": "0",
"gasPrice": "50", "gasPrice": "50",
@ -615,6 +624,7 @@
}, },
"RSsecp256k1" : { "RSsecp256k1" : {
"expect" : "valid",
"transaction" : "transaction" :
{ {
"data" : "0x5544", "data" : "0x5544",