MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestAddAddressesToSendBook

Function TestAddAddressesToSendBook

src/qt/test/addressbooktests.cpp:73–209  ·  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

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

Callers 1

addressBookTestsMethod · 0.85

Calls 15

GenerateRandomKeyFunction · 0.85
EncodeDestinationFunction · 0.85
AddWalletFunction · 0.85
RemoveWalletFunction · 0.85
EditAddressAndSubmitFunction · 0.85
SetWalletFlagMethod · 0.80
SetAddressBookMethod · 0.80
getAddressTableModelMethod · 0.80
setTextMethod · 0.80
MakeWalletLoaderFunction · 0.50

Tested by

no test coverage detected