TransactionTest

Incorrect receiver address ength
This commit is contained in:
winsvega 2015-02-07 01:13:02 +03:00
parent 4d76086860
commit b8a07a22be
2 changed files with 86 additions and 67 deletions

View File

@ -28,31 +28,48 @@ using namespace dev::eth;
namespace dev { namespace test {
Transaction createTransactionFromFields(mObject& _tObj)
RLPStream createRLPStreamFromTransactionFields(mObject& _tObj)
{
BOOST_REQUIRE(_tObj.count("data") > 0);
BOOST_REQUIRE(_tObj.count("value") > 0);
BOOST_REQUIRE(_tObj.count("gasPrice") > 0);
BOOST_REQUIRE(_tObj.count("gasLimit") > 0);
BOOST_REQUIRE(_tObj.count("nonce")> 0);
BOOST_REQUIRE(_tObj.count("to") > 0);
BOOST_REQUIRE(_tObj.count("v") > 0);
BOOST_REQUIRE(_tObj.count("r") > 0);
BOOST_REQUIRE(_tObj.count("s") > 0);
//Construct Rlp of the given transaction
RLPStream rlpStream;
rlpStream.appendList(9);
rlpStream << bigint(_tObj["nonce"].get_str()) << bigint(_tObj["gasPrice"].get_str()) << bigint(_tObj["gasLimit"].get_str());
rlpStream.appendList(_tObj.size());
if (_tObj.count("nonce") > 0)
rlpStream << bigint(_tObj["nonce"].get_str());
if (_tObj.count("gasPrice") > 0)
rlpStream << bigint(_tObj["gasPrice"].get_str());
if (_tObj.count("gasLimit") > 0)
rlpStream << bigint(_tObj["gasLimit"].get_str());
if (_tObj.count("to") > 0)
{
if (_tObj["to"].get_str().empty())
rlpStream << "";
else
rlpStream << Address(_tObj["to"].get_str());
rlpStream << bigint(_tObj["value"].get_str()) << importData(_tObj);
rlpStream << bigint(_tObj["v"].get_str()) << bigint(_tObj["r"].get_str()) << bigint(_tObj["s"].get_str());
rlpStream << importByteArray(_tObj["to"].get_str());
}
return Transaction(rlpStream.out(), CheckSignature::Sender);
if (_tObj.count("value") > 0)
rlpStream << bigint(_tObj["value"].get_str());
if (_tObj.count("data") > 0)
rlpStream << importData(_tObj);
if (_tObj.count("v") > 0)
rlpStream << bigint(_tObj["v"].get_str());
if (_tObj.count("r") > 0)
rlpStream << bigint(_tObj["r"].get_str());
if (_tObj.count("s") > 0)
rlpStream << bigint(_tObj["s"].get_str());
if (_tObj.count("extrafield") > 0)
rlpStream << bigint(_tObj["extrafield"].get_str());
return rlpStream;
}
void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
@ -83,7 +100,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
BOOST_REQUIRE(o.count("transaction") > 0);
mObject tObj = o["transaction"].get_obj();
Transaction txFromFields = createTransactionFromFields(tObj);
Transaction txFromFields(createRLPStreamFromTransactionFields(tObj).out(),CheckSignature::Sender);
//Check the fields restored from RLP to original fields
BOOST_CHECK_MESSAGE(txFromFields.data() == txFromRlp.data(), "Data in given RLP not matching the Transaction data!");
@ -105,44 +122,7 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
mObject tObj = o["transaction"].get_obj();
//Construct Rlp of the given transaction
RLPStream rlpStream;
rlpStream.appendList(tObj.size());
if (tObj.count("nonce") > 0)
rlpStream << bigint(tObj["nonce"].get_str());
if (tObj.count("gasPrice") > 0)
rlpStream << bigint(tObj["gasPrice"].get_str());
if (tObj.count("gasLimit") > 0)
rlpStream << bigint(tObj["gasLimit"].get_str());
if (tObj.count("to") > 0)
{
if (tObj["to"].get_str().empty())
rlpStream << "";
else
rlpStream << Address(tObj["to"].get_str());
}
if (tObj.count("value") > 0)
rlpStream << bigint(tObj["value"].get_str());
if (tObj.count("data") > 0)
rlpStream << importData(tObj);
if (tObj.count("v") > 0)
rlpStream << bigint(tObj["v"].get_str());
if (tObj.count("r") > 0)
rlpStream << bigint(tObj["r"].get_str());
if (tObj.count("s") > 0)
rlpStream << bigint(tObj["s"].get_str());
if (tObj.count("extrafield") > 0)
rlpStream << bigint(tObj["extrafield"].get_str());
RLPStream rlpStream = createRLPStreamFromTransactionFields(tObj);
o["rlp"] = "0x" + toHex(rlpStream.out());
try
@ -151,9 +131,6 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
if (!txFromFields.signature().isValid())
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("transaction from RLP signature is invalid") );
//cause Address is length20 array, when trying to create address from sting of another length, field "to" would be diffrent from RLP encoded Address
BOOST_CHECK_MESSAGE(Address(tObj["to"].get_str()) == txFromFields.receiveAddress(), "seems that transaction 'to' address has wrong format");
o["sender"] = toString(txFromFields.sender());
}
catch(...)
@ -163,7 +140,6 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
}
}//for
}//doTransactionTests
} }// Namespace Close

View File

@ -11,7 +11,6 @@
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
@ -255,6 +254,50 @@
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
}
},
"AddressMoreThan20" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b1c",
"value" : "10",
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"AddressLessThan20" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "b9331677e6ebf",
"value" : "10",
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"AddressLessThan20Prefixed0" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "0x000000000000000000000000000b9331677e6ebf",
"value" : "10",
"v" : "28",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
}
}