|
|
@ -25,12 +25,16 @@ |
|
|
|
#include <test/TestHelper.h> |
|
|
|
#include <test/fuzzTesting/fuzzHelper.h> |
|
|
|
|
|
|
|
|
|
|
|
//String Variables
|
|
|
|
extern std::string const c_testExampleStateTest; |
|
|
|
extern std::string const c_testExampleTransactionTest; |
|
|
|
|
|
|
|
//Main Test functinos
|
|
|
|
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString); |
|
|
|
|
|
|
|
//Helper Functions
|
|
|
|
std::vector<std::string> getTypes(); |
|
|
|
void parseTestWithTypes(std::string& test); |
|
|
|
void randomTransactionTest(); |
|
|
|
void randomBlockChainTest(); |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
@ -44,7 +48,7 @@ int main(int argc, char *argv[]) |
|
|
|
if (arg == "-t" && i + 1 < argc) |
|
|
|
{ |
|
|
|
testSuite = argv[i + 1]; |
|
|
|
if (testSuite != "BlockChainTests" && testSuite != "TransactionTests") |
|
|
|
if (testSuite != "BlockChainTests" && testSuite != "TransactionTests" && testSuite != "StateTests") |
|
|
|
testSuite = ""; |
|
|
|
} |
|
|
|
} |
|
|
@ -53,15 +57,18 @@ int main(int argc, char *argv[]) |
|
|
|
std::cout << "Error! Test suite not supported! (Usage -t TestSuite)"; |
|
|
|
else |
|
|
|
if (testSuite == "BlockChainTests") |
|
|
|
randomBlockChainTest(); |
|
|
|
fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest); |
|
|
|
else |
|
|
|
if (testSuite == "TransactionTests") |
|
|
|
randomTransactionTest(); |
|
|
|
fillRandomTest(dev::test::doTransactionTests, c_testExampleTransactionTest); |
|
|
|
else |
|
|
|
if (testSuite == "StateTests") |
|
|
|
fillRandomTest(dev::test::doStateTests, c_testExampleStateTest); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void randomTransactionTest() |
|
|
|
void fillRandomTest(std::function<void(json_spirit::mValue&, bool)> doTests, std::string const& testString) |
|
|
|
{ |
|
|
|
//redirect all output to the stream
|
|
|
|
std::ostringstream strCout; |
|
|
@ -72,10 +79,10 @@ void randomTransactionTest() |
|
|
|
json_spirit::mValue v; |
|
|
|
try |
|
|
|
{ |
|
|
|
std::string newTest = c_testExampleTransactionTest; |
|
|
|
std::string newTest = testString; |
|
|
|
parseTestWithTypes(newTest); |
|
|
|
json_spirit::read_string(newTest, v); |
|
|
|
dev::test::doTransactionTests(v, true); |
|
|
|
doTests(v, true); |
|
|
|
} |
|
|
|
catch(...) |
|
|
|
{ |
|
|
@ -88,55 +95,67 @@ void randomTransactionTest() |
|
|
|
std::cout << json_spirit::write_string(v, true); |
|
|
|
} |
|
|
|
|
|
|
|
void randomBlockChainTest() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// Parse Test string replacing keywords to fuzzed values
|
|
|
|
void parseTestWithTypes(std::string& test) |
|
|
|
void parseTestWithTypes(std::string& _test) |
|
|
|
{ |
|
|
|
dev::test::RandomCodeOptions options; |
|
|
|
options.setWeight(dev::eth::Instruction::STOP, 10); //default 50
|
|
|
|
options.setWeight(dev::eth::Instruction::SSTORE, 70); |
|
|
|
options.setWeight(dev::eth::Instruction::CALL, 75); |
|
|
|
options.addAddress(dev::Address("0xffffffffffffffffffffffffffffffffffffffff")); |
|
|
|
options.addAddress(dev::Address("0x1000000000000000000000000000000000000000")); |
|
|
|
options.addAddress(dev::Address("0x095e7baea6a6c7c4c2dfeb977efac326af552d87")); |
|
|
|
options.addAddress(dev::Address("0x945304eb96065b2a98b57a48a06ae28d285a71b5")); |
|
|
|
options.addAddress(dev::Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")); |
|
|
|
options.addAddress(dev::Address("0x0000000000000000000000000000000000000001")); |
|
|
|
options.addAddress(dev::Address("0x0000000000000000000000000000000000000002")); |
|
|
|
options.addAddress(dev::Address("0x0000000000000000000000000000000000000003")); |
|
|
|
options.addAddress(dev::Address("0x0000000000000000000000000000000000000004")); |
|
|
|
options.smartCodeProbability = 35; |
|
|
|
|
|
|
|
std::vector<std::string> types = getTypes(); |
|
|
|
for (unsigned i = 0; i < types.size(); i++) |
|
|
|
{ |
|
|
|
std::size_t pos = test.find(types.at(i)); |
|
|
|
std::size_t pos = _test.find(types.at(i)); |
|
|
|
while (pos != std::string::npos) |
|
|
|
{ |
|
|
|
if (types.at(i) == "[CODE]") |
|
|
|
test.replace(pos, 6, "0x"+dev::test::RandomCode::generate(10)); |
|
|
|
_test.replace(pos, 6, "0x"+dev::test::RandomCode::generate(10, options)); |
|
|
|
else |
|
|
|
if (types.at(i) == "[HEX]") |
|
|
|
test.replace(pos, 5, dev::test::RandomCode::randomUniIntHex()); |
|
|
|
_test.replace(pos, 5, dev::test::RandomCode::randomUniIntHex()); |
|
|
|
else |
|
|
|
if (types.at(i) == "[HASH20]") |
|
|
|
test.replace(pos, 8, dev::test::RandomCode::rndByteSequence(20)); |
|
|
|
_test.replace(pos, 8, dev::test::RandomCode::rndByteSequence(20)); |
|
|
|
else |
|
|
|
if (types.at(i) == "[0xHASH32]") |
|
|
|
test.replace(pos, 10, "0x" + dev::test::RandomCode::rndByteSequence(32)); |
|
|
|
_test.replace(pos, 10, "0x" + dev::test::RandomCode::rndByteSequence(32)); |
|
|
|
else |
|
|
|
if (types.at(i) == "[HASH32]") |
|
|
|
_test.replace(pos, 8, dev::test::RandomCode::rndByteSequence(32)); |
|
|
|
else |
|
|
|
if (types.at(i) == "[V]") |
|
|
|
{ |
|
|
|
int random = dev::test::RandomCode::randomUniInt() % 100; |
|
|
|
if (random < 30) |
|
|
|
test.replace(pos, 3, "28"); |
|
|
|
_test.replace(pos, 3, "28"); |
|
|
|
else |
|
|
|
if (random < 60) |
|
|
|
test.replace(pos, 3, "29"); |
|
|
|
_test.replace(pos, 3, "29"); |
|
|
|
else |
|
|
|
test.replace(pos, 3, "0x" + dev::test::RandomCode::rndByteSequence(1)); |
|
|
|
_test.replace(pos, 3, "0x" + dev::test::RandomCode::rndByteSequence(1)); |
|
|
|
} |
|
|
|
|
|
|
|
pos = test.find(types.at(i)); |
|
|
|
pos = _test.find(types.at(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<std::string> getTypes() |
|
|
|
{ |
|
|
|
return {"[CODE]", "[HEX]", "[HASH20]", "[0xHASH32]", "[V]"}; |
|
|
|
return {"[CODE]", "[HEX]", "[HASH20]", "[HASH32]", "[0xHASH32]", "[V]"}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string const c_testExampleTransactionTest = R"( |
|
|
|
{ |
|
|
|
"TransactionTest" : { |
|
|
@ -156,5 +175,49 @@ std::string const c_testExampleTransactionTest = R"( |
|
|
|
} |
|
|
|
)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string const c_testExampleStateTest = R"( |
|
|
|
{ |
|
|
|
"randomStatetest" : { |
|
|
|
"env" : { |
|
|
|
"currentCoinbase" : "[HASH20]", |
|
|
|
"currentDifficulty" : "[HEX]", |
|
|
|
"currentGasLimit" : "[HEX]", |
|
|
|
"currentNumber" : "[HEX]", |
|
|
|
"currentTimestamp" : "[HEX]", |
|
|
|
"previousHash" : "[HASH32]" |
|
|
|
}, |
|
|
|
"pre" : { |
|
|
|
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : { |
|
|
|
"balance" : "[HEX]", |
|
|
|
"code" : "[CODE]", |
|
|
|
"nonce" : "[V]", |
|
|
|
"storage" : { |
|
|
|
} |
|
|
|
}, |
|
|
|
"945304eb96065b2a98b57a48a06ae28d285a71b5" : { |
|
|
|
"balance" : "[HEX]", |
|
|
|
"code" : "[CODE]", |
|
|
|
"nonce" : "[V]", |
|
|
|
"storage" : { |
|
|
|
} |
|
|
|
}, |
|
|
|
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
|
|
|
"balance" : "[HEX]", |
|
|
|
"code" : "0x", |
|
|
|
"nonce" : "0", |
|
|
|
"storage" : { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
"transaction" : { |
|
|
|
"data" : "[CODE]", |
|
|
|
"gasLimit" : "[HEX]", |
|
|
|
"gasPrice" : "[V]", |
|
|
|
"nonce" : "0", |
|
|
|
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
|
|
|
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", |
|
|
|
"value" : "[HEX]" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)"; |
|
|
|