From eb78b1d5077116bb5fb302cf15fde4f7a82c1a1f Mon Sep 17 00:00:00 2001 From: Carl Allendorph Date: Sat, 19 Apr 2014 10:55:20 -0700 Subject: [PATCH] Broke the virtual machine unit test out into a separate Boost auto test case. --- test/main.cpp | 3 +- test/vm.cpp | 81 +++++++++++++++++++-------------------------------- 2 files changed, 31 insertions(+), 53 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index f5cab4789..4205c6a44 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -45,11 +45,10 @@ BOOST_AUTO_TEST_CASE(basic_tests) std::cout << sha3(s.out()) << std::endl;*/ int r = 0; - r += vmTest(); // r += daggerTest(); // r += stateTest(); // r += peerTest(argc, argv); - BOOST_REQUIRE(!r); +// BOOST_REQUIRE(!r); } diff --git a/test/vm.cpp b/test/vm.cpp index a0b268639..3fe5b399d 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -27,12 +27,13 @@ #include #include #include "JsonSpiritHeaders.h" +#include + using namespace std; using namespace json_spirit; using namespace eth; -namespace eth -{ +namespace eth { namespace test { class FakeExtVM: public ExtVMFace { @@ -311,37 +312,16 @@ public: bytes thisTxData; }; -#define CREATE_TESTS 0 - -template <> class UnitTest<1> -{ -public: - int operator()() - { - json_spirit::mValue v; -#if CREATE_TESTS - string s = asString(contents("../../cpp-ethereum/test/vmtests.json")); - json_spirit::read_string(s, v); - bool passed = doTests(v, true); - cout << json_spirit::write_string(v, true) << endl; -#else - string s = asString(contents("../../tests/vmtests.json")); - json_spirit::read_string(s, v); - bool passed = doTests(v, false); -#endif - return passed ? 0 : 1; - } - - bool doTests(json_spirit::mValue& v, bool _fillin) + void doTests(json_spirit::mValue& v, bool _fillin) { - bool passed = true; for (auto& i: v.get_obj()) + { cnote << i.first; mObject& o = i.second.get_obj(); VM vm; - FakeExtVM fev; + eth::test::FakeExtVM fev; fev.importEnv(o["env"].get_obj()); fev.importState(o["pre"].get_obj()); @@ -365,37 +345,40 @@ public: } else { - FakeExtVM test; + eth::test::FakeExtVM test; test.importState(o["post"].get_obj()); test.importTxs(o["txs"].get_array()); int i = 0; for (auto const& d: o["out"].get_array()) { - if (output[i] != FakeExtVM::toInt(d)) - { - cwarn << "Test failed: output byte" << i << "different."; - passed = false; - } + BOOST_CHECK_MESSAGE( output[i] == FakeExtVM::toInt(d), "Output byte [" << i << "] different!"); ++i; } - - if (test.addresses != fev.addresses) - { - cwarn << "Test failed: state different."; - passed = false; - } - if (test.txs != fev.txs) - { - cwarn << "Test failed: tx list different:"; - cwarn << test.txs; - cwarn << fev.txs; - passed = false; - } + BOOST_CHECK( test.addresses == fev.addresses); + BOOST_CHECK( test.txs == fev.txs ); } } - return passed; } +} } // Namespace Close + +BOOST_AUTO_TEST_CASE(vm_tests) +{ + try + { + cnote << "Testing VM..."; + json_spirit::mValue v; + string s = asString(contents("../../tests/vmtests.json")); + BOOST_REQUIRE_MESSAGE( s.length() > 0, "Contents of 'vmtests.json' is empty. Have you cloned the 'tests' repo branch develop?" ); + json_spirit::read_string(s, v); + eth::test::doTests(v, false); + } + catch( std::exception& e) + { + BOOST_ERROR("Failed VM Test with Exception: " << e.what()); + } +} +#if 0 string makeTestCase() { json_spirit::mObject o; @@ -427,9 +410,5 @@ public: } -int vmTest() -{ - cnote << "Testing VM..."; - return UnitTest<1>()(); -} +#endif