mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
In VM tests, check only if an exception occurred if an exception expected (no post state and output checking)
This commit is contained in:
parent
9544173e3b
commit
7df5ec34c7
@ -374,6 +374,7 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun
|
|||||||
{
|
{
|
||||||
BOOST_ERROR("Failed test with Exception: " << _e.what());
|
BOOST_ERROR("Failed test with Exception: " << _e.what());
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
81
vm.cpp
81
vm.cpp
@ -300,6 +300,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
VM vm(fev.gas);
|
VM vm(fev.gas);
|
||||||
|
|
||||||
u256 gas;
|
u256 gas;
|
||||||
|
bool vmExceptionOccured = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
output = vm.go(fev, fev.simpleTrace()).toVector();
|
output = vm.go(fev, fev.simpleTrace()).toVector();
|
||||||
@ -308,7 +309,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
catch (VMException const& _e)
|
catch (VMException const& _e)
|
||||||
{
|
{
|
||||||
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
cnote << "VM did throw an exception: " << diagnostic_information(_e);
|
||||||
gas = 0;
|
vmExceptionOccured = true;
|
||||||
}
|
}
|
||||||
catch (Exception const& _e)
|
catch (Exception const& _e)
|
||||||
{
|
{
|
||||||
@ -342,48 +343,58 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
{
|
{
|
||||||
o["env"] = mValue(fev.exportEnv());
|
o["env"] = mValue(fev.exportEnv());
|
||||||
o["exec"] = mValue(fev.exportExec());
|
o["exec"] = mValue(fev.exportExec());
|
||||||
o["post"] = mValue(fev.exportState());
|
if (!vmExceptionOccured)
|
||||||
o["callcreates"] = fev.exportCallCreates();
|
{
|
||||||
o["out"] = "0x" + toHex(output);
|
o["post"] = mValue(fev.exportState());
|
||||||
fev.push(o, "gas", gas);
|
o["callcreates"] = fev.exportCallCreates();
|
||||||
|
o["out"] = "0x" + toHex(output);
|
||||||
|
fev.push(o, "gas", gas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BOOST_REQUIRE(o.count("post") > 0);
|
if (o.count("post") > 0) // No exceptions expected
|
||||||
BOOST_REQUIRE(o.count("callcreates") > 0);
|
|
||||||
BOOST_REQUIRE(o.count("out") > 0);
|
|
||||||
BOOST_REQUIRE(o.count("gas") > 0);
|
|
||||||
|
|
||||||
dev::test::FakeExtVM test;
|
|
||||||
test.importState(o["post"].get_obj());
|
|
||||||
test.importCallCreates(o["callcreates"].get_array());
|
|
||||||
|
|
||||||
checkOutput(output, o);
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(toInt(o["gas"]), gas);
|
|
||||||
|
|
||||||
auto& expectedAddrs = test.addresses;
|
|
||||||
auto& resultAddrs = fev.addresses;
|
|
||||||
for (auto&& expectedPair : expectedAddrs)
|
|
||||||
{
|
{
|
||||||
auto& expectedAddr = expectedPair.first;
|
BOOST_CHECK(!vmExceptionOccured);
|
||||||
auto resultAddrIt = resultAddrs.find(expectedAddr);
|
|
||||||
if (resultAddrIt == resultAddrs.end())
|
BOOST_REQUIRE(o.count("post") > 0);
|
||||||
BOOST_ERROR("Missing expected address " << expectedAddr);
|
BOOST_REQUIRE(o.count("callcreates") > 0);
|
||||||
else
|
BOOST_REQUIRE(o.count("out") > 0);
|
||||||
|
BOOST_REQUIRE(o.count("gas") > 0);
|
||||||
|
|
||||||
|
dev::test::FakeExtVM test;
|
||||||
|
test.importState(o["post"].get_obj());
|
||||||
|
test.importCallCreates(o["callcreates"].get_array());
|
||||||
|
|
||||||
|
checkOutput(output, o);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(toInt(o["gas"]), gas);
|
||||||
|
|
||||||
|
auto& expectedAddrs = test.addresses;
|
||||||
|
auto& resultAddrs = fev.addresses;
|
||||||
|
for (auto&& expectedPair : expectedAddrs)
|
||||||
{
|
{
|
||||||
auto& expectedState = expectedPair.second;
|
auto& expectedAddr = expectedPair.first;
|
||||||
auto& resultState = resultAddrIt->second;
|
auto resultAddrIt = resultAddrs.find(expectedAddr);
|
||||||
BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState));
|
if (resultAddrIt == resultAddrs.end())
|
||||||
BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState));
|
BOOST_ERROR("Missing expected address " << expectedAddr);
|
||||||
BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code");
|
else
|
||||||
|
{
|
||||||
|
auto& expectedState = expectedPair.second;
|
||||||
|
auto& resultState = resultAddrIt->second;
|
||||||
|
BOOST_CHECK_MESSAGE(std::get<0>(expectedState) == std::get<0>(resultState), expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState));
|
||||||
|
BOOST_CHECK_MESSAGE(std::get<1>(expectedState) == std::get<1>(resultState), expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState));
|
||||||
|
BOOST_CHECK_MESSAGE(std::get<3>(expectedState) == std::get<3>(resultState), expectedAddr << ": incorrect code");
|
||||||
|
|
||||||
checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
|
checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses);
|
checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses);
|
||||||
BOOST_CHECK(test.callcreates == fev.callcreates);
|
BOOST_CHECK(test.callcreates == fev.callcreates);
|
||||||
|
}
|
||||||
|
else // Exception expected
|
||||||
|
BOOST_CHECK(vmExceptionOccured);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user