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 <api/BitcoinLikeOperation.hpp>
54 #include <api/BitcoinLikeTransaction.hpp>
55 #include <api/BitcoinLikeInput.hpp>
56 #include <api/BitcoinLikeOutput.hpp>
57 #include <api/BigInt.hpp>
58 #include <net/QtHttpClient.hpp>
59 #include <events/LambdaEventReceiver.hpp>
60 #include <soci.h>
61 #include <api/Account.hpp>
62 #include <api/BitcoinLikeAccount.hpp>
63 
64 using namespace ledger::core; // Only do that for testing
65 using namespace ledger::qt; // Djeez
66 
67 extern api::ExtendedKeyAccountCreationInfo P2PKH_MEDIUM_XPUB_INFO;
68 extern api::AccountCreationInfo P2PKH_MEDIUM_KEYS_INFO;
69 extern api::ExtendedKeyAccountCreationInfo P2PKH_BIG_XPUB_INFO;
70 extern const std::string TX_1;
71 extern const std::string TX_2;
72 extern const std::string TX_3;
73 extern const std::string TX_4;
74 
75 
76 class BaseFixture : public ::testing::Test {
77 public:
78  void SetUp() override;
79  void TearDown() override;
80  std::shared_ptr<WalletPool> newDefaultPool(std::string poolName = "my_ppol");
81  void createWallet(const std::shared_ptr<WalletPool>& pool,
82  const std::string& walletName,
83  const std::string& currencyName,
84  const std::shared_ptr<api::DynamicObject> &configuration);
85 
86  void createAccount(const std::shared_ptr<WalletPool>& pool, const std::string& walletName, int32_t index);
87  BitcoinLikeWalletDatabase newBitcoinAccount(const std::shared_ptr<WalletPool>& pool,
88  const std::string& walletName,
89  const std::string& currencyName,
90  const std::shared_ptr<api::DynamicObject> &configuration,
91  int32_t index,
92  const std::string& xpub);
93  std::shared_ptr<BitcoinLikeAccount> createBitcoinLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
94  int32_t index,
95  const api::AccountCreationInfo &info
96  );
97  std::shared_ptr<BitcoinLikeAccount> createBitcoinLikeAccount(const std::shared_ptr<AbstractWallet>& wallet,
98  int32_t index,
100  );
101 
102  std::shared_ptr<QtThreadDispatcher> dispatcher;
103  std::shared_ptr<NativePathResolver> resolver;
104  std::shared_ptr<DatabaseBackend> backend;
105  std::shared_ptr<CoutLogPrinter> printer;
106  std::shared_ptr<QtHttpClient> http;
107 };
108 
109 #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