Fabcoin Core  0.16.2
P2P Digital Currency
ImportTest.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 */
21 #pragma once
25 #include <libethereum/State.h>
26 
27 namespace dev
28 {
29 namespace test
30 {
31 
32 enum class testType
33 {
34  StateTests,
37  Other
38 };
39 
41 {
42 public:
43  ImportTest(json_spirit::mObject& _o, bool isFiller, testType testTemplate = testType::StateTests);
44 
45  // imports
46  void importEnv(json_spirit::mObject& _o);
47  static void importState(json_spirit::mObject const& _o, eth::State& _state);
48  static void importState(json_spirit::mObject const& _o, eth::State& _state, eth::AccountMaskMap& o_mask);
49  static void importTransaction (json_spirit::mObject const& _o, eth::Transaction& o_tr);
50  void importTransaction(json_spirit::mObject const& _o);
51  static json_spirit::mObject& makeAllFieldsHex(json_spirit::mObject& _o);
52 
53  bytes executeTest();
54  int exportTest(bytes const& _output);
55  static int compareStates(eth::State const& _stateExpect, eth::State const& _statePost, eth::AccountMaskMap const _expectedStateOptions = eth::AccountMaskMap(), WhenError _throw = WhenError::Throw);
56  void checkGeneralTestSection(json_spirit::mObject const& _expects, std::vector<size_t>& _errorTransactions, std::string const& _network="") const;
57 
62 
63 private:
64  typedef std::pair<eth::ExecutionResult, eth::TransactionReceipt> execOutput;
65  std::pair<eth::State, execOutput> executeTransaction(eth::Network const _sealEngineNetwork, eth::EnvInfo const& _env, eth::State const& _preState, eth::Transaction const& _tr);
66 
69 
70  //General State Tests
72  {
73  transactionToExecute(int d, int g, int v, eth::Transaction const& t):
74  dataInd(d), gasInd(g), valInd(v), transaction(t), postState(0), netId(eth::Network::MainNetwork) {}
75  int dataInd;
76  int gasInd;
77  int valInd;
81  };
82  std::vector<transactionToExecute> m_transactions;
83  using StateAndMap = std::pair<eth::State, eth::AccountMaskMap>;
84  using TrExpectSection = std::pair<transactionToExecute, StateAndMap>;
85  void checkGeneralTestSectionSearch(json_spirit::mObject const& _expects, std::vector<size_t>& _errorTransactions, std::string const& _network = "", TrExpectSection* _search = NULL) const;
86 
89 };
90 
91 } //namespace test
92 } //namespace dev
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Network
The network id.
Definition: GenesisInfo.h:34
std::pair< transactionToExecute, StateAndMap > TrExpectSection
Definition: ImportTest.h:84
#define g(i)
Definition: sha.cpp:735
std::pair< eth::ExecutionResult, eth::TransactionReceipt > execOutput
Definition: ImportTest.h:64
WhenError
Definition: CommonData.h:39
Model of an Ethereum state, essentially a facade for the trie.
Definition: State.h:161
eth::EnvInfo m_envInfo
Definition: ImportTest.h:67
eth::Transaction m_transaction
Definition: ImportTest.h:68
transactionToExecute(int d, int g, int v, eth::Transaction const &t)
Definition: ImportTest.h:73
std::vector< byte > bytes
Definition: Common.h:75
json_spirit::mObject & m_testObject
Definition: ImportTest.h:87
Network
Definition: netaddress.h:19
std::pair< eth::State, eth::AccountMaskMap > StateAndMap
Definition: ImportTest.h:83
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Definition: Transaction.h:84
std::unordered_map< Address, AccountMask > AccountMaskMap
Definition: Account.h:240
mConfig::Object_type mObject
eth::State m_statePre
Definition: ImportTest.h:58
std::vector< transactionToExecute > m_transactions
Definition: ImportTest.h:82
eth::State m_statePost
Definition: ImportTest.h:59
#define d(i)
Definition: sha.cpp:732
eth::LogEntries m_logsExpected
Definition: ImportTest.h:61
eth::LogEntries m_logs
Definition: ImportTest.h:60
std::vector< LogEntry > LogEntries
Definition: ExtVMFace.h:110