aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwinsvega <winsvega@mail.ru>2015-03-25 02:36:04 +0800
committerwinsvega <winsvega@mail.ru>2015-04-08 02:32:31 +0800
commita14cada9dd81a263a6af2c299507f1aa9c913807 (patch)
tree6ab9205ecfd93079d2b6a06b7e9709be1529491c
parent68b61432aea5f99f179b74f5a7a63138a5d2b09a (diff)
downloaddexon-solidity-a14cada9dd81a263a6af2c299507f1aa9c913807.tar.gz
dexon-solidity-a14cada9dd81a263a6af2c299507f1aa9c913807.tar.zst
dexon-solidity-a14cada9dd81a263a6af2c299507f1aa9c913807.zip
State Test
Expected state check when filling test
-rw-r--r--TestHelper.cpp66
-rw-r--r--TestHelper.h2
2 files changed, 66 insertions, 2 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index dd7c09ea..a9913c28 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -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());
diff --git a/TestHelper.h b/TestHelper.h
index 7f6d7336..d830ceb6 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -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;
};