From a14cada9dd81a263a6af2c299507f1aa9c913807 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 24 Mar 2015 21:36:04 +0300 Subject: State Test Expected state check when filling test --- TestHelper.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'TestHelper.cpp') 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 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()); -- cgit v1.2.3 From bfc4d2eceb44b07f1bbdb3b3418af39a89efc420 Mon Sep 17 00:00:00 2001 From: winsvega Date: Wed, 25 Mar 2015 15:47:28 +0300 Subject: Expect State Check state and vmtests --- TestHelper.cpp | 98 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index a9913c28..31672563 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -76,9 +77,7 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o) { importEnv(_o["env"].get_obj()); - importState(_o["pre"].get_obj(), m_statePre); - if (_o.count("expect") > 0) - importState(_o["expect"].get_obj(), m_stateExpect); + importState(_o["pre"].get_obj(), m_statePre); importTransaction(_o["transaction"].get_obj()); if (!isFiller) @@ -178,62 +177,59 @@ void ImportTest::importTransaction(json_spirit::mObject& _o) } } -void ImportTest::checkFillTest(State const& _statePost) +bool ImportTest::compareStates(State const& _stateExpect, 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()) + 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")); + + 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 + for (auto const& it: testNetAddressList) { - bool bFound = false; //do not count default addresses as it's not in addressInUse - for (auto const& it: testNetAddressList) + if (it == a.first) { - if (it == a.first) - { - bFound = true; - break; - } + 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)); + if (bFound) + continue; - map 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(_statePost.addressInUse(a.first), "Filling Test Error: " << a.first << " expected address not in use!"); + 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)); - 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)) << "'"); + map 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)); } - } - m_TestObject.erase(m_TestObject.find("expect")); + 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)) << "'"); + } } + + return true; } 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()); // 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 m_TestObject["post"] = fillJsonWithState(_statePost); -- cgit v1.2.3 From b0c8babf0e76ffa1fc5cb21642f3ac2fc3d1cb55 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 26 Mar 2015 03:12:25 +0300 Subject: Check State Refactoring --- TestHelper.cpp | 63 ++++++++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 42 deletions(-) (limited to 'TestHelper.cpp') 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 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; } } } -- cgit v1.2.3 From adba4fb9a136ec27d6fc3e295c43a6f0f04ae865 Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 27 Mar 2015 01:05:45 +0300 Subject: Check State Incomplete State Support --- TestHelper.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 29 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index ca7caf3d..a830636d 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -107,41 +106,72 @@ void ImportTest::importEnv(json_spirit::mObject& _o) m_statePre.m_currentBlock = m_environment.currentBlock; } -void ImportTest::importState(json_spirit::mObject& _o, State& _state) +// import state from not fully declared json_spirit::mObject, writing to _stateOptionsMap which fields were defined in json + +void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptionsMap& _stateOptionsMap) { for (auto& i: _o) { json_spirit::mObject o = i.second.get_obj(); - assert(o.count("balance") > 0); - assert(o.count("nonce") > 0); - assert(o.count("storage") > 0); - assert(o.count("code") > 0); + ImportStateOptions stateOptions; + u256 iBalance = 0, iNonce = 0; - if (bigint(o["balance"].get_str()) >= c_max256plus1) - BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") ); - if (bigint(o["nonce"].get_str()) >= c_max256plus1) - BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") ); + if (o.count("balance") > 0) + { + stateOptions.m_bHasBalance = true; + if (bigint(o["balance"].get_str()) >= c_max256plus1) + BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") ); + iBalance = toInt(o["balance"]); + } + + if (o.count("nonce") > 0) + { + stateOptions.m_bHasNonce = true; + if (bigint(o["nonce"].get_str()) >= c_max256plus1) + BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") ); + iNonce = toInt(o["nonce"]); + } Address address = Address(i.first); - bytes code = importCode(o); + bytes code; + if (o.count("code") > 0) + { + code = importCode(o); + stateOptions.m_bHasCode = true; + } if (code.size()) { - _state.m_cache[address] = Account(toInt(o["balance"]), Account::ContractConception); + _state.m_cache[address] = Account(iBalance, Account::ContractConception); _state.m_cache[address].setCode(code); } else - _state.m_cache[address] = Account(toInt(o["balance"]), Account::NormalCreation); + _state.m_cache[address] = Account(iBalance, Account::NormalCreation); - for (auto const& j: o["storage"].get_obj()) - _state.setStorage(address, toInt(j.first), toInt(j.second)); + if (o.count("storage") > 0) + { + stateOptions.m_bHasStorage = true; + for (auto const& j: o["storage"].get_obj()) + _state.setStorage(address, toInt(j.first), toInt(j.second)); + } - for(int i=0; i stateStorage = _statePost.storage(a.first); - for (auto const& s: _stateExpect.storage(a.first)) + if (addressOptions.m_bHasNonce) { - CHECK(stateStorage[s.first] == s.second, - "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second)); + CHECK(_stateExpect.transactionsFrom(a.first) == _statePost.transactionsFrom(a.first), + "Check State: " << a.first << ": incorrect nonce " << _statePost.transactionsFrom(a.first) << ", expected " << _stateExpect.transactionsFrom(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)) << "'"); + if (addressOptions.m_bHasStorage) + { + map stateStorage = _statePost.storage(a.first); + for (auto const& s: _stateExpect.storage(a.first)) + { + CHECK(stateStorage[s.first] == s.second, + "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second)); + } + } + + if (addressOptions.m_bHasCode) + { + 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)) << "'"); + } } } } @@ -219,9 +282,10 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) // compare expected state with post state if (m_TestObject.count("expect") > 0) { - State expectState(Address(), OverlayDB(), eth::BaseState::Empty); - importState(m_TestObject["expect"].get_obj(), expectState); - checkExpectedState(expectState, _statePost, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); + stateOptionsMap stateMap; + State expectState(Address(), OverlayDB(), eth::BaseState::Empty); + importState(m_TestObject["expect"].get_obj(), expectState, stateMap); + checkExpectedState(expectState, _statePost, stateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); m_TestObject.erase(m_TestObject.find("expect")); } -- cgit v1.2.3 From 2e71a91323124df1ecc7ca2e201f0b64ac9ef892 Mon Sep 17 00:00:00 2001 From: winsvega Date: Sat, 28 Mar 2015 00:48:51 +0300 Subject: Check State State tests with expect section --- TestHelper.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index a830636d..0061b2ee 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -170,9 +170,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) stateOptionsMap importedMap; importState(_o, _state, importedMap); for (auto& stateOptionMap: importedMap) - { assert(stateOptionMap.second.isAllSet()); //check that every parameter was declared in state object - } } void ImportTest::importTransaction(json_spirit::mObject& _o) @@ -256,10 +254,14 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta { map stateStorage = _statePost.storage(a.first); for (auto const& s: _stateExpect.storage(a.first)) - { CHECK(stateStorage[s.first] == s.second, "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(stateStorage[s.first]) << ", expected [" << s.first << "] = " << toHex(s.second)); - } + + //Check for unexpected storage values + stateStorage = _stateExpect.storage(a.first); + for (auto const& s: _statePost.storage(a.first)) + CHECK(stateStorage[s.first] == s.second, + "Check State: " << a.first << ": incorrect storage [" << s.first << "] = " << toHex(s.second) << ", expected [" << s.first << "] = " << toHex(stateStorage[s.first])); } if (addressOptions.m_bHasCode) -- cgit v1.2.3 From 923e452846241f9f97b7fb0dc3351c0c479089b6 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 2 Apr 2015 18:33:28 +0300 Subject: Check State Style Changes --- TestHelper.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 0061b2ee..2c6ee8d4 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -205,13 +205,7 @@ void ImportTest::importTransaction(json_spirit::mObject& _o) } } -void ImportTest::checkExpectedState(State const& _stateExpect, State const& _statePost, WhenError _throw) -{ - stateOptionsMap defaultMap; - checkExpectedState(_stateExpect, _statePost, defaultMap, _throw); -} - -void ImportTest::checkExpectedState(State const& _stateExpect, State const& _statePost, stateOptionsMap const& _expectedStateOptions, WhenError _throw) +void ImportTest::checkExpectedState(State const& _stateExpect, State const& _statePost, stateOptionsMap const _expectedStateOptions, WhenError _throw) { #define CHECK(a,b) \ if (_throw == WhenError::Throw) \ -- cgit v1.2.3 From c38c8bb5676d39f52a1aef4f41b01c252a94e5ca Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 3 Apr 2015 23:40:51 +0300 Subject: Check State style changes --- TestHelper.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 2c6ee8d4..80722465 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -157,7 +157,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio _state.setStorage(address, toInt(j.first), toInt(j.second)); } - for (int i=0; i Date: Mon, 6 Apr 2015 17:40:01 +0300 Subject: Check State Style + Rebase --- TestHelper.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 80722465..94751c1e 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -115,14 +115,14 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio json_spirit::mObject o = i.second.get_obj(); ImportStateOptions stateOptions; - u256 iBalance = 0, iNonce = 0; + u256 balance = 0, nonce = 0; if (o.count("balance") > 0) { stateOptions.m_bHasBalance = true; if (bigint(o["balance"].get_str()) >= c_max256plus1) BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") ); - iBalance = toInt(o["balance"]); + balance = toInt(o["balance"]); } if (o.count("nonce") > 0) @@ -130,7 +130,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio stateOptions.m_bHasNonce = true; if (bigint(o["nonce"].get_str()) >= c_max256plus1) BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") ); - iNonce = toInt(o["nonce"]); + nonce = toInt(o["nonce"]); } Address address = Address(i.first); @@ -144,11 +144,11 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio if (code.size()) { - _state.m_cache[address] = Account(iBalance, Account::ContractConception); + _state.m_cache[address] = Account(balance, Account::ContractConception); _state.m_cache[address].setCode(code); } else - _state.m_cache[address] = Account(iBalance, Account::NormalCreation); + _state.m_cache[address] = Account(balance, Account::NormalCreation); if (o.count("storage") > 0) { @@ -157,7 +157,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio _state.setStorage(address, toInt(j.first), toInt(j.second)); } - for (int i=0; i < iNonce; ++i) + for (int i = 0; i < nonce; ++i) _state.noteSending(address); _state.ensureCached(address, false, false); @@ -275,7 +275,7 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) if (m_TestObject.count("expect") > 0) { stateOptionsMap stateMap; - State expectState(Address(), OverlayDB(), eth::BaseState::Empty); + State expectState(OverlayDB(), eth::BaseState::Empty); importState(m_TestObject["expect"].get_obj(), expectState, stateMap); checkExpectedState(expectState, _statePost, stateMap, Options::get().checkState ? WhenError::Throw : WhenError::DontThrow); m_TestObject.erase(m_TestObject.find("expect")); -- cgit v1.2.3 From 4774ccfb287edc1dc61462c27a1ec5ea8af69673 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 6 Apr 2015 18:32:24 +0300 Subject: Check State Unused Variable --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 94751c1e..1ff091c1 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -170,7 +170,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) stateOptionsMap importedMap; importState(_o, _state, importedMap); for (auto& stateOptionMap: importedMap) - assert(stateOptionMap.second.isAllSet()); //check that every parameter was declared in state object + BOOST_CHECK_MESSAGE(stateOptionMap.second.isAllSet(), "Import State[" << stateOptionMap.first << "]: State is not complete!"); //check that every parameter was declared in state object } void ImportTest::importTransaction(json_spirit::mObject& _o) -- cgit v1.2.3 From dd0cdddd946c036f64d92f000618930c14bf95d5 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 6 Apr 2015 22:38:52 +0300 Subject: Check State style changes --- TestHelper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 1ff091c1..3d96af42 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -115,7 +115,8 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio json_spirit::mObject o = i.second.get_obj(); ImportStateOptions stateOptions; - u256 balance = 0, nonce = 0; + u256 balance = 0; + u256 nonce = 0; if (o.count("balance") > 0) { -- cgit v1.2.3 From ff5ce7bda3346e3893d933196371564b4e45baec Mon Sep 17 00:00:00 2001 From: Wins Vega Date: Wed, 8 Apr 2015 01:31:30 +0400 Subject: Check State: windows build --- TestHelper.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 3d96af42..4214796c 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -68,6 +68,8 @@ namespace test { struct ValueTooLarge: virtual Exception {}; +struct MissingFields : virtual Exception {}; + bigint const c_max256plus1 = bigint(1) << 256; ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): @@ -170,8 +172,12 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) { stateOptionsMap importedMap; importState(_o, _state, importedMap); - for (auto& stateOptionMap: importedMap) - BOOST_CHECK_MESSAGE(stateOptionMap.second.isAllSet(), "Import State[" << stateOptionMap.first << "]: State is not complete!"); //check that every parameter was declared in state object + for (auto& stateOptionMap : importedMap) + { + //check that every parameter was declared in state object + if (!stateOptionMap.second.isAllSet()) + BOOST_THROW_EXCEPTION(MissingFields() << errinfo_comment("Import State: Missing state fields!")); + } } void ImportTest::importTransaction(json_spirit::mObject& _o) -- cgit v1.2.3 From fff3784c010925a543f6bc7df803f7a107f3964b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 8 Apr 2015 02:42:51 +0200 Subject: Remove VMTRACE. Better transaction logging. Avoid bothering with obviously invalid transactions. --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index dd7c09ea..757a6e7a 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -172,7 +172,7 @@ void ImportTest::importTransaction(json_spirit::mObject& _o) { RLPStream transactionRLPStream = createRLPStreamFromTransactionFields(_o); RLP transactionRLP(transactionRLPStream.out()); - m_transaction = Transaction(transactionRLP.data(), CheckSignature::Sender); + m_transaction = Transaction(transactionRLP.data(), CheckTransaction::Everything); } } -- cgit v1.2.3 From e54952c8cf718fb1b7af853bead145292c7f25db Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 9 Apr 2015 18:13:31 +0300 Subject: BlockTests: add expect section --- TestHelper.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index e86b84aa..45fe55b0 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -671,7 +671,6 @@ Options::Options() memory = true; inputLimits = true; bigData = true; - checkState = true; } } } -- cgit v1.2.3 From efdd3790a0405654933f456751230254cef95151 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 13 Apr 2015 18:12:05 +0200 Subject: Various fixes for mining. --- TestHelper.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 45fe55b0..93c564e6 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -62,6 +62,37 @@ void connectClients(Client& c1, Client& c2) c2.connect("127.0.0.1", c1Port); #endif } + +void mine(State& s, BlockChain const& _bc) +{ + s.commitToMine(_bc); + GenericFarm f; + bool completed = false; + f.onSolutionFound([&](ProofOfWork::Solution sol) + { + return completed = s.completeMine(sol); + }); + f.setWork(s.info()); + f.startCPU(); + while (!completed) + this_thread::sleep_for(chrono::milliseconds(20)); +} + +void mine(BlockInfo& _bi) +{ + GenericFarm f; + bool completed = false; + f.onSolutionFound([&](ProofOfWork::Solution sol) + { + ProofOfWork::assignResult(sol, _bi); + return completed = true; + }); + f.setWork(_bi); + f.startCPU(); + while (!completed) + this_thread::sleep_for(chrono::milliseconds(20)); +} + } namespace test -- cgit v1.2.3