MCPcopy Create free account
hub / github.com/ElementsProject/elements / TestAddAddressesToSendBook

Function TestAddAddressesToSendBook

src/qt/test/addressbooktests.cpp:69–158  ·  view source on GitHub ↗

* Test adding various send addresses to the address book. * * There are three cases tested: * * - new_address: a new address which should add as a send address successfully. * - existing_s_address: an existing sending address which won't add successfully. * - existing_r_address: an existing receiving address which won't add successfully. * * In each case, verify the resulting state o

Source from the content-addressed store, hash-verified

67 * the warning message presented to the user.
68 */
69void TestAddAddressesToSendBook(interfaces::Node& node)
70{
71 TestChain100Setup test;
72 auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
73 test.m_node.wallet_loader = wallet_loader.get();
74 node.setContext(&test.m_node);
75 const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", gArgs, CreateMockWalletDatabase());
76 wallet->LoadWallet();
77 wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
78 {
79 LOCK(wallet->cs_wallet);
80 wallet->SetupDescriptorScriptPubKeyMans();
81 }
82
83 auto build_address = [&wallet]() {
84 CKey key;
85 key.MakeNewKey(true);
86 CTxDestination dest(GetDestinationForKey(
87 key.GetPubKey(), wallet->m_default_address_type));
88
89 return std::make_pair(dest, QString::fromStdString(EncodeDestination(dest)));
90 };
91
92 CTxDestination r_key_dest, s_key_dest;
93
94 // Add a preexisting "receive" entry in the address book.
95 QString preexisting_r_address;
96 QString r_label("already here (r)");
97
98 // Add a preexisting "send" entry in the address book.
99 QString preexisting_s_address;
100 QString s_label("already here (s)");
101
102 // Define a new address (which should add to the address book successfully).
103 QString new_address;
104
105 std::tie(r_key_dest, preexisting_r_address) = build_address();
106 std::tie(s_key_dest, preexisting_s_address) = build_address();
107 std::tie(std::ignore, new_address) = build_address();
108
109 {
110 LOCK(wallet->cs_wallet);
111 wallet->SetAddressBook(r_key_dest, r_label.toStdString(), "receive");
112 wallet->SetAddressBook(s_key_dest, s_label.toStdString(), "send");
113 }
114
115 auto check_addbook_size = [&wallet](int expected_size) {
116 LOCK(wallet->cs_wallet);
117 QCOMPARE(static_cast<int>(wallet->m_address_book.size()), expected_size);
118 };
119
120 // We should start with the two addresses we added earlier and nothing else.
121 check_addbook_size(2);
122
123 // Initialize relevant QT models.
124 std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
125 OptionsModel optionsModel;
126 ClientModel clientModel(node, &optionsModel);

Callers 1

addressBookTestsMethod · 0.85

Calls 15

CreateMockWalletDatabaseFunction · 0.85
GetDestinationForKeyFunction · 0.85
EncodeDestinationFunction · 0.85
AddWalletFunction · 0.85
RemoveWalletFunction · 0.85
EditAddressAndSubmitFunction · 0.85
SetWalletFlagMethod · 0.80
MakeNewKeyMethod · 0.80
SetAddressBookMethod · 0.80
getAddressTableModelMethod · 0.80
MakeWalletLoaderFunction · 0.50

Tested by

no test coverage detected