diff options
author | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-10-27 19:45:29 +0800 |
---|---|---|
committer | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-10-27 19:45:29 +0800 |
commit | 4651b9f3a71b5ef7b20fe88a0344af6f31a51cc8 (patch) | |
tree | cbb91aa6af8633785059bd074f29523619bb9425 | |
parent | 08c45c85b49edad8451a03df4a31363f216db97c (diff) | |
download | dexon-solidity-4651b9f3a71b5ef7b20fe88a0344af6f31a51cc8.tar.gz dexon-solidity-4651b9f3a71b5ef7b20fe88a0344af6f31a51cc8.tar.zst dexon-solidity-4651b9f3a71b5ef7b20fe88a0344af6f31a51cc8.zip |
Add VMTRACE to user defined vm test
-rw-r--r-- | vm.cpp | 54 | ||||
-rw-r--r-- | vm.h | 3 |
2 files changed, 54 insertions, 3 deletions
@@ -20,9 +20,9 @@ * vm test functions. */ -#include "vm.h" -#include <libdevcore/CommonIO.h> #include <boost/filesystem/path.hpp> +#include <libdevcore/CommonIO.h> +#include "vm.h" //#define FILL_TESTS @@ -418,6 +418,26 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) } } +OnOpFunc FakeExtVM::simpleTrace() +{ + return [](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt) + { + FakeExtVM const& ext = *(FakeExtVM const*)voidExt; + VM& vm = *(VM*)voidVM; + + ostringstream o; + o << endl << " STACK" << endl; + for (auto i: vm.stack()) + o << (h256)i << endl; + o << " MEMORY" << endl << memDump(vm.memory()); + o << " STORAGE" << endl; + for (auto const& i: ext.state().storage(ext.myAddress)) + o << showbase << hex << i.first << ": " << i.second << endl; + dev::LogOutputStream<VMTraceChannel, false>(true) << o.str(); + dev::LogOutputStream<VMTraceChannel, false>(false) << " | " << dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << dec << vm.gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32" << " ]"; + }; +} + h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, std::set<Address>* o_suicides, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level) { if (!_origin) @@ -484,6 +504,7 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end + namespace dev { namespace test { void doTests(json_spirit::mValue& v, bool _fillin) @@ -515,7 +536,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) VM vm(fev.gas); try { - output = vm.go(fev).toVector(); + output = vm.go(fev, fev.simpleTrace()).toVector(); } catch (Exception const& _e) { @@ -751,3 +772,30 @@ 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]; + 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::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()); + } + } +} @@ -80,6 +80,9 @@ public: json_spirit::mArray exportCallCreates(); void importCallCreates(json_spirit::mArray& _callcreates); + static eth::OnOpFunc simpleTrace(); + FakeState state() const { return m_s; } + std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses; eth::Transactions callcreates; bytes thisTxData; |