Fix remaining gas testing [#81118624]

This commit is contained in:
Paweł Bylica 2014-10-21 19:42:24 +02:00
parent af47913b16
commit d6ec0a1248

33
vm.cpp
View File

@ -512,37 +512,35 @@ void doTests(json_spirit::mValue& v, bool _fillin)
fev.code = &fev.thisTxCode; fev.code = &fev.thisTxCode;
} }
auto argc = boost::unit_test::framework::master_test_suite().argc;
auto argv = boost::unit_test::framework::master_test_suite().argv;
auto useJit = argc >= 2 && std::string(argv[1]) == "--jit";
jit::VM jit(fev.gas);
VM interpreter(fev.gas);
bytes output; bytes output;
u256 gas; auto outOfGas = false;
try try
{ {
auto argc = boost::unit_test::framework::master_test_suite().argc;
auto argv = boost::unit_test::framework::master_test_suite().argv;
auto useJit = argc >= 2 && std::string(argv[1]) == "--jit";
if (useJit) if (useJit)
{ output = jit.go(fev);
jit::VM vm(fev.gas);
output = vm.go(fev);
gas = vm.gas();
}
else else
{ output = interpreter.go(fev).toVector();
VM vm(fev.gas);
output = vm.go(fev).toVector();
gas = vm.gas(); // Get the remaining gas
} }
catch (OutOfGas const&)
{
outOfGas = true;
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
cnote << "VM did throw an exception: " << diagnostic_information(_e); cnote << "VM did throw an exception: " << diagnostic_information(_e);
//BOOST_ERROR("Failed VM Test with Exception: " << e.what());
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
cnote << "VM did throw an exception: " << _e.what(); cnote << "VM did throw an exception: " << _e.what();
//BOOST_ERROR("Failed VM Test with Exception: " << e.what());
} }
auto gas = useJit ? jit.gas() : interpreter.gas();
// delete null entries in storage for the sake of comparison // delete null entries in storage for the sake of comparison
@ -593,6 +591,9 @@ void doTests(json_spirit::mValue& v, bool _fillin)
BOOST_CHECK(output == fromHex(o["out"].get_str())); BOOST_CHECK(output == fromHex(o["out"].get_str()));
BOOST_CHECK_EQUAL(test.toInt(o["gas"]), gas); BOOST_CHECK_EQUAL(test.toInt(o["gas"]), gas);
if (outOfGas)
BOOST_CHECK_MESSAGE(gas == 0, "Remaining gas not 0 in out-of-gas state");
auto& expectedAddrs = test.addresses; auto& expectedAddrs = test.addresses;
auto& resultAddrs = fev.addresses; auto& resultAddrs = fev.addresses;