aboutsummaryrefslogtreecommitdiffstats
path: root/vm.cpp
diff options
context:
space:
mode:
authorCarl Allendorph <callendorph@gmail.com>2014-04-20 01:55:20 +0800
committerCarl Allendorph <callendorph@gmail.com>2014-04-20 01:55:20 +0800
commit16c7fe5dadcf349655d9cd454d31bba9eb7e8722 (patch)
tree6a04c2a23c0fc841031e488c7bc8cb5dd124865b /vm.cpp
parentbf4865adaf6a5a739fff4c5c267b16ac3cfa6eb2 (diff)
downloaddexon-solidity-16c7fe5dadcf349655d9cd454d31bba9eb7e8722.tar.gz
dexon-solidity-16c7fe5dadcf349655d9cd454d31bba9eb7e8722.tar.zst
dexon-solidity-16c7fe5dadcf349655d9cd454d31bba9eb7e8722.zip
Broke the virtual machine unit test out into a separate Boost auto test case.
Diffstat (limited to 'vm.cpp')
-rw-r--r--vm.cpp81
1 files changed, 30 insertions, 51 deletions
diff --git a/vm.cpp b/vm.cpp
index a0b26863..3fe5b399 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -27,12 +27,13 @@
#include <Log.h>
#include <Instruction.h>
#include "JsonSpiritHeaders.h"
+#include <boost/test/unit_test.hpp>
+
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