Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | public: | ||||
std::unique_ptr<CWallet> wallet; | std::unique_ptr<CWallet> wallet; | ||||
}; | }; | ||||
BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) { | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) { | ||||
std::string coinbaseAddress = coinbaseKey.GetPubKey().GetID().ToString(); | std::string coinbaseAddress = coinbaseKey.GetPubKey().GetID().ToString(); | ||||
// Confirm ListCoins initially returns 1 coin grouped under coinbaseKey | // Confirm ListCoins initially returns 1 coin grouped under coinbaseKey | ||||
// address. | // address. | ||||
auto list = wallet->ListCoins(); | std::map<CTxDestination, std::vector<COutput>> list; | ||||
{ | |||||
LOCK2(cs_main, wallet->cs_wallet); | |||||
list = wallet->ListCoins(); | |||||
} | |||||
BOOST_CHECK_EQUAL(list.size(), 1U); | BOOST_CHECK_EQUAL(list.size(), 1U); | ||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | ||||
coinbaseAddress); | coinbaseAddress); | ||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U); | BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U); | ||||
// Check initial balance from one mature coinbase transaction. | // Check initial balance from one mature coinbase transaction. | ||||
BOOST_CHECK_EQUAL(50 * COIN, wallet->GetAvailableBalance()); | BOOST_CHECK_EQUAL(50 * COIN, wallet->GetAvailableBalance()); | ||||
// Add a transaction creating a change address, and confirm ListCoins still | // Add a transaction creating a change address, and confirm ListCoins still | ||||
// returns the coin associated with the change address underneath the | // returns the coin associated with the change address underneath the | ||||
// coinbaseKey pubkey, even though the change address has a different | // coinbaseKey pubkey, even though the change address has a different | ||||
// pubkey. | // pubkey. | ||||
AddTx(CRecipient{GetScriptForRawPubKey({}), 1 * COIN, | AddTx(CRecipient{GetScriptForRawPubKey({}), 1 * COIN, | ||||
false /* subtract fee */}); | false /* subtract fee */}); | ||||
{ | |||||
LOCK2(cs_main, wallet->cs_wallet); | |||||
list = wallet->ListCoins(); | list = wallet->ListCoins(); | ||||
} | |||||
BOOST_CHECK_EQUAL(list.size(), 1U); | BOOST_CHECK_EQUAL(list.size(), 1U); | ||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | ||||
coinbaseAddress); | coinbaseAddress); | ||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | ||||
// Lock both coins. Confirm number of available coins drops to 0. | // Lock both coins. Confirm number of available coins drops to 0. | ||||
{ | { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
Show All 10 Lines | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) { | ||||
{ | { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
std::vector<COutput> available; | std::vector<COutput> available; | ||||
wallet->AvailableCoins(available); | wallet->AvailableCoins(available); | ||||
BOOST_CHECK_EQUAL(available.size(), 0U); | BOOST_CHECK_EQUAL(available.size(), 0U); | ||||
} | } | ||||
// Confirm ListCoins still returns same result as before, despite coins | // Confirm ListCoins still returns same result as before, despite coins | ||||
// being locked. | // being locked. | ||||
{ | |||||
LOCK2(cs_main, wallet->cs_wallet); | |||||
list = wallet->ListCoins(); | list = wallet->ListCoins(); | ||||
} | |||||
BOOST_CHECK_EQUAL(list.size(), 1U); | BOOST_CHECK_EQUAL(list.size(), 1U); | ||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), | ||||
coinbaseAddress); | coinbaseAddress); | ||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |