ledger-core
BaseFixture.h
1 /*
2  *
3  * BaseFixture.h
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 21/09/2017.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2017 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 
32 #ifndef LEDGER_CORE_BASEFIXTURE_H
33 #define LEDGER_CORE_BASEFIXTURE_H
34 
35 #include <gtest/gtest.h>
36 #include <async/QtThreadDispatcher.hpp>
37 #include <src/database/DatabaseSessionPool.hpp>
38 #include <NativePathResolver.hpp>
39 #include <unordered_set>
40 #include <src/wallet/pool/WalletPool.hpp>
41 #include <CoutLogPrinter.hpp>
42 #include <src/api/DynamicObject.hpp>
43 #include <wallet/common/CurrencyBuilder.hpp>
44 #include <wallet/bitcoin/BitcoinLikeWallet.hpp>
45 #include <wallet/bitcoin/database/BitcoinLikeWalletDatabase.h>
46 #include <wallet/bitcoin/database/BitcoinLikeTransactionDatabaseHelper.h>
47 #include <wallet/common/database/AccountDatabaseHelper.h>
48 #include <wallet/pool/database/PoolDatabaseHelper.hpp>
49 #include <utils/JSONUtils.h>
50 #include <wallet/bitcoin/explorers/api/TransactionParser.hpp>
51 #include <async/async_wait.h>
52 #include <wallet/bitcoin/BitcoinLikeAccount.hpp>
53 #include <wallet/ethereum/EthereumLikeAccount.h>
54 #include <wallet/ripple/RippleLikeAccount.h>
55 #include <wallet/tezos/TezosLikeAccount.h>
56 #include <api/BitcoinLikeOperation.hpp>
57 #include <api/BitcoinLikeTransaction.hpp>
58 #include <api/BitcoinLikeInput.hpp>
59 #include <api/BitcoinLikeOutput.hpp>
60 #include <api/BigInt.hpp>
61 #include <net/QtHttpClient.hpp>
62 #include <events/LambdaEventReceiver.hpp>
63 #include <soci.h>
64 #include <api/Account.hpp>
65 #include <api/BitcoinLikeAccount.hpp>
66 #include <FakeWebSocketClient.h>
67 #include <OpenSSLRandomNumberGenerator.hpp>
68 
69 using namespace ledger::core; // Only do that for testing
70 using namespace ledger::qt; // Djeez
71 
72 extern api::ExtendedKeyAccountCreationInfo P2PKH_MEDIUM_XPUB_INFO;
73 extern api::ExtendedKeyAccountCreationInfo P2WPKH_MEDIUM_XPUB_INFO;
74 extern api::AccountCreationInfo P2PKH_MEDIUM_KEYS_INFO;
75 extern api::ExtendedKeyAccountCreationInfo P2PKH_BIG_XPUB_INFO;
76 extern api::ExtendedKeyAccountCreationInfo P2SH_XPUB_INFO;
77 extern api::ExtendedKeyAccountCreationInfo ETH_XPUB_INFO;
78 extern api::ExtendedKeyAccountCreationInfo ETH_ROPSTEN_XPUB_INFO;
79 extern api::ExtendedKeyAccountCreationInfo ETH_MAIN_XPUB_INFO;
80 extern api::AccountCreationInfo ETH_KEYS_INFO;
81 extern api::AccountCreationInfo ETH_KEYS_INFO_VAULT;
82 extern api::AccountCreationInfo ETH_KEYS_INFO_LIVE;
83 extern api::AccountCreationInfo ETC_KEYS_INFO_LIVE;
84 extern api::AccountCreationInfo XRP_KEYS_INFO;
85 extern api::AccountCreationInfo VAULT_XRP_KEYS_INFO;
86 extern api::AccountCreationInfo XTZ_KEYS_INFO;
87 extern const std::string TX_1;
88 extern const std::string TX_2;
89 extern const std::string TX_3;
90 extern const std::string TX_4;
91 
92 
93 class BaseFixture : public ::testing::Test {
94 public:
95  void SetUp() override;
96  void TearDown() override;
97  std::shared_ptr<WalletPool> newDefaultPool(const std::string &poolName = "my_ppol", const std::string &password = "test");
98  void createWallet(const std::shared_ptr<WalletPool>& pool,
99  const std::string& walletName,
100  const std::string& currencyName,
101  const std::shared_ptr<api::DynamicObject> &configuration);
102  void createAccount(const std::shared_ptr<WalletPool>& pool, const std::string &walletName, int32_t index);
103  BitcoinLikeWalletDatabase newBitcoinAccount(const std::shared_ptr<WalletPool>& pool,
104  const std::string& walletName,
105  const std::string& currencyName,
106  const std::shared_ptr<api::DynamicObject> &configuration,
107  int32_t index,
108  const std::string& xpub);
109  std::shared_ptr<BitcoinLikeAccount> createBitcoinLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
110  int32_t index,
111  const api::AccountCreationInfo &info);
112  std::shared_ptr<BitcoinLikeAccount> createBitcoinLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
113  int32_t index,
115 
116  std::shared_ptr<EthereumLikeAccount> createEthereumLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
117  int32_t index,
118  const api::AccountCreationInfo &info);
119  std::shared_ptr<EthereumLikeAccount> createEthereumLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
120  int32_t index,
122 
123  std::shared_ptr<RippleLikeAccount> createRippleLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
124  int32_t index,
125  const api::AccountCreationInfo &info);
126  std::shared_ptr<RippleLikeAccount> createRippleLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
127  int32_t index,
129  std::shared_ptr<TezosLikeAccount> createTezosLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
130  int32_t index,
131  const api::AccountCreationInfo &info);
132 
133  std::shared_ptr<QtThreadDispatcher> dispatcher;
134  std::shared_ptr<NativePathResolver> resolver;
135  std::shared_ptr<DatabaseBackend> backend;
136  std::shared_ptr<CoutLogPrinter> printer;
137  std::shared_ptr<QtHttpClient> http;
138  std::shared_ptr<FakeWebSocketClient> ws;
139  std::shared_ptr<OpenSSLRandomNumberGenerator> rng;
140 };
141 
142 #endif //LEDGER_CORE_BASEFIXTURE_H
Definition: Account.cpp:8
Definition: BitcoinLikeWalletDatabase.h:42
Definition: ExtendedKeyAccountCreationInfo.hpp:16
Definition: BaseFixture.h:76
Definition: AccountCreationInfo.hpp:16