Changeset View
Changeset View
Standalone View
Standalone View
src/qt/test/addressbooktests.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
* - existing_r_address: an existing receiving address which won't add | * - existing_r_address: an existing receiving address which won't add | ||||
* successfully. | * successfully. | ||||
* | * | ||||
* In each case, verify the resulting state of the address book and optionally | * In each case, verify the resulting state of the address book and optionally | ||||
* the warning message presented to the user. | * the warning message presented to the user. | ||||
*/ | */ | ||||
void TestAddAddressesToSendBook() { | void TestAddAddressesToSendBook() { | ||||
TestChain100Setup test; | TestChain100Setup test; | ||||
CWallet wallet(Params(), "mock", WalletDatabase::CreateMock()); | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
Params(), "mock", WalletDatabase::CreateMock()); | |||||
bool firstRun; | bool firstRun; | ||||
wallet.LoadWallet(firstRun); | wallet->LoadWallet(firstRun); | ||||
auto build_address = [&wallet]() { | auto build_address = [&wallet]() { | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
CTxDestination dest(GetDestinationForKey( | CTxDestination dest(GetDestinationForKey( | ||||
key.GetPubKey(), wallet.m_default_address_type)); | key.GetPubKey(), wallet->m_default_address_type)); | ||||
return std::make_pair( | return std::make_pair( | ||||
dest, QString::fromStdString(EncodeCashAddr(dest, Params()))); | dest, QString::fromStdString(EncodeCashAddr(dest, Params()))); | ||||
}; | }; | ||||
CTxDestination r_key_dest, s_key_dest; | CTxDestination r_key_dest, s_key_dest; | ||||
// Add a preexisting "receive" entry in the address book. | // Add a preexisting "receive" entry in the address book. | ||||
QString preexisting_r_address; | QString preexisting_r_address; | ||||
QString r_label("already here (r)"); | QString r_label("already here (r)"); | ||||
// Add a preexisting "send" entry in the address book. | // Add a preexisting "send" entry in the address book. | ||||
QString preexisting_s_address; | QString preexisting_s_address; | ||||
QString s_label("already here (s)"); | QString s_label("already here (s)"); | ||||
// Define a new address (which should add to the address book successfully). | // Define a new address (which should add to the address book successfully). | ||||
QString new_address; | QString new_address; | ||||
std::tie(r_key_dest, preexisting_r_address) = build_address(); | std::tie(r_key_dest, preexisting_r_address) = build_address(); | ||||
std::tie(s_key_dest, preexisting_s_address) = build_address(); | std::tie(s_key_dest, preexisting_s_address) = build_address(); | ||||
std::tie(std::ignore, new_address) = build_address(); | std::tie(std::ignore, new_address) = build_address(); | ||||
{ | { | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet.SetAddressBook(r_key_dest, r_label.toStdString(), "receive"); | wallet->SetAddressBook(r_key_dest, r_label.toStdString(), "receive"); | ||||
wallet.SetAddressBook(s_key_dest, s_label.toStdString(), "send"); | wallet->SetAddressBook(s_key_dest, s_label.toStdString(), "send"); | ||||
} | } | ||||
auto check_addbook_size = [&wallet](int expected_size) { | auto check_addbook_size = [&wallet](int expected_size) { | ||||
QCOMPARE(static_cast<int>(wallet.mapAddressBook.size()), expected_size); | QCOMPARE(static_cast<int>(wallet->mapAddressBook.size()), | ||||
expected_size); | |||||
}; | }; | ||||
// We should start with the two addresses we added earlier and nothing else. | // We should start with the two addresses we added earlier and nothing else. | ||||
check_addbook_size(2); | check_addbook_size(2); | ||||
// Initialize relevant QT models. | // Initialize relevant QT models. | ||||
std::unique_ptr<const PlatformStyle> platformStyle( | std::unique_ptr<const PlatformStyle> platformStyle( | ||||
PlatformStyle::instantiate("other")); | PlatformStyle::instantiate("other")); | ||||
auto node = interfaces::MakeNode(); | auto node = interfaces::MakeNode(); | ||||
OptionsModel optionsModel(*node); | OptionsModel optionsModel(*node); | ||||
AddWallet(&wallet); | AddWallet(wallet); | ||||
WalletModel walletModel(std::move(node->getWallets()[0]), *node, | WalletModel walletModel(std::move(node->getWallets()[0]), *node, | ||||
platformStyle.get(), &optionsModel); | platformStyle.get(), &optionsModel); | ||||
RemoveWallet(&wallet); | RemoveWallet(wallet); | ||||
EditAddressDialog editAddressDialog(EditAddressDialog::NewSendingAddress); | EditAddressDialog editAddressDialog(EditAddressDialog::NewSendingAddress); | ||||
editAddressDialog.setModel(walletModel.getAddressTableModel()); | editAddressDialog.setModel(walletModel.getAddressTableModel()); | ||||
EditAddressAndSubmit( | EditAddressAndSubmit( | ||||
&editAddressDialog, QString("uhoh"), preexisting_r_address, | &editAddressDialog, QString("uhoh"), preexisting_r_address, | ||||
QString( | QString( | ||||
"Address \"%1\" already exists as a receiving address with label " | "Address \"%1\" already exists as a receiving address with label " | ||||
"\"%2\" and so cannot be added as a sending address.") | "\"%2\" and so cannot be added as a sending address.") | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |