2014-09-27 10:51:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of cpp-ethereum.
|
|
|
|
|
|
|
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
cpp-ethereum is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/** @file vm.h
|
|
|
|
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com>
|
|
|
|
* @author Gav Wood <i@gavwood.com>
|
|
|
|
* @date 2014
|
|
|
|
* vm test functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <cstdint>
|
2014-10-01 11:59:07 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2014-12-14 18:11:54 +00:00
|
|
|
#include <json_spirit/json_spirit.h>
|
2014-09-27 10:51:34 +00:00
|
|
|
#include <libdevcore/Log.h>
|
2014-10-27 21:21:30 +00:00
|
|
|
#include <libdevcore/CommonIO.h>
|
2014-11-06 13:50:18 +00:00
|
|
|
#include <libevmcore/Instruction.h>
|
2014-09-27 10:51:34 +00:00
|
|
|
#include <libevm/ExtVMFace.h>
|
|
|
|
#include <libevm/VM.h>
|
|
|
|
#include <liblll/Compiler.h>
|
|
|
|
#include <libethereum/Transaction.h>
|
|
|
|
#include <libethereum/ExtVM.h>
|
2014-10-01 11:59:07 +00:00
|
|
|
#include <libethereum/State.h>
|
2014-11-03 15:33:02 +00:00
|
|
|
#include "TestHelper.h"
|
2014-09-27 10:51:34 +00:00
|
|
|
|
|
|
|
namespace dev { namespace test {
|
|
|
|
|
2014-10-06 08:17:27 +00:00
|
|
|
struct FakeExtVMFailure : virtual Exception {};
|
|
|
|
|
2014-09-27 10:51:34 +00:00
|
|
|
class FakeExtVM: public eth::ExtVMFace
|
|
|
|
{
|
|
|
|
public:
|
2014-10-22 10:45:26 +00:00
|
|
|
FakeExtVM() = default;
|
2014-10-08 15:51:51 +00:00
|
|
|
FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth = 0);
|
2014-09-27 10:51:34 +00:00
|
|
|
|
2014-10-22 10:45:26 +00:00
|
|
|
virtual u256 store(u256 _n) override { return std::get<2>(addresses[myAddress])[_n]; }
|
|
|
|
virtual void setStore(u256 _n, u256 _v) override { std::get<2>(addresses[myAddress])[_n] = _v; }
|
|
|
|
virtual u256 balance(Address _a) override { return std::get<0>(addresses[_a]); }
|
|
|
|
virtual void subBalance(u256 _a) override { std::get<0>(addresses[myAddress]) -= _a; }
|
|
|
|
virtual u256 txCount(Address _a) override { return std::get<1>(addresses[_a]); }
|
|
|
|
virtual void suicide(Address _a) override { std::get<0>(addresses[_a]) += std::get<0>(addresses[myAddress]); addresses.erase(myAddress); }
|
|
|
|
virtual bytes const& codeAt(Address _a) override { return std::get<3>(addresses[_a]); }
|
2014-12-12 12:33:42 +00:00
|
|
|
virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _init, eth::OnOpFunc const&) override;
|
|
|
|
virtual bool call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256& io_gas, bytesRef _out, eth::OnOpFunc const&, Address, Address) override;
|
2014-09-27 10:51:34 +00:00
|
|
|
void setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const& _data);
|
|
|
|
void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code);
|
|
|
|
void set(Address _a, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code);
|
|
|
|
void reset(u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage);
|
|
|
|
void push(json_spirit::mObject& o, std::string const& _n, u256 _v);
|
|
|
|
void push(json_spirit::mArray& a, u256 _v);
|
2014-10-06 19:42:41 +00:00
|
|
|
u256 doPosts();
|
2014-09-27 10:51:34 +00:00
|
|
|
json_spirit::mObject exportEnv();
|
|
|
|
void importEnv(json_spirit::mObject& _o);
|
|
|
|
json_spirit::mObject exportState();
|
|
|
|
void importState(json_spirit::mObject& _object);
|
|
|
|
json_spirit::mObject exportExec();
|
|
|
|
void importExec(json_spirit::mObject& _o);
|
|
|
|
json_spirit::mArray exportCallCreates();
|
|
|
|
void importCallCreates(json_spirit::mArray& _callcreates);
|
|
|
|
|
2014-10-27 21:21:30 +00:00
|
|
|
eth::OnOpFunc simpleTrace();
|
2014-10-27 17:59:42 +00:00
|
|
|
|
2014-09-27 10:51:34 +00:00
|
|
|
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
|
|
|
|
eth::Transactions callcreates;
|
|
|
|
bytes thisTxData;
|
|
|
|
bytes thisTxCode;
|
|
|
|
u256 gas;
|
|
|
|
};
|
|
|
|
|
2014-10-27 21:21:30 +00:00
|
|
|
|
2014-09-27 10:51:34 +00:00
|
|
|
} } // Namespace Close
|