Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show All 23 Lines | |||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <future> | #include <future> | ||||
#include <memory> | #include <memory> | ||||
#include <vector> | #include <vector> | ||||
extern RecursiveMutex cs_wallets; | |||||
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | ||||
static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain &chain) { | static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain &chain) { | ||||
DatabaseOptions options; | DatabaseOptions options; | ||||
DatabaseStatus status; | DatabaseStatus status; | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
auto database = MakeWalletDatabase("", options, status, error); | auto database = MakeWalletDatabase("", options, status, error); | ||||
▲ Show 20 Lines • Show All 785 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup) { | ||||
// paying to the wallet as the wallet finishes loading and syncing the | // paying to the wallet as the wallet finishes loading and syncing the | ||||
// queue so the events have to be handled immediately. Releasing the wallet | // queue so the events have to be handled immediately. Releasing the wallet | ||||
// lock during the sync is a little artificial but is needed to avoid a | // lock during the sync is a little artificial but is needed to avoid a | ||||
// deadlock during the sync and simulates a new block notification happening | // deadlock during the sync and simulates a new block notification happening | ||||
// as soon as possible. | // as soon as possible. | ||||
addtx_count = 0; | addtx_count = 0; | ||||
auto handler = HandleLoadWallet( | auto handler = HandleLoadWallet( | ||||
[&](std::unique_ptr<interfaces::Wallet> wallet_param) | [&](std::unique_ptr<interfaces::Wallet> wallet_param) | ||||
EXCLUSIVE_LOCKS_REQUIRED(wallet_param->wallet()->cs_wallet) { | EXCLUSIVE_LOCKS_REQUIRED(wallet_param->wallet()->cs_wallet, | ||||
cs_wallets) { | |||||
BOOST_CHECK(rescan_completed); | BOOST_CHECK(rescan_completed); | ||||
m_coinbase_txns.push_back( | m_coinbase_txns.push_back( | ||||
CreateAndProcessBlock( | CreateAndProcessBlock( | ||||
{}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | {}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | ||||
.vtx[0]); | .vtx[0]); | ||||
block_tx = | block_tx = | ||||
TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey, | TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey, | ||||
GetScriptForRawPubKey(key.GetPubKey())); | GetScriptForRawPubKey(key.GetPubKey())); | ||||
m_coinbase_txns.push_back( | m_coinbase_txns.push_back( | ||||
CreateAndProcessBlock( | CreateAndProcessBlock( | ||||
{block_tx}, | {block_tx}, | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | ||||
.vtx[0]); | .vtx[0]); | ||||
mempool_tx = | mempool_tx = | ||||
TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey, | TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey, | ||||
GetScriptForRawPubKey(key.GetPubKey())); | GetScriptForRawPubKey(key.GetPubKey())); | ||||
BOOST_CHECK(chain->broadcastTransaction( | BOOST_CHECK(chain->broadcastTransaction( | ||||
GetConfig(), MakeTransactionRef(mempool_tx), | GetConfig(), MakeTransactionRef(mempool_tx), | ||||
DEFAULT_TRANSACTION_MAXFEE, false, error)); | DEFAULT_TRANSACTION_MAXFEE, false, error)); | ||||
LEAVE_CRITICAL_SECTION(cs_wallets); | |||||
LEAVE_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet); | LEAVE_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet); | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
ENTER_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet); | ENTER_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet); | ||||
ENTER_CRITICAL_SECTION(cs_wallets); | |||||
}); | }); | ||||
wallet = TestLoadWallet(*chain); | wallet = TestLoadWallet(*chain); | ||||
BOOST_CHECK_EQUAL(addtx_count, 4); | BOOST_CHECK_EQUAL(addtx_count, 4); | ||||
{ | { | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U); | BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U); | ||||
BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U); | BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |