mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Broke the virtual machine unit test out into a separate Boost auto test case.
This commit is contained in:
parent
bf4865adaf
commit
16c7fe5dad
3
main.cpp
3
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);
|
||||
}
|
||||
|
||||
|
81
vm.cpp
81
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()()
|
||||
void doTests(json_spirit::mValue& v, bool _fillin)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user