From 389b0973c4ef343faf3b35fec4d7859ad0a5c4e1 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 12 Jan 2015 12:46:40 +0100 Subject: [PATCH 1/7] start with block info opcodes --- test/createRandomTest.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index 1af12f64d..40ed1aa9c 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -54,18 +54,26 @@ int main(int argc, char *argv[]) gen.seed(static_cast(timeSinceEpoch)); boost::random::uniform_int_distribution<> lengthOfCodeDist(2, 16); boost::random::uniform_int_distribution<> opcodeDist(0, 255); + boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x41, 0x45); boost::random::variate_generator > randGen(gen, opcodeDist); + boost::random::variate_generator > randGenBlockInfoOpcode(gen, BlockInfoOpcodeDist); int lengthOfCode = lengthOfCodeDist(gen); string randomCode; for (int i = 0; i < lengthOfCode; ++i) { - uint8_t opcode = randGen(); + if (i < 8 && (randGen() < 192)) + { + randomCode += toHex(toCompactBigEndian((uint8_t)randGenBlockInfoOpcode())); + continue; + } - // disregard all invalid commands, except of one (0x10) - if (dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || opcode == 0x10) + uint8_t opcode = randGen(); + // disregard all invalid commands, except of one (0x0c) + if (dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || opcode == 0x0a) randomCode += toHex(toCompactBigEndian(opcode)); else i--; @@ -77,9 +85,9 @@ int main(int argc, char *argv[]) \"env\" : {\n\ \"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\ \"currentNumber\" : \"0\",\n\ - \"currentGasLimit\" : \"1000000\",\n\ - \"currentDifficulty\" : \"256\",\n\ - \"currentTimestamp\" : 1,\n\ + \"currentGasLimit\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ + \"currentDifficulty\" : \"1\",\n\ + \"currentTimestamp\" : 2,\n\ \"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\ },\n\ \"pre\" : {\n\ @@ -106,7 +114,7 @@ int main(int argc, char *argv[]) read_string(s, v); // insert new random code - v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode; + v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + "55"; // execute code in vm doMyTests(v); From 070d1d800c8f830f095b0c1fd099f17e09865446 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 12 Jan 2015 15:42:28 +0100 Subject: [PATCH 2/7] rests current gas limit in vm test --- test/createRandomTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index 40ed1aa9c..d9638cebe 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -85,8 +85,8 @@ int main(int argc, char *argv[]) \"env\" : {\n\ \"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\ \"currentNumber\" : \"0\",\n\ - \"currentGasLimit\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ - \"currentDifficulty\" : \"1\",\n\ + \"currentGasLimit\" : \"1000000\",\n\ + \"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ \"currentTimestamp\" : 2,\n\ \"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\ },\n\ From 720f49e19ade9319daf5086632000a2879242257 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 13 Jan 2015 09:53:46 +0100 Subject: [PATCH 3/7] reinclude invalid opcode in random tests --- test/createRandomTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index d9638cebe..d2522cf47 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) gen.seed(static_cast(timeSinceEpoch)); boost::random::uniform_int_distribution<> lengthOfCodeDist(2, 16); boost::random::uniform_int_distribution<> opcodeDist(0, 255); - boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x41, 0x45); + boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x40, 0x45); boost::random::variate_generator > randGen(gen, opcodeDist); boost::random::variate_generator Date: Tue, 13 Jan 2015 14:38:36 +0100 Subject: [PATCH 4/7] random test optimization --- test/createRandomTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index d2522cf47..b3a704e9d 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) \"currentNumber\" : \"0\",\n\ \"currentGasLimit\" : \"1000000\",\n\ \"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ - \"currentTimestamp\" : 5,\n\ + \"currentTimestamp\" : 2,\n\ \"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\ },\n\ \"pre\" : {\n\ From 607c71e785b78306455d8ac0047ea499736fc2ba Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 13 Jan 2015 17:58:14 +0100 Subject: [PATCH 5/7] more randomness in the optimizations --- test/createRandomTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index b3a704e9d..37d61fac9 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) uint8_t opcode = randGen(); // disregard all invalid commands, except of one (0x0c) - if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (opcode == 0x0c))) + if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 128))) randomCode += toHex(toCompactBigEndian(opcode)); else i--; @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) \"randomVMtest\": {\n\ \"env\" : {\n\ \"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\ - \"currentNumber\" : \"0\",\n\ + \"currentNumber\" : \"300\",\n\ \"currentGasLimit\" : \"1000000\",\n\ \"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\ \"currentTimestamp\" : 2,\n\ @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) read_string(s, v); // insert new random code - v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + "55"; + v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + (randGen() > 128 ? "55" : ""); // execute code in vm doMyTests(v); From 3d01e66c1d2812f670287abc314983e592534cd6 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 13 Jan 2015 18:00:00 +0100 Subject: [PATCH 6/7] replace BOOST_REQUIRE with assert, because it is used outside the boost test framework --- test/vm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/vm.cpp b/test/vm.cpp index 8b8c75a04..42113e7b6 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -232,10 +232,10 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) for (mValue& v: _callcreates) { auto tx = v.get_obj(); - BOOST_REQUIRE(tx.count("data") > 0); - BOOST_REQUIRE(tx.count("value") > 0); - BOOST_REQUIRE(tx.count("destination") > 0); - BOOST_REQUIRE(tx.count("gasLimit") > 0); + assert(tx.count("data") > 0); + assert(tx.count("value") > 0); + assert(tx.count("destination") > 0); + assert(tx.count("gasLimit") > 0); Transaction t = tx["destination"].get_str().empty() ? Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data.toBytes()) : Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data.toBytes()); From 5ff846e1c76347f1b309f7aecb23f9bf9cb85949 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 14 Jan 2015 09:39:21 +0100 Subject: [PATCH 7/7] less invalid opcode tests --- test/createRandomTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/createRandomTest.cpp b/test/createRandomTest.cpp index 37d61fac9..a913d697f 100644 --- a/test/createRandomTest.cpp +++ b/test/createRandomTest.cpp @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) uint8_t opcode = randGen(); // disregard all invalid commands, except of one (0x0c) - if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 128))) + if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 250))) randomCode += toHex(toCompactBigEndian(opcode)); else i--;