diff options
author | winsvega <winsvega@mail.ru> | 2015-03-26 08:12:25 +0800 |
---|---|---|
committer | winsvega <winsvega@mail.ru> | 2015-04-08 02:32:32 +0800 |
commit | b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55 (patch) | |
tree | 5a11ca01374392fb31d8efdf444f65ecaad683ba | |
parent | 7ed2db70a7ebaaa661f4fabf73f19d17dd5f8f51 (diff) | |
download | dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.gz dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.bz2 dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.lz dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.xz dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.tar.zst dexon-solidity-b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55.zip |
Check State
Refactoring
-rw-r--r-- | TestHelper.cpp | 63 | ||||
-rw-r--r-- | TestHelper.h | 3 | ||||
-rw-r--r-- | state.cpp | 16 | ||||
-rw-r--r-- | vm.cpp | 27 |
4 files changed, 30 insertions, 79 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; } } } diff --git a/TestHelper.h b/TestHelper.h index 4e205378..b4002aeb 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -108,7 +108,7 @@ public: static void importState(json_spirit::mObject& _o, eth::State& _state); void importTransaction(json_spirit::mObject& _o); void exportTest(bytes const& _output, eth::State const& _statePost); - static bool compareStates(eth::State const& _stateExpect, eth::State const& _statePost); + static void checkExpectedState(eth::State const& _stateExpect, eth::State const& _statePost, WhenError _throw = WhenError::Throw); eth::State m_statePre; eth::State m_statePost; @@ -166,6 +166,7 @@ public: bool fillTests = false; ///< Create JSON test files from execution results bool stats = false; ///< Execution time stats std::string statsOutFile; ///< Stats output file. "out" for standard output + bool checkState = false;///< Throw error when checking test states /// Test selection /// @{ @@ -91,23 +91,9 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) // check addresses #if ETH_FATDB + ImportTest::checkExpectedState(importer.m_statePost, theState); auto expectedAddrs = importer.m_statePost.addresses(); auto resultAddrs = theState.addresses(); - for (auto& expectedPair : expectedAddrs) - { - auto& expectedAddr = expectedPair.first; - auto resultAddrIt = resultAddrs.find(expectedAddr); - if (resultAddrIt == resultAddrs.end()) - BOOST_ERROR("Missing expected address " << expectedAddr); - else - { - BOOST_CHECK_MESSAGE(importer.m_statePost.balance(expectedAddr) == theState.balance(expectedAddr), expectedAddr << ": incorrect balance " << theState.balance(expectedAddr) << ", expected " << importer.m_statePost.balance(expectedAddr)); - BOOST_CHECK_MESSAGE(importer.m_statePost.transactionsFrom(expectedAddr) == theState.transactionsFrom(expectedAddr), expectedAddr << ": incorrect txCount " << theState.transactionsFrom(expectedAddr) << ", expected " << importer.m_statePost.transactionsFrom(expectedAddr)); - BOOST_CHECK_MESSAGE(importer.m_statePost.code(expectedAddr) == theState.code(expectedAddr), expectedAddr << ": incorrect code"); - - checkStorage(importer.m_statePost.storage(expectedAddr), theState.storage(expectedAddr), expectedAddr); - } - } checkAddresses<map<Address, u256> >(expectedAddrs, resultAddrs); #endif BOOST_CHECK_MESSAGE(theState.rootHash() == h256(o["postStateRoot"].get_str()), "wrong post state root"); @@ -380,7 +380,6 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) } } - if (_fillin) { o["env"] = mValue(fev.exportEnv()); @@ -394,7 +393,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) State postState, expectState; ImportTest::importState(o["post"].get_obj(), postState); ImportTest::importState(o["expect"].get_obj(), expectState); - ImportTest::compareStates(expectState, postState); + ImportTest::checkExpectedState(expectState, postState, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); o.erase(o.find("expect")); } @@ -425,25 +424,11 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); - auto& expectedAddrs = test.addresses; - auto& resultAddrs = fev.addresses; - for (auto&& expectedPair : expectedAddrs) - { - auto& expectedAddr = expectedPair.first; - auto resultAddrIt = resultAddrs.find(expectedAddr); - if (resultAddrIt == resultAddrs.end()) - BOOST_ERROR("Missing expected address " << expectedAddr); - 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); - } - } + State postState, expectState; + mObject mPostState = fev.exportState(); + ImportTest::importState(mPostState, postState); + ImportTest::importState(o["post"].get_obj(), expectState); + ImportTest::checkExpectedState(expectState, postState); checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses); |