ledger-core
transaction_test_helper.h
1 /*
2  *
3  * transaction_test_helper
4  * ledger-core
5  *
6  * Created by El Khalil Bellakrid on 16/05/2018.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2018 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_TRANSACTION_TEST_HELPER_H
33 #define LEDGER_CORE_TRANSACTION_TEST_HELPER_H
34 
35 #include <string>
36 #include <api/DynamicObject.hpp>
37 #include <wallet/bitcoin/BitcoinLikeWallet.hpp>
38 #include <wallet/bitcoin/BitcoinLikeAccount.hpp>
39 #include <wallet/bitcoin/transaction_builders/BitcoinLikeTransactionBuilder.h>
40 #include <wallet/ethereum/EthereumLikeWallet.h>
41 #include <wallet/ethereum/EthereumLikeAccount.h>
42 #include <wallet/ethereum/transaction_builders/EthereumLikeTransactionBuilder.h>
43 #include <wallet/ripple/RippleLikeWallet.h>
44 #include <wallet/ripple/RippleLikeAccount.h>
45 #include <wallet/ripple/transaction_builders/RippleLikeTransactionBuilder.h>
46 #include <wallet/tezos/TezosLikeWallet.h>
47 #include <wallet/tezos/TezosLikeAccount.h>
48 #include <wallet/tezos/transaction_builders/TezosLikeTransactionBuilder.h>
49 #include "../BaseFixture.h"
50 
51 
52 using namespace ledger::core;
53 
55  std::shared_ptr<api::DynamicObject> configuration;
56  std::string walletName;
57  std::string currencyName;
58  std::function<std::shared_ptr<BitcoinLikeAccount> (const std::shared_ptr<WalletPool>&,
59  const std::shared_ptr<AbstractWallet>& )> inflate_btc;
60  std::function<std::shared_ptr<EthereumLikeAccount> (const std::shared_ptr<WalletPool>&,
61  const std::shared_ptr<AbstractWallet>& )> inflate_eth;
62 
63  std::function<std::shared_ptr<RippleLikeAccount> (const std::shared_ptr<WalletPool>&,
64  const std::shared_ptr<AbstractWallet>& )> inflate_xrp;
65 
66  std::function<std::shared_ptr<TezosLikeAccount> (const std::shared_ptr<WalletPool>&,
67  const std::shared_ptr<AbstractWallet>& )> inflate_xtz;
68 };
69 
71 
72  void SetUp() override {
73  BaseFixture::SetUp();
74  SetUpConfig();
75  recreate();
76  }
77 
78  void recreate() {
79  pool = newDefaultPool();
80  wallet = wait(pool->createWallet(testData.walletName, testData.currencyName, testData.configuration));
81  account = testData.inflate_btc(pool, wallet);
82  currency = wallet->getCurrency();
83  }
84 
85  void TearDown() override {
86  BaseFixture::TearDown();
87  pool = nullptr;
88  wallet = nullptr;
89  account = nullptr;
90  }
91 
92  std::shared_ptr<BitcoinLikeTransactionBuilder> tx_builder() {
93  return std::dynamic_pointer_cast<BitcoinLikeTransactionBuilder>(account->buildTransaction(false));
94  }
95  std::shared_ptr<WalletPool> pool;
96  std::shared_ptr<AbstractWallet> wallet;
97  std::shared_ptr<BitcoinLikeAccount> account;
98  api::Currency currency;
99  TransactionTestData testData;
100 
101 protected:
102  virtual void SetUpConfig() = 0;
103 };
104 
106 
107  void SetUp() override {
108  BaseFixture::SetUp();
109  SetUpConfig();
110  recreate();
111  }
112 
113  void recreate() {
114  pool = newDefaultPool();
115  wallet = wait(pool->createWallet(testData.walletName, testData.currencyName, testData.configuration));
116  account = testData.inflate_eth(pool, wallet);
117  currency = wallet->getCurrency();
118  }
119 
120  void TearDown() override {
121  BaseFixture::TearDown();
122  pool = nullptr;
123  wallet = nullptr;
124  account = nullptr;
125  }
126 
127  std::shared_ptr<EthereumLikeTransactionBuilder> tx_builder() {
128  return std::dynamic_pointer_cast<EthereumLikeTransactionBuilder>(account->buildTransaction());
129  }
130  std::shared_ptr<WalletPool> pool;
131  std::shared_ptr<AbstractWallet> wallet;
132  std::shared_ptr<EthereumLikeAccount> account;
133  api::Currency currency;
134  TransactionTestData testData;
135 
136 protected:
137  virtual void SetUpConfig() = 0;
138 };
139 
141 
142  void SetUp() override {
143  BaseFixture::SetUp();
144  SetUpConfig();
145  recreate();
146  }
147 
148  void recreate() {
149  pool = newDefaultPool();
150  wallet = wait(pool->createWallet(testData.walletName, testData.currencyName, testData.configuration));
151  account = testData.inflate_xrp(pool, wallet);
152  currency = wallet->getCurrency();
153  }
154 
155  void TearDown() override {
156  BaseFixture::TearDown();
157  pool = nullptr;
158  wallet = nullptr;
159  account = nullptr;
160  }
161 
162  std::shared_ptr<RippleLikeTransactionBuilder> tx_builder() {
163  return std::dynamic_pointer_cast<RippleLikeTransactionBuilder>(account->buildTransaction());
164  }
165  std::shared_ptr<WalletPool> pool;
166  std::shared_ptr<AbstractWallet> wallet;
167  std::shared_ptr<RippleLikeAccount> account;
168  api::Currency currency;
169  TransactionTestData testData;
170 
171 protected:
172  virtual void SetUpConfig() = 0;
173 };
174 
176 
177  void SetUp() override {
178  BaseFixture::SetUp();
179  SetUpConfig();
180  recreate();
181  }
182 
183  void recreate() {
184  pool = newDefaultPool();
185  wallet = wait(pool->createWallet(testData.walletName, testData.currencyName, testData.configuration));
186  account = testData.inflate_xtz(pool, wallet);
187  currency = wallet->getCurrency();
188  }
189 
190  void TearDown() override {
191  BaseFixture::TearDown();
192  pool = nullptr;
193  wallet = nullptr;
194  account = nullptr;
195  }
196 
197  std::shared_ptr<TezosLikeTransactionBuilder> tx_builder() {
198  return std::dynamic_pointer_cast<TezosLikeTransactionBuilder>(account->buildTransaction());
199  }
200  std::shared_ptr<WalletPool> pool;
201  std::shared_ptr<AbstractWallet> wallet;
202  std::shared_ptr<TezosLikeAccount> account;
203  api::Currency currency;
204  TransactionTestData testData;
205 
206 protected:
207  virtual void SetUpConfig() = 0;
208 };
209 
210 
211 
212 #endif //LEDGER_CORE_TRANSACTION_TEST_HELPER_H
Definition: Account.cpp:8
Definition: BitcoinLikeTransactionBuilder.h:66
Definition: transaction_test_helper.h:105
Definition: transaction_test_helper.h:140
Definition: RippleLikeTransactionBuilder.h:67
Definition: transaction_test_helper.h:54
Definition: Currency.hpp:23
Definition: TezosLikeTransactionBuilder.h:69
Definition: transaction_test_helper.h:175
Definition: BaseFixture.h:76
Definition: transaction_test_helper.h:70
Definition: EthereumLikeTransactionBuilder.h:67