Skip to content

Commit 306aab5

Browse files
committed
test,gui: decouple widgets and model into a MiniGui struct
So it can be reused across tests.
1 parent 2f76ac0 commit 306aab5

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/qt/test/wallettests.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChai
206206
return wallet;
207207
}
208208

209+
struct MiniGUI {
210+
public:
211+
SendCoinsDialog sendCoinsDialog;
212+
TransactionView transactionView;
213+
OptionsModel optionsModel;
214+
std::unique_ptr<ClientModel> clientModel;
215+
std::unique_ptr<WalletModel> walletModel;
216+
217+
MiniGUI(interfaces::Node& node, const PlatformStyle* platformStyle) : sendCoinsDialog(platformStyle), transactionView(platformStyle), optionsModel(node) {
218+
bilingual_str error;
219+
QVERIFY(optionsModel.Init(error));
220+
clientModel = std::make_unique<ClientModel>(node, &optionsModel);
221+
}
222+
223+
void initModelForWallet(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet, const PlatformStyle* platformStyle)
224+
{
225+
WalletContext& context = *node.walletLoader().context();
226+
AddWallet(context, wallet);
227+
walletModel = std::make_unique<WalletModel>(interfaces::MakeWallet(context, wallet), *clientModel, platformStyle);
228+
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
229+
sendCoinsDialog.setModel(walletModel.get());
230+
transactionView.setModel(walletModel.get());
231+
}
232+
233+
};
234+
209235
//! Simple qt wallet tests.
210236
//
211237
// Test widgets can be debugged interactively calling show() on them and
@@ -223,18 +249,11 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
223249
{
224250
// Create widgets for sending coins and listing transactions.
225251
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
226-
SendCoinsDialog sendCoinsDialog(platformStyle.get());
227-
TransactionView transactionView(platformStyle.get());
228-
OptionsModel optionsModel(node);
229-
bilingual_str error;
230-
QVERIFY(optionsModel.Init(error));
231-
ClientModel clientModel(node, &optionsModel);
232-
WalletContext& context = *node.walletLoader().context();
233-
AddWallet(context, wallet);
234-
WalletModel walletModel(interfaces::MakeWallet(context, wallet), clientModel, platformStyle.get());
235-
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
236-
sendCoinsDialog.setModel(&walletModel);
237-
transactionView.setModel(&walletModel);
252+
MiniGUI mini_gui(node, platformStyle.get());
253+
mini_gui.initModelForWallet(node, wallet, platformStyle.get());
254+
WalletModel& walletModel = *mini_gui.walletModel;
255+
SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
256+
TransactionView& transactionView = mini_gui.transactionView;
238257

239258
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
240259
walletModel.pollBalanceChanged();

0 commit comments

Comments
 (0)