From 3565d42a14feae1af85fa2aabc455d8f1f6da15b Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 29 Oct 2014 17:25:02 +0100 Subject: Restructure state tests. Remove FakeStateClass --- vm.cpp | 378 ++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 177 insertions(+), 201 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index e6c82349..97d64506 100644 --- a/vm.cpp +++ b/vm.cpp @@ -36,33 +36,35 @@ FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&) { + Address na = right160(sha3(rlpList(myAddress, get<1>(addresses[myAddress])))); + Transaction t; t.value = _endowment; t.gasPrice = gasPrice; t.gas = *_gas; t.data = _init.toBytes(); - m_s.noteSending(myAddress); - m_ms.internal.resize(m_ms.internal.size() + 1); - auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); - if (!m_ms.internal.back().from) - m_ms.internal.pop_back(); +// m_s.noteSending(myAddress); +// m_ms.internal.resize(m_ms.internal.size() + 1); +// auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); +// if (!m_ms.internal.back().from) +// m_ms.internal.pop_back(); - if (get<0>(addresses[myAddress]) >= _endowment) - { - get<1>(addresses[myAddress])++; - get<0>(addresses[ret]) = _endowment; - get<3>(addresses[ret]) = m_s.code(ret); - } +// if (get<0>(addresses[myAddress]) >= _endowment) +// { +// get<1>(addresses[myAddress])++; +// get<0>(addresses[ret]) = _endowment; +// //get<3>(addresses[ret]) = m_s.code(ret); +// } t.type = eth::Transaction::ContractCreation; callcreates.push_back(t); - return ret; + return na; } bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride) { - u256 contractgas = 0xffff; +// u256 contractgas = 0xffff; Transaction t; t.value = _value; @@ -72,101 +74,103 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, t.type = eth::Transaction::MessageCall; t.receiveAddress = _receiveAddress; callcreates.push_back(t); - - string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) ); - string sizeOfCode = toHex(toCompactBigEndian((codeOf_CodeAddress.size()+1)/2)); - - string codeOf_SenderAddress = toHex(get<3>(addresses[myAddress]) ); - string sizeOfSenderCode = toHex(toCompactBigEndian((codeOf_SenderAddress.size()+1)/2)); - - if (codeOf_SenderAddress.size()) - { - // create init code that returns given contract code - string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfSenderCode + " ) 0x" + sizeOfSenderCode + ") (RETURN 0 0x" + sizeOfSenderCode +")}"; - bytes initBytes = compileLLL(initStringHex, true, NULL); - initBytes += fromHex(codeOf_SenderAddress); - bytesConstRef init(&initBytes); - - if (!m_s.addresses().count(myAddress)) - { - m_ms.internal.resize(m_ms.internal.size() + 1); - auto na = m_s.createNewAddress(myAddress, myAddress, balance(myAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); - if (!m_ms.internal.back().from) - m_ms.internal.pop_back(); - if (na != myAddress) - { - cnote << "not able to call to : " << myAddress << "\n"; - cnote << "in FakeExtVM you can only make a call to " << na << "\n"; - BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(myAddress))); - return false; - } - } - } - - if (codeOf_CodeAddress.size()) - { - // create init code that returns given contract code - string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfCode + " ) 0x" + sizeOfCode + ") (RETURN 0 0x" + sizeOfCode +")}"; - bytes initBytes = compileLLL(initStringHex, true, NULL); - initBytes += fromHex(codeOf_CodeAddress); - bytesConstRef init(&initBytes); - - if (!m_s.addresses().count(_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) - { - m_s.noteSending(myAddress); - m_ms.internal.resize(m_ms.internal.size() + 1); - auto na = m_s.createNewAddress(_codeAddressOverride ? _codeAddressOverride : _receiveAddress, myAddress, balance(_codeAddressOverride ? _codeAddressOverride : _receiveAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1); - if (!m_ms.internal.back().from) - m_ms.internal.pop_back(); - - if (na != (_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) - { - cnote << "not able to call to : " << (_codeAddressOverride ? _codeAddressOverride : _receiveAddress) << "\n"; - cnote << "in FakeExtVM you can only make a call to " << na << "\n"; - BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(_codeAddressOverride ? _codeAddressOverride : _receiveAddress))); - return false; - } - } - - m_ms.internal.resize(m_ms.internal.size() + 1); - - auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), Executive::simpleTrace(), 1); - - if (!m_ms.internal.back().from) - m_ms.internal.pop_back(); - - // get correct balances, (also for sucicides in the call function) - for (auto const& f: addresses) - { - if (m_s.addressInUse(f.first)) - get<0>(addresses[f.first]) = m_s.balance(f.first); - } - - if (!ret) - return false; - - // TODO: @CJentzsch refund SSTORE stuff. - // TODO: @CJentzsch test logs. - - // do suicides - for (auto const& f: sub.suicides) - addresses.erase(f); - - // get storage - if ((get<0>(addresses[myAddress]) >= _value) && (sub.suicides.find(_receiveAddress) == sub.suicides.end())) - { - for (auto const& j: m_s.storage(_receiveAddress)) - { - u256 adr(j.first); - if ((j.second != 0) ) - get<2>(addresses[_receiveAddress])[adr] = j.second; - } - } - } - else - addresses.erase(_receiveAddress); // for the sake of comparison - + (void)_out; return true; + +// string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) ); +// string sizeOfCode = toHex(toCompactBigEndian((codeOf_CodeAddress.size()+1)/2)); + +// string codeOf_SenderAddress = toHex(get<3>(addresses[myAddress]) ); +// string sizeOfSenderCode = toHex(toCompactBigEndian((codeOf_SenderAddress.size()+1)/2)); + +// if (codeOf_SenderAddress.size()) +// { +// // create init code that returns given contract code +// string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfSenderCode + " ) 0x" + sizeOfSenderCode + ") (RETURN 0 0x" + sizeOfSenderCode +")}"; +// bytes initBytes = compileLLL(initStringHex, true, NULL); +// initBytes += fromHex(codeOf_SenderAddress); +// bytesConstRef init(&initBytes); + +// if (!m_s.addresses().count(myAddress)) +// { +// m_ms.internal.resize(m_ms.internal.size() + 1); +// auto na = m_s.createNewAddress(myAddress, myAddress, balance(myAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); +// if (!m_ms.internal.back().from) +// m_ms.internal.pop_back(); +// if (na != myAddress) +// { +// cnote << "not able to call to : " << myAddress << "\n"; +// cnote << "in FakeExtVM you can only make a call to " << na << "\n"; +// BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(myAddress))); +// return false; +// } +// } +// } + +// if (codeOf_CodeAddress.size()) +// { +// // create init code that returns given contract code +// string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfCode + " ) 0x" + sizeOfCode + ") (RETURN 0 0x" + sizeOfCode +")}"; +// bytes initBytes = compileLLL(initStringHex, true, NULL); +// initBytes += fromHex(codeOf_CodeAddress); +// bytesConstRef init(&initBytes); + +// if (!m_s.addresses().count(_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) +// { +// m_s.noteSending(myAddress); +// m_ms.internal.resize(m_ms.internal.size() + 1); +// auto na = m_s.createNewAddress(_codeAddressOverride ? _codeAddressOverride : _receiveAddress, myAddress, balance(_codeAddressOverride ? _codeAddressOverride : _receiveAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1); +// if (!m_ms.internal.back().from) +// m_ms.internal.pop_back(); + +// if (na != (_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) +// { +// cnote << "not able to call to : " << (_codeAddressOverride ? _codeAddressOverride : _receiveAddress) << "\n"; +// cnote << "in FakeExtVM you can only make a call to " << na << "\n"; +// BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(_codeAddressOverride ? _codeAddressOverride : _receiveAddress))); +// return false; +// } +// } + +// m_ms.internal.resize(m_ms.internal.size() + 1); + +// auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), Executive::simpleTrace(), 1); + +// if (!m_ms.internal.back().from) +// m_ms.internal.pop_back(); + +// // get correct balances, (also for sucicides in the call function) +// for (auto const& f: addresses) +// { +// if (m_s.addressInUse(f.first)) +// get<0>(addresses[f.first]) = m_s.balance(f.first); +// } + +// if (!ret) +// return false; + +// // TODO: @CJentzsch refund SSTORE stuff. +// // TODO: @CJentzsch test logs. + +// // do suicides +// for (auto const& f: sub.suicides) +// addresses.erase(f); + +// // get storage +// if ((get<0>(addresses[myAddress]) >= _value) && (sub.suicides.find(_receiveAddress) == sub.suicides.end())) +// { +// for (auto const& j: m_s.storage(_receiveAddress)) +// { +// u256 adr(j.first); +// if ((j.second != 0) ) +// get<2>(addresses[_receiveAddress])[adr] = j.second; +// } +// } +// } +// else +// addresses.erase(_receiveAddress); // for the sake of comparison + +// return true; } void FakeExtVM::setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const& _data) @@ -435,8 +439,8 @@ eth::OnOpFunc FakeExtVM::simpleTrace() o << " MEMORY" << std::endl << memDump(vm.memory()); o << " STORAGE" << std::endl; - for (auto const& i: ext.state().storage(ext.myAddress)) - o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; +// for (auto const& i: ext.state().storage(ext.myAddress)) +// o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; @@ -454,70 +458,70 @@ eth::OnOpFunc FakeExtVM::simpleTrace() }; } -// THIS IS BROKEN AND NEEDS TO BE REMOVED. -h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level) -{ - (void)o_sub; - - if (!_origin) - _origin = _sender; - - if (o_ms) - { - o_ms->from = _sender; - o_ms->to = Address(); - o_ms->value = _endowment; - o_ms->input = _code.toBytes(); - } - - // Set up new account... - m_cache[_newAddress] = AddressState(0, balance(_newAddress) + _endowment, h256(), h256()); - - // Execute init code. - VM vm(*_gas); - ExtVM evm(*this, _newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); - bool revert = false; - bytesConstRef out; - - try - { - out = vm.go(evm, _onOp); - if (o_ms) - o_ms->output = out.toBytes(); - // TODO: deal with evm.sub - } - catch (OutOfGas const& /*_e*/) - { - clog(StateChat) << "Out of Gas! Reverting."; - revert = true; - } - catch (VMException const& _e) - { - clog(StateChat) << "VM Exception: " << diagnostic_information(_e); - } - catch (Exception const& _e) - { - clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); - } - catch (std::exception const& _e) - { - clog(StateChat) << "std::exception in VM: " << _e.what(); - } - - // TODO: CHECK: IS THIS CORRECT?! (esp. given account created prior to revertion init.) - - // Write state out only in the case of a non-out-of-gas transaction. - if (revert) - evm.revert(); - - // Set code. - if (addressInUse(_newAddress)) - m_cache[_newAddress].setCode(out); - - *_gas = vm.gas(); - - return _newAddress; -} +//// THIS IS BROKEN AND NEEDS TO BE REMOVED. +//h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level) +//{ +// (void)o_sub; + +// if (!_origin) +// _origin = _sender; + +// if (o_ms) +// { +// o_ms->from = _sender; +// o_ms->to = Address(); +// o_ms->value = _endowment; +// o_ms->input = _code.toBytes(); +// } + +// // Set up new account... +// m_cache[_newAddress] = AddressState(0, balance(_newAddress) + _endowment, h256(), h256()); + +// // Execute init code. +// VM vm(*_gas); +// ExtVM evm(*this, _newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); +// bool revert = false; +// bytesConstRef out; + +// try +// { +// out = vm.go(evm, _onOp); +// if (o_ms) +// o_ms->output = out.toBytes(); +// // TODO: deal with evm.sub +// } +// catch (OutOfGas const& /*_e*/) +// { +// clog(StateChat) << "Out of Gas! Reverting."; +// revert = true; +// } +// catch (VMException const& _e) +// { +// clog(StateChat) << "VM Exception: " << diagnostic_information(_e); +// } +// catch (Exception const& _e) +// { +// clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); +// } +// catch (std::exception const& _e) +// { +// clog(StateChat) << "std::exception in VM: " << _e.what(); +// } + +// // TODO: CHECK: IS THIS CORRECT?! (esp. given account created prior to revertion init.) + +// // Write state out only in the case of a non-out-of-gas transaction. +// if (revert) +// evm.revert(); + +// // Set code. +// if (addressInUse(_newAddress)) +// m_cache[_newAddress].setCode(out); + +// *_gas = vm.gas(); + +// return _newAddress; +//} namespace dev { namespace test { @@ -654,34 +658,6 @@ void doTests(json_spirit::mValue& v, bool _fillin) } } -/*string makeTestCase() -{ - json_spirit::mObject o; - - VM vm; - BlockInfo pb; - pb.hash = sha3("previousHash"); - pb.nonce = sha3("previousNonce"); - BlockInfo cb = pb; - cb.difficulty = 256; - cb.timestamp = 1; - cb.coinbaseAddress = toAddress(sha3("coinbase")); - FakeExtVM fev(pb, cb, 0); - bytes init; - fev.setContract(toAddress(sha3("contract")), ether, 0, compileLisp("(suicide (txsender))", false, init), map()); - o["env"] = fev.exportEnv(); - o["pre"] = fev.exportState(); - fev.setTransaction(toAddress(sha3("sender")), ether, finney, bytes()); - mArray execs; - execs.push_back(fev.exportExec()); - o["exec"] = execs; - vm.go(fev); - o["post"] = fev.exportState(); - o["txs"] = fev.exportTxs(); - - return json_spirit::write_string(json_spirit::mValue(o), true); -}*/ - void executeTests(const string& _name) { const char* ptestPath = getenv("ETHEREUM_TEST_PATH"); -- cgit v1.2.3 From 3d17d7b2f13545914647fd5d3eaceda3a8646fc4 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 31 Oct 2014 09:41:02 +0100 Subject: Clean up FakeExtVM - move to state tests --- vm.cpp | 192 +++-------------------------------------------------------------- 1 file changed, 6 insertions(+), 186 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 0259238f..d1728e2e 100644 --- a/vm.cpp +++ b/vm.cpp @@ -43,20 +43,6 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun t.gasPrice = gasPrice; t.gas = *_gas; t.data = _init.toBytes(); - -// m_s.noteSending(myAddress); -// m_ms.internal.resize(m_ms.internal.size() + 1); -// auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); -// if (!m_ms.internal.back().from) -// m_ms.internal.pop_back(); - -// if (get<0>(addresses[myAddress]) >= _endowment) -// { -// get<1>(addresses[myAddress])++; -// get<0>(addresses[ret]) = _endowment; -// //get<3>(addresses[ret]) = m_s.code(ret); -// } - t.type = eth::Transaction::ContractCreation; callcreates.push_back(t); return na; @@ -64,8 +50,6 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride) { -// u256 contractgas = 0xffff; - Transaction t; t.value = _value; t.gasPrice = gasPrice; @@ -76,101 +60,6 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, callcreates.push_back(t); (void)_out; return true; - -// string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) ); -// string sizeOfCode = toHex(toCompactBigEndian((codeOf_CodeAddress.size()+1)/2)); - -// string codeOf_SenderAddress = toHex(get<3>(addresses[myAddress]) ); -// string sizeOfSenderCode = toHex(toCompactBigEndian((codeOf_SenderAddress.size()+1)/2)); - -// if (codeOf_SenderAddress.size()) -// { -// // create init code that returns given contract code -// string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfSenderCode + " ) 0x" + sizeOfSenderCode + ") (RETURN 0 0x" + sizeOfSenderCode +")}"; -// bytes initBytes = compileLLL(initStringHex, true, NULL); -// initBytes += fromHex(codeOf_SenderAddress); -// bytesConstRef init(&initBytes); - -// if (!m_s.addresses().count(myAddress)) -// { -// m_ms.internal.resize(m_ms.internal.size() + 1); -// auto na = m_s.createNewAddress(myAddress, myAddress, balance(myAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1); -// if (!m_ms.internal.back().from) -// m_ms.internal.pop_back(); -// if (na != myAddress) -// { -// cnote << "not able to call to : " << myAddress << "\n"; -// cnote << "in FakeExtVM you can only make a call to " << na << "\n"; -// BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(myAddress))); -// return false; -// } -// } -// } - -// if (codeOf_CodeAddress.size()) -// { -// // create init code that returns given contract code -// string initStringHex = "{ (CODECOPY 0 (- (CODESIZE) 0x" + sizeOfCode + " ) 0x" + sizeOfCode + ") (RETURN 0 0x" + sizeOfCode +")}"; -// bytes initBytes = compileLLL(initStringHex, true, NULL); -// initBytes += fromHex(codeOf_CodeAddress); -// bytesConstRef init(&initBytes); - -// if (!m_s.addresses().count(_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) -// { -// m_s.noteSending(myAddress); -// m_ms.internal.resize(m_ms.internal.size() + 1); -// auto na = m_s.createNewAddress(_codeAddressOverride ? _codeAddressOverride : _receiveAddress, myAddress, balance(_codeAddressOverride ? _codeAddressOverride : _receiveAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1); -// if (!m_ms.internal.back().from) -// m_ms.internal.pop_back(); - -// if (na != (_codeAddressOverride ? _codeAddressOverride : _receiveAddress)) -// { -// cnote << "not able to call to : " << (_codeAddressOverride ? _codeAddressOverride : _receiveAddress) << "\n"; -// cnote << "in FakeExtVM you can only make a call to " << na << "\n"; -// BOOST_THROW_EXCEPTION(FakeExtVMFailure() << errinfo_comment("Address not callable in FakeExtVM\n") << errinfo_wrongAddress(toString(_codeAddressOverride ? _codeAddressOverride : _receiveAddress))); -// return false; -// } -// } - -// m_ms.internal.resize(m_ms.internal.size() + 1); - -// auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), Executive::simpleTrace(), 1); - -// if (!m_ms.internal.back().from) -// m_ms.internal.pop_back(); - -// // get correct balances, (also for sucicides in the call function) -// for (auto const& f: addresses) -// { -// if (m_s.addressInUse(f.first)) -// get<0>(addresses[f.first]) = m_s.balance(f.first); -// } - -// if (!ret) -// return false; - -// // TODO: @CJentzsch refund SSTORE stuff. -// // TODO: @CJentzsch test logs. - -// // do suicides -// for (auto const& f: sub.suicides) -// addresses.erase(f); - -// // get storage -// if ((get<0>(addresses[myAddress]) >= _value) && (sub.suicides.find(_receiveAddress) == sub.suicides.end())) -// { -// for (auto const& j: m_s.storage(_receiveAddress)) -// { -// u256 adr(j.first); -// if ((j.second != 0) ) -// get<2>(addresses[_receiveAddress])[adr] = j.second; -// } -// } -// } -// else -// addresses.erase(_receiveAddress); // for the sake of comparison - -// return true; } void FakeExtVM::setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const& _data) @@ -363,9 +252,9 @@ void FakeExtVM::importExec(mObject& _o) code = &thisTxCode; if (_o["code"].type() == str_type) if (_o["code"].get_str().find_first_of("0x") == 0) - thisTxCode = fromHex(_o["code"].get_str().substr(2)); - else thisTxCode = compileLLL(_o["code"].get_str()); + else + thisTxCode = fromHex(_o["code"].get_str().substr(2)); else if (_o["code"].type() == array_type) for (auto const& j: _o["code"].get_array()) thisTxCode.push_back(toByte(j)); @@ -439,9 +328,6 @@ eth::OnOpFunc FakeExtVM::simpleTrace() o << " MEMORY" << std::endl << memDump(vm.memory()); o << " STORAGE" << std::endl; -// for (auto const& i: ext.state().storage(ext.myAddress)) -// o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; - for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; @@ -458,71 +344,6 @@ eth::OnOpFunc FakeExtVM::simpleTrace() }; } -//// THIS IS BROKEN AND NEEDS TO BE REMOVED. -//h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level) -//{ -// (void)o_sub; - -// if (!_origin) -// _origin = _sender; - -// if (o_ms) -// { -// o_ms->from = _sender; -// o_ms->to = Address(); -// o_ms->value = _endowment; -// o_ms->input = _code.toBytes(); -// } - -// // Set up new account... -// m_cache[_newAddress] = AddressState(0, balance(_newAddress) + _endowment, h256(), h256()); - -// // Execute init code. -// VM vm(*_gas); -// ExtVM evm(*this, _newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); -// bool revert = false; -// bytesConstRef out; - -// try -// { -// out = vm.go(evm, _onOp); -// if (o_ms) -// o_ms->output = out.toBytes(); -// // TODO: deal with evm.sub -// } -// catch (OutOfGas const& /*_e*/) -// { -// clog(StateChat) << "Out of Gas! Reverting."; -// revert = true; -// } -// catch (VMException const& _e) -// { -// clog(StateChat) << "VM Exception: " << diagnostic_information(_e); -// } -// catch (Exception const& _e) -// { -// clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); -// } -// catch (std::exception const& _e) -// { -// clog(StateChat) << "std::exception in VM: " << _e.what(); -// } - -// // TODO: CHECK: IS THIS CORRECT?! (esp. given account created prior to revertion init.) - -// // Write state out only in the case of a non-out-of-gas transaction. -// if (revert) -// evm.revert(); - -// // Set code. -// if (addressInUse(_newAddress)) -// m_cache[_newAddress].setCode(out); - -// *_gas = vm.gas(); - -// return _newAddress; -//} - namespace dev { namespace test { void doTests(json_spirit::mValue& v, bool _fillin) @@ -758,14 +579,13 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) dev::test::executeTests("vmPushDupSwapTest"); } -BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) -{ - dev::test::executeTests("vmSystemOperationsTest"); -} +//BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) +//{ +// dev::test::executeTests("vmSystemOperationsTest"); +//} BOOST_AUTO_TEST_CASE(userDefinedFile) { - if (boost::unit_test::framework::master_test_suite().argc == 2) { string filename = boost::unit_test::framework::master_test_suite().argv[1]; -- cgit v1.2.3 From 6eeef2762c0e784bf0c44793376a70430575d34d Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 3 Nov 2014 16:33:02 +0100 Subject: Clean up and organize tests + state class tests --- vm.cpp | 207 ++++++++++++----------------------------------------------------- 1 file changed, 36 insertions(+), 171 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index e8105ac6..4061d789 100644 --- a/vm.cpp +++ b/vm.cpp @@ -20,11 +20,8 @@ * vm test functions. */ -#include #include "vm.h" -//#define FILL_TESTS - using namespace std; using namespace json_spirit; using namespace dev; @@ -59,6 +56,8 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, t.receiveAddress = _receiveAddress; callcreates.push_back(t); (void)_out; + (void)_myAddressOverride; + (void)_codeAddressOverride; return true; } @@ -91,45 +90,13 @@ void FakeExtVM::reset(u256 _myBalance, u256 _myNonce, map const& _st set(myAddress, _myBalance, _myNonce, _storage, get<3>(addresses[myAddress])); } -u256 FakeExtVM::toInt(mValue const& _v) -{ - switch (_v.type()) - { - case str_type: return u256(_v.get_str()); - case int_type: return (u256)_v.get_uint64(); - case bool_type: return (u256)(uint64_t)_v.get_bool(); - case real_type: return (u256)(uint64_t)_v.get_real(); - default: cwarn << "Bad type for scalar: " << _v.type(); - } - return 0; -} - -byte FakeExtVM::toByte(mValue const& _v) -{ - switch (_v.type()) - { - case str_type: return (byte)stoi(_v.get_str()); - case int_type: return (byte)_v.get_uint64(); - case bool_type: return (byte)_v.get_bool(); - case real_type: return (byte)_v.get_real(); - default: cwarn << "Bad type for scalar: " << _v.type(); - } - return 0; -} - void FakeExtVM::push(mObject& o, string const& _n, u256 _v) { - // if (_v < (u256)1 << 64) - // o[_n] = (uint64_t)_v; - // else o[_n] = toString(_v); } void FakeExtVM::push(mArray& a, u256 _v) { - // if (_v < (u256)1 << 64) - // a.push_back((uint64_t)_v); - // else a.push_back(toString(_v)); } @@ -202,17 +169,7 @@ void FakeExtVM::importState(mObject& _object) for (auto const& j: o["storage"].get_obj()) get<2>(a)[toInt(j.first)] = toInt(j.second); - if (o["code"].type() == str_type) - if (o["code"].get_str().find_first_of("0x") != 0) - get<3>(a) = compileLLL(o["code"].get_str(), false); - else - get<3>(a) = fromHex(o["code"].get_str().substr(2)); - else - { - get<3>(a).clear(); - for (auto const& j: o["code"].get_array()) - get<3>(a).push_back(toByte(j)); - } + get<3>(a) = importCode(o); } } @@ -250,26 +207,14 @@ void FakeExtVM::importExec(mObject& _o) thisTxCode.clear(); code = &thisTxCode; - if (_o["code"].type() == str_type) - if (_o["code"].get_str().find_first_of("0x") == 0) - thisTxCode = fromHex(_o["code"].get_str().substr(2)); - else - thisTxCode = compileLLL(_o["code"].get_str()); - else if (_o["code"].type() == array_type) - for (auto const& j: _o["code"].get_array()) - thisTxCode.push_back(toByte(j)); - else + + thisTxCode = importCode(_o); + if (_o["code"].type() != str_type && _o["code"].type() != array_type) code.reset(); thisTxData.clear(); - if (_o["data"].type() == str_type) - if (_o["data"].get_str().find_first_of("0x") == 0) - thisTxData = fromHex(_o["data"].get_str().substr(2)); - else - thisTxData = fromHex(_o["data"].get_str()); - else - for (auto const& j: _o["data"].get_array()) - thisTxData.push_back(toByte(j)); + thisTxData = importData(_o); + data = &thisTxData; } @@ -302,14 +247,7 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) t.receiveAddress = Address(tx["destination"].get_str()); t.value = toInt(tx["value"]); t.gas = toInt(tx["gasLimit"]); - if (tx["data"].type() == str_type) - if (tx["data"].get_str().find_first_of("0x") == 0) - t.data = fromHex(tx["data"].get_str().substr(2)); - else - t.data = fromHex(tx["data"].get_str()); - else - for (auto const& j: tx["data"].get_array()) - t.data.push_back(toByte(j)); + t.data = importData(tx); callcreates.push_back(t); } } @@ -346,7 +284,7 @@ eth::OnOpFunc FakeExtVM::simpleTrace() namespace dev { namespace test { -void doTests(json_spirit::mValue& v, bool _fillin) +void doVMTests(json_spirit::mValue& v, bool _fillin) { for (auto& i: v.get_obj()) { @@ -424,19 +362,10 @@ void doTests(json_spirit::mValue& v, bool _fillin) dev::test::FakeExtVM test; test.importState(o["post"].get_obj()); test.importCallCreates(o["callcreates"].get_array()); - int i = 0; - if (o["out"].type() == array_type) - for (auto const& d: o["out"].get_array()) - { - BOOST_CHECK_MESSAGE(output[i] == test.toInt(d), "Output byte [" << i << "] different!"); - ++i; - } - else if (o["out"].get_str().find("0x") == 0) - BOOST_CHECK(output == fromHex(o["out"].get_str().substr(2))); - else - BOOST_CHECK(output == fromHex(o["out"].get_str())); - BOOST_CHECK_EQUAL(test.toInt(o["gas"]), vm.gas()); + checkOutput(output, o); + + BOOST_CHECK_EQUAL(toInt(o["gas"]), vm.gas()); auto& expectedAddrs = test.addresses; auto& resultAddrs = fev.addresses; @@ -454,134 +383,68 @@ void doTests(json_spirit::mValue& v, bool _fillin) 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"); - auto&& expectedStore = std::get<2>(expectedState); - auto&& resultStore = std::get<2>(resultState); - - for (auto&& expectedStorePair : expectedStore) - { - auto& expectedStoreKey = expectedStorePair.first; - auto resultStoreIt = resultStore.find(expectedStoreKey); - if (resultStoreIt == resultStore.end()) - BOOST_ERROR(expectedAddr << ": missing store key " << expectedStoreKey); - else - { - auto& expectedStoreValue = expectedStorePair.second; - auto& resultStoreValue = resultStoreIt->second; - BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue); - } - } + checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr); } } - BOOST_CHECK(test.addresses == fev.addresses); // Just to make sure nothing missed + checkAddresses, bytes> > >(test.addresses, fev.addresses); BOOST_CHECK(test.callcreates == fev.callcreates); } } } -void executeTests(const string& _name) -{ - const char* ptestPath = getenv("ETHEREUM_TEST_PATH"); - string testPath; - - if (ptestPath == NULL) - { - cnote << " could not find environment variable ETHEREUM_TEST_PATH \n"; - testPath = "../../../tests"; - } - else - testPath = ptestPath; - - testPath += "/vmtests"; - -#ifdef FILL_TESTS - try - { - cnote << "Populating VM tests..."; - json_spirit::mValue v; - boost::filesystem::path p(__FILE__); - boost::filesystem::path dir = p.parent_path(); - string s = asString(contents(dir.string() + "/" + _name + "Filler.json")); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + _name + "Filler.json is empty."); - json_spirit::read_string(s, v); - dev::test::doTests(v, true); - writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true))); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); - } -#endif - - try - { - cnote << "Testing VM..." << _name; - json_spirit::mValue v; - string s = asString(contents(testPath + "/" + _name + ".json")); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testPath + "/" + _name + ".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?"); - json_spirit::read_string(s, v); - dev::test::doTests(v, false); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); - } - -} - } } // Namespace Close +BOOST_AUTO_TEST_SUITE(VMTests) + BOOST_AUTO_TEST_CASE(vm_tests) { - dev::test::executeTests("vmtests"); + dev::test::executeTests("vmtests", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmArithmeticTest) { - dev::test::executeTests("vmArithmeticTest"); + dev::test::executeTests("vmArithmeticTest", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmBitwiseLogicOperationTest) { - dev::test::executeTests("vmBitwiseLogicOperationTest"); + dev::test::executeTests("vmBitwiseLogicOperationTest", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmSha3Test) { - dev::test::executeTests("vmSha3Test"); + dev::test::executeTests("vmSha3Test", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmEnvironmentalInfoTest) { - dev::test::executeTests("vmEnvironmentalInfoTest"); + dev::test::executeTests("vmEnvironmentalInfoTest", "/VMTests", dev::test::doVMTests); } BOOST_AUTO_TEST_CASE(vmBlockInfoTest) { - dev::test::executeTests("vmBlockInfoTest"); + dev::test::executeTests("vmBlockInfoTest", "/VMTests", dev::test::doVMTests); } -BOOST_AUTO_TEST_CASE(vmIOandFlowOperationsTest) +//BOOST_AUTO_TEST_CASE(vmIOandFlowOperationsTest) +//{ +// dev::test::executeTests("vmIOandFlowOperationsTest", "/VMTests", dev::test::doVMTests); +//} + +BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) { - dev::test::executeTests("vmIOandFlowOperationsTest"); + dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests); } -BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) +BOOST_AUTO_TEST_CASE(vmNamecoin) { - dev::test::executeTests("vmPushDupSwapTest"); + dev::test::executeTests("vmNamecoin", "/VMTests", dev::test::doVMTests); } //BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) //{ -// dev::test::executeTests("vmSystemOperationsTest"); +// dev::test::executeTests("vmSystemOperationsTest", "/VMTests", dev::test::doVMTests); //} BOOST_AUTO_TEST_CASE(userDefinedFile) @@ -598,7 +461,7 @@ BOOST_AUTO_TEST_CASE(userDefinedFile) string s = asString(contents(filename)); BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); json_spirit::read_string(s, v); - dev::test::doTests(v, false); + dev::test::doVMTests(v, false); } catch (Exception const& _e) { @@ -611,3 +474,5 @@ BOOST_AUTO_TEST_CASE(userDefinedFile) g_logVerbosity = currentVerbosity; } } + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 1310011f77d157265c8137daf90c9f7bb9f6e90e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 3 Nov 2014 23:49:05 +0100 Subject: Fix ABAcalls OOG bug --- vm.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 4061d789..87670671 100644 --- a/vm.cpp +++ b/vm.cpp @@ -29,7 +29,7 @@ using namespace dev::eth; using namespace dev::test; FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix. - ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytesConstRef(), _previousBlock, _currentBlock, _depth) {} + ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, _depth) {} h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&) { @@ -206,11 +206,11 @@ void FakeExtVM::importExec(mObject& _o) gas = toInt(_o["gas"]); thisTxCode.clear(); - code = &thisTxCode; + code = thisTxCode; thisTxCode = importCode(_o); if (_o["code"].type() != str_type && _o["code"].type() != array_type) - code.reset(); + code.clear(); thisTxData.clear(); thisTxData = importData(_o); @@ -303,10 +303,10 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code) + if (!fev.code.size()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); - fev.code = &fev.thisTxCode; + fev.code = fev.thisTxCode; } bytes output; -- cgit v1.2.3 From 3a5808c39f10ebe3bde3d4c0ebd250013aa74591 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Tue, 4 Nov 2014 13:36:29 +0100 Subject: Update tests to latest protocol changes (PoC7) --- vm.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 617cb95c..74d300b6 100644 --- a/vm.cpp +++ b/vm.cpp @@ -695,7 +695,7 @@ void executeTests(const string& _name) else testPath = ptestPath; - testPath += "/vmtests"; + testPath += "/VMTests"; #ifdef FILL_TESTS try @@ -782,10 +782,10 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) dev::test::executeTests("vmPushDupSwapTest"); } -BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) -{ - dev::test::executeTests("vmSystemOperationsTest"); -} +//BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) +//{ +// dev::test::executeTests("vmSystemOperationsTest"); +//} BOOST_AUTO_TEST_CASE(userDefinedFile) { -- cgit v1.2.3 From adaf26d9ca4a054837eb217086c8251e7bfd238a Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 5 Nov 2014 00:12:29 +0100 Subject: uncomment vmIOandFlowOPerations test --- vm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 4061d789..67ecc261 100644 --- a/vm.cpp +++ b/vm.cpp @@ -427,10 +427,10 @@ BOOST_AUTO_TEST_CASE(vmBlockInfoTest) dev::test::executeTests("vmBlockInfoTest", "/VMTests", dev::test::doVMTests); } -//BOOST_AUTO_TEST_CASE(vmIOandFlowOperationsTest) -//{ -// dev::test::executeTests("vmIOandFlowOperationsTest", "/VMTests", dev::test::doVMTests); -//} +BOOST_AUTO_TEST_CASE(vmIOandFlowOperationsTest) +{ + dev::test::executeTests("vmIOandFlowOperationsTest", "/VMTests", dev::test::doVMTests); +} BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) { -- cgit v1.2.3 From 07ee2e48477ba411722bb05d9714ec734f1760bb Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 5 Nov 2014 13:45:19 +0000 Subject: Classify Transaction. --- vm.cpp | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 617cb95c..8344c0c5 100644 --- a/vm.cpp +++ b/vm.cpp @@ -36,11 +36,7 @@ FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFunc const&) { - Transaction t; - t.value = _endowment; - t.gasPrice = gasPrice; - t.gas = *_gas; - t.data = _init.toBytes(); + Transaction t(_endowment, gasPrice, *_gas, _init.toBytes()); m_s.noteSending(myAddress); m_ms.internal.resize(m_ms.internal.size() + 1); @@ -55,7 +51,6 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun get<3>(addresses[ret]) = m_s.code(ret); } - t.type = eth::Transaction::ContractCreation; callcreates.push_back(t); return ret; } @@ -64,13 +59,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, { u256 contractgas = 0xffff; - Transaction t; - t.value = _value; - t.gasPrice = gasPrice; - t.gas = *_gas; - t.data = _data.toVector(); - t.type = eth::Transaction::MessageCall; - t.receiveAddress = _receiveAddress; + Transaction t(_value, gasPrice, *_gas, _receiveAddress, _data.toVector()); callcreates.push_back(t); string codeOf_CodeAddress = _codeAddressOverride ? toHex(get<3>(addresses[_codeAddressOverride])) : toHex(get<3>(addresses[_receiveAddress]) ); @@ -386,10 +375,10 @@ mArray FakeExtVM::exportCallCreates() for (Transaction const& tx: callcreates) { mObject o; - o["destination"] = tx.type == Transaction::ContractCreation ? "" : toString(tx.receiveAddress); - push(o, "gasLimit", tx.gas); - push(o, "value", tx.value); - o["data"] = "0x" + toHex(tx.data); + o["destination"] = tx.type() == Transaction::ContractCreation ? "" : toString(tx.receiveAddress()); + push(o, "gasLimit", tx.gas()); + push(o, "value", tx.value()); + o["data"] = "0x" + toHex(tx.data()); ret.push_back(o); } return ret; @@ -404,19 +393,18 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) BOOST_REQUIRE(tx.count("value") > 0); BOOST_REQUIRE(tx.count("destination") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0); - Transaction t; - t.type = tx["destination"].get_str().empty() ? Transaction::ContractCreation : Transaction::MessageCall; - t.receiveAddress = Address(tx["destination"].get_str()); - t.value = toInt(tx["value"]); - t.gas = toInt(tx["gasLimit"]); + bytes data; if (tx["data"].type() == str_type) if (tx["data"].get_str().find_first_of("0x") == 0) - t.data = fromHex(tx["data"].get_str().substr(2)); + data = fromHex(tx["data"].get_str().substr(2)); else - t.data = fromHex(tx["data"].get_str()); + data = fromHex(tx["data"].get_str()); else for (auto const& j: tx["data"].get_array()) - t.data.push_back(toByte(j)); + data.push_back(toByte(j)); + Transaction t = tx["destination"].get_str().empty() ? + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data) : + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data); callcreates.push_back(t); } } -- cgit v1.2.3 From 6b6bb65eb8bdca8754d334510fc6938ff4b1ef5c Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 5 Nov 2014 18:30:38 +0100 Subject: Update transactions, style fix --- vm.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index b9df6af2..0457d7bb 100644 --- a/vm.cpp +++ b/vm.cpp @@ -232,8 +232,8 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) BOOST_REQUIRE(tx.count("destination") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0); Transaction t = tx["destination"].get_str().empty() ? - Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data) : - Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data); + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data.toBytes()) : + Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data.toBytes()); callcreates.push_back(t); } } @@ -423,16 +423,6 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests); } -BOOST_AUTO_TEST_CASE(vmNamecoin) -{ - dev::test::executeTests("vmNamecoin", "/VMTests", dev::test::doVMTests); -} - -//BOOST_AUTO_TEST_CASE(vmSystemOperationsTest) -//{ -// dev::test::executeTests("vmSystemOperationsTest", "/VMTests", dev::test::doVMTests); -//} - BOOST_AUTO_TEST_CASE(userDefinedFile) { if (boost::unit_test::framework::master_test_suite().argc == 2) -- cgit v1.2.3 From e53f83151096f51328ef03a355c58bb8e84064a3 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 5 Nov 2014 21:02:16 +0100 Subject: Added dynamic jump out of code test --- vm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 0457d7bb..acede800 100644 --- a/vm.cpp +++ b/vm.cpp @@ -213,7 +213,7 @@ mArray FakeExtVM::exportCallCreates() for (Transaction const& tx: callcreates) { mObject o; - o["destination"] = tx.type() == Transaction::ContractCreation ? "" : toString(tx.receiveAddress()); + o["destination"] = tx.isCreation() ? "" : toString(tx.receiveAddress()); push(o, "gasLimit", tx.gas()); push(o, "value", tx.value()); o["data"] = "0x" + toHex(tx.data()); -- cgit v1.2.3 From 139668dea45f9ee13c889a94b2515dec86387b3c Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 5 Nov 2014 21:55:10 +0100 Subject: style --- vm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index acede800..c6799daa 100644 --- a/vm.cpp +++ b/vm.cpp @@ -231,7 +231,7 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) BOOST_REQUIRE(tx.count("value") > 0); BOOST_REQUIRE(tx.count("destination") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0); -Transaction t = tx["destination"].get_str().empty() ? + Transaction t = tx["destination"].get_str().empty() ? Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data.toBytes()) : Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data.toBytes()); callcreates.push_back(t); -- cgit v1.2.3 From ab3a1ec6ef5f7d37baad864b3235c37f7e518144 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 13:29:13 +0100 Subject: Added random test execution --- vm.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index a093966d..ccf78802 100644 --- a/vm.cpp +++ b/vm.cpp @@ -20,6 +20,7 @@ * vm test functions. */ +#include #include "vm.h" using namespace std; @@ -423,6 +424,41 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest) dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests); } +BOOST_AUTO_TEST_CASE(vmRandom) +{ + string testPath = getTestPath(); + testPath += "/VMTests/RandomTests"; + + vector testFiles; + boost::filesystem::directory_iterator iterator(testPath); + for(; iterator != boost::filesystem::directory_iterator(); ++iterator) + if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() == ".json") + testFiles.push_back(iterator->path()); + + for (auto& path: testFiles) + { + try + { + cnote << "Testing ..." << path.filename(); + json_spirit::mValue v; + string testpath(path.c_str()); + string s = asString(dev::contents(testpath)); + + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testpath + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?"); + json_spirit::read_string(s, v); + doVMTests(v, false); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e)); + } + catch (std::exception const& _e) + { + BOOST_ERROR("Failed test with Exception: " << _e.what()); + } + } +} + BOOST_AUTO_TEST_CASE(userDefinedFile) { if (boost::unit_test::framework::master_test_suite().argc == 2) -- cgit v1.2.3 From a6ba0f7908627b65d3b115e342746819a2186d10 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 15:16:42 +0100 Subject: style --- vm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index a093966d..93cf121d 100644 --- a/vm.cpp +++ b/vm.cpp @@ -289,7 +289,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code.size()) + if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode; -- cgit v1.2.3 From b4d8ff5fdc82a1b93defa94cb3b0a075f13600f7 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 10 Nov 2014 07:12:29 +0100 Subject: specified user defined test --- vm.cpp | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index ccf78802..040506b8 100644 --- a/vm.cpp +++ b/vm.cpp @@ -459,31 +459,42 @@ BOOST_AUTO_TEST_CASE(vmRandom) } } -BOOST_AUTO_TEST_CASE(userDefinedFile) +BOOST_AUTO_TEST_CASE(userDefinedFileVM) { - if (boost::unit_test::framework::master_test_suite().argc == 2) + for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) { - string filename = boost::unit_test::framework::master_test_suite().argv[1]; - int currentVerbosity = g_logVerbosity; - g_logVerbosity = 12; - try - { - cnote << "Testing VM..." << "user defined test"; - json_spirit::mValue v; - string s = asString(contents(filename)); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); - json_spirit::read_string(s, v); - dev::test::doVMTests(v, false); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) + string arg = boost::unit_test::framework::master_test_suite().argv[i]; + if (arg == "--vmtest") { - BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); + if (i + 1 >= boost::unit_test::framework::master_test_suite().argc) + { + cnote << "Missing filename\nUsage: testeth --vmtest \n"; + return; + } + string filename = boost::unit_test::framework::master_test_suite().argv[i+1]; + int currentVerbosity = g_logVerbosity; + g_logVerbosity = 12; + try + { + cnote << "Testing VM..." << "user defined test"; + json_spirit::mValue v; + string s = asString(contents(filename)); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); + json_spirit::read_string(s, v); + dev::test::doVMTests(v, false); + } + catch (Exception const& _e) + { + BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e)); + } + catch (std::exception const& _e) + { + BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); + } + g_logVerbosity = currentVerbosity; } - g_logVerbosity = currentVerbosity; + else + continue; } } -- cgit v1.2.3 From 3c45877e2aecb7e73392540fdbf82de0bd35156e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 10 Nov 2014 17:37:55 +0100 Subject: added generic userDefinedTest function --- vm.cpp | 42 +++--------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index 36970509..a3475ac0 100644 --- a/vm.cpp +++ b/vm.cpp @@ -441,10 +441,8 @@ BOOST_AUTO_TEST_CASE(vmRandom) { cnote << "Testing ..." << path.filename(); json_spirit::mValue v; - string testpath(path.c_str()); - string s = asString(dev::contents(testpath)); - - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testpath + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?"); + string s = asString(dev::contents(path.string())); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + path.string() + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?"); json_spirit::read_string(s, v); doVMTests(v, false); } @@ -461,41 +459,7 @@ BOOST_AUTO_TEST_CASE(vmRandom) BOOST_AUTO_TEST_CASE(userDefinedFileVM) { - for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) - { - string arg = boost::unit_test::framework::master_test_suite().argv[i]; - if (arg == "--vmtest") - { - if (i + 1 >= boost::unit_test::framework::master_test_suite().argc) - { - cnote << "Missing filename\nUsage: testeth --vmtest \n"; - return; - } - string filename = boost::unit_test::framework::master_test_suite().argv[i+1]; - int currentVerbosity = g_logVerbosity; - g_logVerbosity = 12; - try - { - cnote << "Testing VM..." << "user defined test"; - json_spirit::mValue v; - string s = asString(contents(filename)); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. "); - json_spirit::read_string(s, v); - dev::test::doVMTests(v, false); - } - catch (Exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e)); - } - catch (std::exception const& _e) - { - BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); - } - g_logVerbosity = currentVerbosity; - } - else - continue; - } + userDefinedTest("--vmtest", dev::test::doVMTests); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 9b14af5c15971329c7520b9754d04664c71a2987 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 10 Nov 2014 18:30:35 +0100 Subject: build fix --- vm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index a3475ac0..b36d3dc2 100644 --- a/vm.cpp +++ b/vm.cpp @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(vmRandom) BOOST_AUTO_TEST_CASE(userDefinedFileVM) { - userDefinedTest("--vmtest", dev::test::doVMTests); + dev::test::userDefinedTest("--vmtest", dev::test::doVMTests); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From d3910593a08bf1718b35136d2119462c36e12920 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 10 Nov 2014 22:26:07 +0100 Subject: All unintended VM exceptions work like OOG in tests --- vm.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'vm.cpp') diff --git a/vm.cpp b/vm.cpp index b36d3dc2..cacbf94c 100644 --- a/vm.cpp +++ b/vm.cpp @@ -298,19 +298,27 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) bytes output; VM vm(fev.gas); + + u256 gas; try { output = vm.go(fev, fev.simpleTrace()).toVector(); + gas = vm.gas(); + } + catch (VMException const& _e) + { + cnote << "VM did throw an exception: " << diagnostic_information(_e); + gas = 0; } catch (Exception const& _e) { cnote << "VM did throw an exception: " << diagnostic_information(_e); - //BOOST_ERROR("Failed VM Test with Exception: " << e.what()); + BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); } catch (std::exception const& _e) { cnote << "VM did throw an exception: " << _e.what(); - //BOOST_ERROR("Failed VM Test with Exception: " << e.what()); + BOOST_ERROR("Failed VM Test with Exception: " << _e.what()); } // delete null entries in storage for the sake of comparison @@ -337,7 +345,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["post"] = mValue(fev.exportState()); o["callcreates"] = fev.exportCallCreates(); o["out"] = "0x" + toHex(output); - fev.push(o, "gas", vm.gas()); + fev.push(o, "gas", gas); } else { @@ -352,7 +360,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) checkOutput(output, o); - BOOST_CHECK_EQUAL(toInt(o["gas"]), vm.gas()); + BOOST_CHECK_EQUAL(toInt(o["gas"]), gas); auto& expectedAddrs = test.addresses; auto& resultAddrs = fev.addresses; -- cgit v1.2.3