mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Expect State Check
state and vmtests
This commit is contained in:
parent
a14cada9dd
commit
bfc4d2eceb
@ -25,6 +25,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
#include <boost/assign.hpp>
|
||||||
|
|
||||||
#include <libethereum/Client.h>
|
#include <libethereum/Client.h>
|
||||||
#include <liblll/Compiler.h>
|
#include <liblll/Compiler.h>
|
||||||
@ -77,8 +78,6 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller):
|
|||||||
{
|
{
|
||||||
importEnv(_o["env"].get_obj());
|
importEnv(_o["env"].get_obj());
|
||||||
importState(_o["pre"].get_obj(), m_statePre);
|
importState(_o["pre"].get_obj(), m_statePre);
|
||||||
if (_o.count("expect") > 0)
|
|
||||||
importState(_o["expect"].get_obj(), m_stateExpect);
|
|
||||||
importTransaction(_o["transaction"].get_obj());
|
importTransaction(_o["transaction"].get_obj());
|
||||||
|
|
||||||
if (!isFiller)
|
if (!isFiller)
|
||||||
@ -178,26 +177,24 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportTest::checkFillTest(State const& _statePost)
|
bool ImportTest::compareStates(State const& _stateExpect, State const& _statePost)
|
||||||
{
|
{
|
||||||
//TestNet Addresses
|
//TestNet Addresses
|
||||||
static Addresses testNetAddressList;
|
static Addresses testNetAddressList = boost::assign::list_of
|
||||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000001"));
|
(Address("0000000000000000000000000000000000000001"))
|
||||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000002"));
|
(Address("0000000000000000000000000000000000000002"))
|
||||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000003"));
|
(Address("0000000000000000000000000000000000000003"))
|
||||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000004"));
|
(Address("0000000000000000000000000000000000000004"))
|
||||||
testNetAddressList.push_back(Address("1a26338f0d905e295fccb71fa9ea849ffa12aaf4"));
|
(Address("1a26338f0d905e295fccb71fa9ea849ffa12aaf4"))
|
||||||
testNetAddressList.push_back(Address("2ef47100e0787b915105fd5e3f4ff6752079d5cb"));
|
(Address("2ef47100e0787b915105fd5e3f4ff6752079d5cb"))
|
||||||
testNetAddressList.push_back(Address("6c386a4b26f73c802f34673f7248bb118f97424a"));
|
(Address("6c386a4b26f73c802f34673f7248bb118f97424a"))
|
||||||
testNetAddressList.push_back(Address("b9c015918bdaba24b4ff057a92a3873d6eb201be"));
|
(Address("b9c015918bdaba24b4ff057a92a3873d6eb201be"))
|
||||||
testNetAddressList.push_back(Address("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"));
|
(Address("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"))
|
||||||
testNetAddressList.push_back(Address("dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6"));
|
(Address("dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6"))
|
||||||
testNetAddressList.push_back(Address("e4157b34ea9615cfbde6b4fda419828124b70c78"));
|
(Address("e4157b34ea9615cfbde6b4fda419828124b70c78"))
|
||||||
testNetAddressList.push_back(Address("e6716f9544a56c530d868e4bfbacb172315bdead"));
|
(Address("e6716f9544a56c530d868e4bfbacb172315bdead"));
|
||||||
|
|
||||||
if (m_TestObject.find("expect") != m_TestObject.end())
|
for (auto const& a: _stateExpect.addresses())
|
||||||
{
|
|
||||||
for (auto const& a: m_stateExpect.addresses())
|
|
||||||
{
|
{
|
||||||
bool bFound = false; //do not count default addresses as it's not in addressInUse
|
bool bFound = false; //do not count default addresses as it's not in addressInUse
|
||||||
for (auto const& it: testNetAddressList)
|
for (auto const& it: testNetAddressList)
|
||||||
@ -215,25 +212,24 @@ void ImportTest::checkFillTest(State const& _statePost)
|
|||||||
BOOST_CHECK_MESSAGE(_statePost.addressInUse(a.first), "Filling Test Error: " << a.first << " expected address not in use!");
|
BOOST_CHECK_MESSAGE(_statePost.addressInUse(a.first), "Filling Test Error: " << a.first << " expected address not in use!");
|
||||||
if (_statePost.addressInUse(a.first))
|
if (_statePost.addressInUse(a.first))
|
||||||
{
|
{
|
||||||
BOOST_CHECK_MESSAGE(m_stateExpect.balance(a.first) == _statePost.balance(a.first),
|
BOOST_CHECK_MESSAGE(_stateExpect.balance(a.first) == _statePost.balance(a.first),
|
||||||
"Filling Test Error: " << a.first << ": incorrect balance " << _statePost.balance(a.first) << ", expected " << m_stateExpect.balance(a.first));
|
"Filling Test Error: " << a.first << ": incorrect balance " << _statePost.balance(a.first) << ", expected " << _stateExpect.balance(a.first));
|
||||||
BOOST_CHECK_MESSAGE(m_stateExpect.transactionsFrom(a.first) == _statePost.transactionsFrom(a.first),
|
BOOST_CHECK_MESSAGE(_stateExpect.transactionsFrom(a.first) == _statePost.transactionsFrom(a.first),
|
||||||
"Filling Test Error: " << a.first << ": incorrect nonce " << _statePost.transactionsFrom(a.first) << ", expected " << m_stateExpect.transactionsFrom(a.first));
|
"Filling Test Error: " << a.first << ": incorrect nonce " << _statePost.transactionsFrom(a.first) << ", expected " << _stateExpect.transactionsFrom(a.first));
|
||||||
|
|
||||||
map<u256, u256> stateStorage = _statePost.storage(a.first);
|
map<u256, u256> stateStorage = _statePost.storage(a.first);
|
||||||
for (auto const& s: m_stateExpect.storage(a.first))
|
for (auto const& s: _stateExpect.storage(a.first))
|
||||||
{
|
{
|
||||||
BOOST_CHECK_MESSAGE(stateStorage[s.first] == s.second,
|
BOOST_CHECK_MESSAGE(stateStorage[s.first] == s.second,
|
||||||
"Filling Test Error: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second));
|
"Filling Test Error: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK_MESSAGE(m_stateExpect.code(a.first) == _statePost.code(a.first),
|
BOOST_CHECK_MESSAGE(_stateExpect.code(a.first) == _statePost.code(a.first),
|
||||||
"Filling Test Error: " << a.first << ": incorrect code '" << toHex(_statePost.code(a.first)) << "', expected '" << toHex(m_stateExpect.code(a.first)) << "'");
|
"Filling Test Error: " << a.first << ": incorrect code '" << toHex(_statePost.code(a.first)) << "', expected '" << toHex(_stateExpect.code(a.first)) << "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_TestObject.erase(m_TestObject.find("expect"));
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportTest::exportTest(bytes const& _output, State const& _statePost)
|
void ImportTest::exportTest(bytes const& _output, State const& _statePost)
|
||||||
@ -245,7 +241,13 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
|
|||||||
m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
|
m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
|
||||||
|
|
||||||
// compare expected state with post state
|
// compare expected state with post state
|
||||||
checkFillTest(_statePost);
|
if (m_TestObject.count("expect") > 0)
|
||||||
|
{
|
||||||
|
State expectState;
|
||||||
|
importState(m_TestObject["expect"].get_obj(), expectState);
|
||||||
|
compareStates(expectState, _statePost);
|
||||||
|
m_TestObject.erase(m_TestObject.find("expect"));
|
||||||
|
}
|
||||||
|
|
||||||
// export post state
|
// export post state
|
||||||
m_TestObject["post"] = fillJsonWithState(_statePost);
|
m_TestObject["post"] = fillJsonWithState(_statePost);
|
||||||
|
@ -105,18 +105,17 @@ public:
|
|||||||
ImportTest(json_spirit::mObject& _o, bool isFiller);
|
ImportTest(json_spirit::mObject& _o, bool isFiller);
|
||||||
// imports
|
// imports
|
||||||
void importEnv(json_spirit::mObject& _o);
|
void importEnv(json_spirit::mObject& _o);
|
||||||
void importState(json_spirit::mObject& _o, eth::State& _state);
|
static void importState(json_spirit::mObject& _o, eth::State& _state);
|
||||||
void importTransaction(json_spirit::mObject& _o);
|
void importTransaction(json_spirit::mObject& _o);
|
||||||
void exportTest(bytes const& _output, eth::State const& _statePost);
|
void exportTest(bytes const& _output, eth::State const& _statePost);
|
||||||
|
static bool compareStates(eth::State const& _stateExpect, eth::State const& _statePost);
|
||||||
|
|
||||||
eth::State m_statePre;
|
eth::State m_statePre;
|
||||||
eth::State m_stateExpect;
|
|
||||||
eth::State m_statePost;
|
eth::State m_statePost;
|
||||||
eth::ExtVMFace m_environment;
|
eth::ExtVMFace m_environment;
|
||||||
eth::Transaction m_transaction;
|
eth::Transaction m_transaction;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkFillTest(eth::State const& _statePost);
|
|
||||||
json_spirit::mObject& m_TestObject;
|
json_spirit::mObject& m_TestObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
10
vm.cpp
10
vm.cpp
@ -388,6 +388,16 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
if (!vmExceptionOccured)
|
if (!vmExceptionOccured)
|
||||||
{
|
{
|
||||||
o["post"] = mValue(fev.exportState());
|
o["post"] = mValue(fev.exportState());
|
||||||
|
|
||||||
|
if (o.count("expect") > 0)
|
||||||
|
{
|
||||||
|
State postState, expectState;
|
||||||
|
ImportTest::importState(o["post"].get_obj(), postState);
|
||||||
|
ImportTest::importState(o["expect"].get_obj(), expectState);
|
||||||
|
ImportTest::compareStates(expectState, postState);
|
||||||
|
o.erase(o.find("expect"));
|
||||||
|
}
|
||||||
|
|
||||||
o["callcreates"] = fev.exportCallCreates();
|
o["callcreates"] = fev.exportCallCreates();
|
||||||
o["out"] = "0x" + toHex(output);
|
o["out"] = "0x" + toHex(output);
|
||||||
fev.push(o, "gas", gas);
|
fev.push(o, "gas", gas);
|
||||||
|
Loading…
Reference in New Issue
Block a user