From 1905208649843cbd52d5ff8be5be6c8206755038 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Mon, 27 Oct 2014 18:59:42 +0100 Subject: Add VMTRACE to user defined vm test Conflicts: test/vm.cpp --- vm.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- vm.h | 3 +++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/vm.cpp b/vm.cpp index fe486304..c0452ef7 100644 --- a/vm.cpp +++ b/vm.cpp @@ -20,9 +20,9 @@ * vm test functions. */ -#include "vm.h" -#include #include +#include +#include "vm.h" //#define FILL_TESTS @@ -63,6 +63,7 @@ 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; @@ -422,8 +423,27 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) } } -// 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) +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(true) << o.str(); + dev::LogOutputStream(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
* o_suicides, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level) { (void)o_sub; @@ -520,7 +540,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) { @@ -756,3 +776,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()); + } + } +} diff --git a/vm.h b/vm.h index 58ff58cd..bf44c4b4 100644 --- a/vm.h +++ b/vm.h @@ -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, bytes>> addresses; eth::Transactions callcreates; bytes thisTxData; -- cgit