aboutsummaryrefslogtreecommitdiffstats
path: root/TestHelper.cpp
diff options
context:
space:
mode:
authorwinsvega <winsvega@mail.ru>2015-03-26 08:12:25 +0800
committerwinsvega <winsvega@mail.ru>2015-04-08 02:32:32 +0800
commitb0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55 (patch)
tree5a11ca01374392fb31d8efdf444f65ecaad683ba /TestHelper.cpp
parent7ed2db70a7ebaaa661f4fabf73f19d17dd5f8f51 (diff)
downloaddexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.gz
dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.zst
dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.zip
Check State
Refactoring
Diffstat (limited to 'TestHelper.cpp')
-rw-r--r--TestHelper.cpp63
1 files changed, 21 insertions, 42 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index 31672563..ca7caf3d 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -177,59 +177,35 @@ void ImportTest::importTransaction(json_spirit::mObject& _o)
}
}
-bool ImportTest::compareStates(State const& _stateExpect, State const& _statePost)
-{
- //TestNet Addresses
- static Addresses testNetAddressList = boost::assign::list_of
- (Address("0000000000000000000000000000000000000001"))
- (Address("0000000000000000000000000000000000000002"))
- (Address("0000000000000000000000000000000000000003"))
- (Address("0000000000000000000000000000000000000004"))
- (Address("1a26338f0d905e295fccb71fa9ea849ffa12aaf4"))
- (Address("2ef47100e0787b915105fd5e3f4ff6752079d5cb"))
- (Address("6c386a4b26f73c802f34673f7248bb118f97424a"))
- (Address("b9c015918bdaba24b4ff057a92a3873d6eb201be"))
- (Address("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"))
- (Address("dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6"))
- (Address("e4157b34ea9615cfbde6b4fda419828124b70c78"))
- (Address("e6716f9544a56c530d868e4bfbacb172315bdead"));
+void ImportTest::checkExpectedState(State const& _stateExpect, State const& _statePost, WhenError _throw)
+{
+ #define CHECK(a,b) \
+ if (_throw == WhenError::Throw) \
+ BOOST_CHECK_MESSAGE(a,b); \
+ else \
+ BOOST_WARN_MESSAGE(a,b);
for (auto const& a: _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!");
+ CHECK(_statePost.addressInUse(a.first), "Filling Test: " << a.first << " missing expected address!");
if (_statePost.addressInUse(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 " << _stateExpect.balance(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 " << _stateExpect.transactionsFrom(a.first));
+ CHECK(_stateExpect.balance(a.first) == _statePost.balance(a.first),
+ "Check State: " << a.first << ": incorrect balance " << _statePost.balance(a.first) << ", expected " << _stateExpect.balance(a.first));
+ CHECK(_stateExpect.transactionsFrom(a.first) == _statePost.transactionsFrom(a.first),
+ "Check State: " << a.first << ": incorrect nonce " << _statePost.transactionsFrom(a.first) << ", expected " << _stateExpect.transactionsFrom(a.first));
map<u256, u256> stateStorage = _statePost.storage(a.first);
for (auto const& s: _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));
+ CHECK(stateStorage[s.first] == s.second,
+ "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second));
}
- 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(_stateExpect.code(a.first)) << "'");
+ CHECK(_stateExpect.code(a.first) == _statePost.code(a.first),
+ "Check State: " << a.first << ": incorrect code '" << toHex(_statePost.code(a.first)) << "', expected '" << toHex(_stateExpect.code(a.first)) << "'");
}
}
-
- return true;
}
void ImportTest::exportTest(bytes const& _output, State const& _statePost)
@@ -243,9 +219,9 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
// compare expected state with post state
if (m_TestObject.count("expect") > 0)
{
- State expectState;
+ State expectState(Address(), OverlayDB(), eth::BaseState::Empty);
importState(m_TestObject["expect"].get_obj(), expectState);
- compareStates(expectState, _statePost);
+ checkExpectedState(expectState, _statePost, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow);
m_TestObject.erase(m_TestObject.find("expect"));
}
@@ -623,6 +599,8 @@ Options::Options()
inputLimits = true;
else if (arg == "--bigdata")
bigData = true;
+ else if (arg == "--checkstate")
+ checkState = true;
else if (arg == "--all")
{
performance = true;
@@ -630,6 +608,7 @@ Options::Options()
memory = true;
inputLimits = true;
bigData = true;
+ checkState = true;
}
}
}