aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwinsvega <winsvega@mail.ru>2015-04-11 01:49:29 +0800
committerwinsvega <winsvega@mail.ru>2015-04-13 17:20:12 +0800
commit47849db473e8ed71281209823c6c2823931f0462 (patch)
tree8936ef388bb19ac5f74234ba528e2eacc6a1625e
parente54952c8cf718fb1b7af853bead145292c7f25db (diff)
downloaddexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar.gz
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar.bz2
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar.lz
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar.xz
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.tar.zst
dexon-solidity-47849db473e8ed71281209823c6c2823931f0462.zip
Check State: Block Test + Transaction
-rw-r--r--blockchain.cpp10
-rw-r--r--transaction.cpp71
-rw-r--r--ttTransactionTestFiller.json78
3 files changed, 96 insertions, 63 deletions
diff --git a/blockchain.cpp b/blockchain.cpp
index b225d313..23bfd665 100644
--- a/blockchain.cpp
+++ b/blockchain.cpp
@@ -53,6 +53,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BOOST_REQUIRE(o.count("pre"));
ImportTest importer(o["pre"].get_obj());
State state(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress);
+ State stateTemp(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress);
importer.importState(o["pre"].get_obj(), state);
o["pre"] = fillJsonWithState(state);
state.commit();
@@ -89,7 +90,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
for (auto const& bl: o["blocks"].get_array())
{
mObject blObj = bl.get_obj();
-
+ stateTemp = state;
// get txs
TransactionQueue txs;
ZeroGasPricer gp;
@@ -180,7 +181,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
}
uncleHeaderObj_pre = uncleHeaderObj;
- }
+ } //for blObj["uncleHeaders"].get_array()
blObj["uncleHeaders"] = aUncleList;
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("uncleHeaders"));
blObj.erase(blObj.find("transactions"));
- state = State(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress);
- importer.importState(o["pre"].get_obj(), state);
+ state = stateTemp; //revert state as if it was before executing this block
}
blArray.push_back(blObj);
- }
+ } //for blocks
if (o.count("expect") > 0)
{
diff --git a/transaction.cpp b/transaction.cpp
index 7aa073f2..daf8368d 100644
--- a/transaction.cpp
+++ b/transaction.cpp
@@ -36,8 +36,54 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
cerr << i.first << endl;
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);
Transaction txFromRlp;
try
@@ -80,29 +126,6 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
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!");
}
- 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
}//doTransactionTests
diff --git a/ttTransactionTestFiller.json b/ttTransactionTestFiller.json
index cb39b533..b75947e8 100644
--- a/ttTransactionTestFiller.json
+++ b/ttTransactionTestFiller.json
@@ -1,5 +1,6 @@
{
"RightVRSTest" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "0x5544",
@@ -15,6 +16,7 @@
},
"V_overflow32bit" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "0x5544",
@@ -30,6 +32,7 @@
},
"V_overflow32bitSigned" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "0x5544",
@@ -45,6 +48,7 @@
},
"V_overflow64bit" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "0x5544",
@@ -60,6 +64,7 @@
},
"V_overflow64bitSigned" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "0x5544",
@@ -75,6 +80,7 @@
},
"WrongVRSTestVEqual26" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -90,6 +96,7 @@
},
"WrongVRSTestVEqual29" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -105,6 +112,7 @@
},
"WrongVRSTestVEqual31" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -120,6 +128,7 @@
},
"WrongVRSTestVOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -135,6 +144,7 @@
},
"WrongVRSTestIncorrectSize" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -151,6 +161,7 @@
"SenderTest" : {
"//" : "sender a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -167,6 +178,7 @@
},
"DataTest" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "0x0358ac39584bc98a7c979f984b03",
@@ -183,6 +195,7 @@
},
"TransactionWithTooManyRLPElements" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -199,6 +212,7 @@
},
"TransactionWithTooFewRLPElements" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -212,6 +226,7 @@
},
"TransactionWithHihghValue" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -228,6 +243,7 @@
"TransactionWithHihghValueOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -243,6 +259,7 @@
},
"TransactionWithSvalueHigh" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -258,6 +275,7 @@
},
"TransactionWithSvalueTooHigh" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -273,6 +291,7 @@
},
"TransactionWithSvalueOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -288,6 +307,7 @@
},
"TransactionWithRvalueOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -303,6 +323,7 @@
},
"TransactionWithRvalueHigh" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -318,6 +339,7 @@
},
"TransactionWithRvalueTooHigh" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -333,6 +355,7 @@
},
"TransactionWithRvalueWrongSize" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -348,6 +371,7 @@
},
"TransactionWithSvalueWrongSize" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -363,6 +387,7 @@
},
"TransactionWithHihghNonce" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -378,6 +403,7 @@
},
"TransactionWithNonceOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -393,6 +419,7 @@
},
"TransactionWithHihghGas" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -408,6 +435,7 @@
},
"TransactionWithHihghGasPrice" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
@@ -423,6 +451,7 @@
},
"TransactionWithGasLimitxPriceOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -438,6 +467,7 @@
},
"TransactionWithGasPriceOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -453,6 +483,7 @@
},
"TransactionWithGasLimitOverflow" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -468,6 +499,7 @@
},
"AddressMoreThan20PrefixedBy0" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "0x12",
@@ -483,14 +515,15 @@
},
"EmptyTransaction" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "",
- "gasLimit" : "",
- "gasPrice" : "",
- "nonce" : "",
+ "gasLimit" : "0",
+ "gasPrice" : "0",
+ "nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "",
+ "value" : "0",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
@@ -498,6 +531,7 @@
},
"AddressMoreThan20" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -513,6 +547,7 @@
},
"AddressLessThan20" : {
+ "expect" : "invalid",
"transaction" :
{
"data" : "",
@@ -528,6 +563,7 @@
},
"AddressLessThan20Prefixed0" : {
+ "expect" : "invalid",
"transaction" :
{
"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": {
+ "expect" : "valid",
"transaction": {
"nonce": "13",
"gasPrice": "0x09184e72a000",
@@ -587,6 +594,7 @@
},
"libsecp256k1test": {
+ "expect" : "valid",
"transaction": {
"nonce": "",
"gasPrice": "0x09184e72a000",
@@ -601,6 +609,7 @@
},
"dataTx_bcValidBlockTest": {
+ "expect" : "valid",
"transaction": {
"nonce": "0",
"gasPrice": "50",
@@ -615,6 +624,7 @@
},
"RSsecp256k1" : {
+ "expect" : "valid",
"transaction" :
{
"data" : "0x5544",