mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
State Test
Expected state check when filling test
This commit is contained in:
parent
68b61432ae
commit
a14cada9dd
@ -76,7 +76,9 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller):
|
||||
m_TestObject(_o)
|
||||
{
|
||||
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());
|
||||
|
||||
if (!isFiller)
|
||||
@ -176,6 +178,64 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
|
||||
}
|
||||
}
|
||||
|
||||
void ImportTest::checkFillTest(State const& _statePost)
|
||||
{
|
||||
//TestNet Addresses
|
||||
static Addresses testNetAddressList;
|
||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000001"));
|
||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000002"));
|
||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000003"));
|
||||
testNetAddressList.push_back(Address("0000000000000000000000000000000000000004"));
|
||||
testNetAddressList.push_back(Address("1a26338f0d905e295fccb71fa9ea849ffa12aaf4"));
|
||||
testNetAddressList.push_back(Address("2ef47100e0787b915105fd5e3f4ff6752079d5cb"));
|
||||
testNetAddressList.push_back(Address("6c386a4b26f73c802f34673f7248bb118f97424a"));
|
||||
testNetAddressList.push_back(Address("b9c015918bdaba24b4ff057a92a3873d6eb201be"));
|
||||
testNetAddressList.push_back(Address("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"));
|
||||
testNetAddressList.push_back(Address("dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6"));
|
||||
testNetAddressList.push_back(Address("e4157b34ea9615cfbde6b4fda419828124b70c78"));
|
||||
testNetAddressList.push_back(Address("e6716f9544a56c530d868e4bfbacb172315bdead"));
|
||||
|
||||
if (m_TestObject.find("expect") != m_TestObject.end())
|
||||
{
|
||||
for (auto const& a: m_stateExpect.addresses())
|
||||
{
|
||||
bool bFound = false; //do not count default addresses as it's not in addressInUse
|
||||
for (auto const& it: testNetAddressList)
|
||||
{
|
||||
if (it == a.first)
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFound)
|
||||
continue;
|
||||
|
||||
BOOST_CHECK_MESSAGE(_statePost.addressInUse(a.first), "Filling Test Error: " << a.first << " expected address not in use!");
|
||||
if (_statePost.addressInUse(a.first))
|
||||
{
|
||||
BOOST_CHECK_MESSAGE(m_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));
|
||||
BOOST_CHECK_MESSAGE(m_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));
|
||||
|
||||
map<u256, u256> stateStorage = _statePost.storage(a.first);
|
||||
for (auto const& s: m_stateExpect.storage(a.first))
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
BOOST_CHECK_MESSAGE(m_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)) << "'");
|
||||
}
|
||||
}
|
||||
|
||||
m_TestObject.erase(m_TestObject.find("expect"));
|
||||
}
|
||||
}
|
||||
|
||||
void ImportTest::exportTest(bytes const& _output, State const& _statePost)
|
||||
{
|
||||
// export output
|
||||
@ -184,8 +244,10 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
|
||||
// export logs
|
||||
m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
|
||||
|
||||
// export post state
|
||||
// compare expected state with post state
|
||||
checkFillTest(_statePost);
|
||||
|
||||
// export post state
|
||||
m_TestObject["post"] = fillJsonWithState(_statePost);
|
||||
m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes());
|
||||
|
||||
|
@ -110,11 +110,13 @@ public:
|
||||
void exportTest(bytes const& _output, eth::State const& _statePost);
|
||||
|
||||
eth::State m_statePre;
|
||||
eth::State m_stateExpect;
|
||||
eth::State m_statePost;
|
||||
eth::ExtVMFace m_environment;
|
||||
eth::Transaction m_transaction;
|
||||
|
||||
private:
|
||||
void checkFillTest(eth::State const& _statePost);
|
||||
json_spirit::mObject& m_TestObject;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user