Changeset View
Changeset View
Standalone View
Standalone View
src/qt/test/wallettests.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
// src/qt/test/test_bitcoin-qt -platform cocoa # macOS | // src/qt/test/test_bitcoin-qt -platform cocoa # macOS | ||||
void TestGUI() { | void TestGUI() { | ||||
// Set up wallet and chain with 105 blocks (5 mature blocks for spending). | // Set up wallet and chain with 105 blocks (5 mature blocks for spending). | ||||
TestChain100Setup test; | TestChain100Setup test; | ||||
for (int i = 0; i < 5; ++i) { | for (int i = 0; i < 5; ++i) { | ||||
test.CreateAndProcessBlock( | test.CreateAndProcessBlock( | ||||
{}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey())); | {}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey())); | ||||
} | } | ||||
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); | ||||
{ | { | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet.SetAddressBook( | wallet->SetAddressBook( | ||||
GetDestinationForKey(test.coinbaseKey.GetPubKey(), | GetDestinationForKey(test.coinbaseKey.GetPubKey(), | ||||
wallet.m_default_address_type), | wallet->m_default_address_type), | ||||
"", "receive"); | "", "receive"); | ||||
wallet.AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey()); | wallet->AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey()); | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
WalletRescanReserver reserver(&wallet); | WalletRescanReserver reserver(wallet.get()); | ||||
reserver.reserve(); | reserver.reserve(); | ||||
wallet.ScanForWalletTransactions(chainActive.Genesis(), nullptr, | wallet->ScanForWalletTransactions(chainActive.Genesis(), nullptr, | ||||
reserver, true); | reserver, true); | ||||
} | } | ||||
wallet.SetBroadcastTransactions(true); | wallet->SetBroadcastTransactions(true); | ||||
// Create widgets for sending coins and listing transactions. | // Create widgets for sending coins and listing transactions. | ||||
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().back()), *node, | WalletModel walletModel(std::move(node->getWallets().back()), *node, | ||||
platformStyle.get(), &optionsModel); | platformStyle.get(), &optionsModel); | ||||
RemoveWallet(&wallet); | RemoveWallet(wallet); | ||||
// Send two transactions, and verify they are added to transaction list. | // Send two transactions, and verify they are added to transaction list. | ||||
SendCoinsDialog sendCoinsDialog(platformStyle.get(), &walletModel); | SendCoinsDialog sendCoinsDialog(platformStyle.get(), &walletModel); | ||||
TransactionTableModel *transactionTableModel = | TransactionTableModel *transactionTableModel = | ||||
walletModel.getTransactionTableModel(); | walletModel.getTransactionTableModel(); | ||||
QCOMPARE(transactionTableModel->rowCount({}), 105); | QCOMPARE(transactionTableModel->rowCount({}), 105); | ||||
uint256 txid1 = | uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, | ||||
SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 5 * COIN); | CTxDestination(CKeyID()), 5 * COIN); | ||||
uint256 txid2 = | uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, | ||||
SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 10 * COIN); | CTxDestination(CKeyID()), 10 * COIN); | ||||
QCOMPARE(transactionTableModel->rowCount({}), 107); | QCOMPARE(transactionTableModel->rowCount({}), 107); | ||||
QVERIFY(FindTx(*transactionTableModel, txid1).isValid()); | QVERIFY(FindTx(*transactionTableModel, txid1).isValid()); | ||||
QVERIFY(FindTx(*transactionTableModel, txid2).isValid()); | QVERIFY(FindTx(*transactionTableModel, txid2).isValid()); | ||||
// Check current balance on OverviewPage | // Check current balance on OverviewPage | ||||
OverviewPage overviewPage(platformStyle.get()); | OverviewPage overviewPage(platformStyle.get()); | ||||
overviewPage.setWalletModel(&walletModel); | overviewPage.setWalletModel(&walletModel); | ||||
QLabel *balanceLabel = overviewPage.findChild<QLabel *>("labelBalance"); | QLabel *balanceLabel = overviewPage.findChild<QLabel *>("labelBalance"); | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |