Fabcoin Core  0.16.2
P2P Digital Currency
vm.h
Go to the documentation of this file.
1 /*
2 This file is part of cpp-ethereum.
3 
4 cpp-ethereum is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 cpp-ethereum is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
24 #pragma once
25 
26 #include <fstream>
27 #include <cstdint>
28 
30 #include <boost/test/unit_test.hpp>
31 
33 #include <libdevcore/Log.h>
34 #include <libdevcore/CommonIO.h>
35 #include <libevmcore/Instruction.h>
36 #include <libevm/ExtVMFace.h>
37 #include <libevm/VM.h>
39 #include <libethereum/ExtVM.h>
40 #include <libethereum/State.h>
41 
42 namespace dev { namespace test {
43 
45 {
46 public:
47  FakeExtVM() = delete;
48  FakeExtVM(eth::EnvInfo const& _envInfo, unsigned _depth = 0);
49 
50  virtual u256 store(u256 _n) override { return std::get<2>(addresses[myAddress])[_n]; }
51  virtual void setStore(u256 _n, u256 _v) override { std::get<2>(addresses[myAddress])[_n] = _v; }
52  virtual bool exists(Address _a) override { return !!addresses.count(_a); }
53  virtual u256 balance(Address _a) override { return std::get<0>(addresses[_a]); }
54  virtual void suicide(Address _a) override { std::get<0>(addresses[_a]) += std::get<0>(addresses[myAddress]); addresses.erase(myAddress); }
55  virtual bytes const& codeAt(Address _a) override { return std::get<3>(addresses[_a]); }
56  virtual size_t codeSizeAt(Address _a) override { return std::get<3>(addresses[_a]).size(); }
57  virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _init, eth::OnOpFunc const&) override;
58  virtual boost::optional<eth::owning_bytes_ref> call(eth::CallParameters&) override;
59  void setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const& _data);
60  void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code);
61  void set(Address _a, u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage, bytes const& _code);
62  void reset(u256 _myBalance, u256 _myNonce, std::map<u256, u256> const& _storage);
63  u256 doPosts();
67  void importState(json_spirit::mObject& _object);
71  void importCallCreates(json_spirit::mArray& _callcreates);
72 
73  eth::OnOpFunc simpleTrace() const;
74 
75  std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
81 };
82 
83 
84 } } // Namespace Close
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
static dev::eth::EnvInfo importEnv(json_spirit::mObject &_o)
Definition: vm.cpp:82
virtual u256 store(u256 _n) override
Read storage location.
Definition: vm.h:50
virtual size_t codeSizeAt(Address _a) override
Definition: vm.h:56
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
Definition: Transaction.h:121
json_spirit::mObject exportExec()
Definition: vm.cpp:144
void importState(json_spirit::mObject &_object)
Definition: vm.cpp:123
virtual u256 balance(Address _a) override
Read address&#39;s balance.
Definition: vm.h:53
virtual bool exists(Address _a) override
Does the account exist?
Definition: vm.h:52
bytes thisTxCode
Definition: vm.h:78
virtual void suicide(Address _a) override
Suicide the associated contract and give proceeds to the given address.
Definition: vm.h:54
void importCallCreates(json_spirit::mArray &_callcreates)
Definition: vm.cpp:205
json_spirit::mObject exportEnv()
Definition: vm.cpp:71
mConfig::Array_type mArray
json_spirit::mObject exportState()
Definition: vm.cpp:103
std::map< Address, std::tuple< u256, u256, std::map< u256, u256 >, bytes > > addresses
Definition: vm.h:75
virtual boost::optional< eth::owning_bytes_ref > call(eth::CallParameters &) override
Make a new message call.
Definition: vm.cpp:49
bytes thisTxData
Definition: vm.h:77
std::vector< byte > bytes
Definition: Common.h:75
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
std::function< void(uint64_t, uint64_t, Instruction, bigint, bigint, bigint, VM *, ExtVMFace const *)> OnOpFunc
Definition: ExtVMFace.h:193
eth::Transactions callcreates
Definition: vm.h:76
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
eth::OnOpFunc simpleTrace() const
Definition: vm.cpp:221
mConfig::Object_type mObject
Interface and null implementation of the class for specifying VM externalities.
Definition: ExtVMFace.h:265
Address myAddress
Address associated with executing code (a contract, or contract-to-be).
Definition: ExtVMFace.h:323
uint8_t const size_t const size
Definition: sha3.h:20
void setContract(Address _myAddress, u256 _myBalance, u256 _myNonce, std::map< u256, u256 > const &_storage, bytes const &_code)
virtual bytes const & codeAt(Address _a) override
Read address&#39;s code.
Definition: vm.h:55
void importExec(json_spirit::mObject &_o)
Definition: vm.cpp:158
virtual void setStore(u256 _n, u256 _v) override
Write a value in storage.
Definition: vm.h:51
u256 execGas
Definition: vm.h:80
json_spirit::mArray exportCallCreates()
Definition: vm.cpp:190
void reset(u256 _myBalance, u256 _myNonce, std::map< u256, u256 > const &_storage)
Definition: vm.cpp:64
virtual h160 create(u256 _endowment, u256 &io_gas, bytesConstRef _init, eth::OnOpFunc const &) override
Create a new (contract) account.
Definition: vm.cpp:40
Helper functions to work with json::spirit and test files.
void setTransaction(Address _caller, u256 _value, u256 _gasPrice, bytes const &_data)