Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show All 35 Lines | |||||
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) { | ||||
// Cap last block file size, and mine new block in a new block file. | // Cap last block file size, and mine new block in a new block file. | ||||
CBlockIndex *oldTip = ::ChainActive().Tip(); | CBlockIndex *oldTip = ::ChainActive().Tip(); | ||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | ||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
CBlockIndex *newTip = ::ChainActive().Tip(); | CBlockIndex *newTip = ::ChainActive().Tip(); | ||||
NodeContext node; | NodeContext node; | ||||
auto chain = interfaces::MakeChain(node); | auto chain = interfaces::MakeChain(node, Params()); | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
// Verify ScanForWalletTransactions accommodates a null start block. | // Verify ScanForWalletTransactions accommodates a null start block. | ||||
{ | { | ||||
CWallet wallet(Params(), chain.get(), WalletLocation(), | CWallet wallet(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) { | ||||
// Cap last block file size, and mine new block in a new block file. | // Cap last block file size, and mine new block in a new block file. | ||||
CBlockIndex *oldTip = ::ChainActive().Tip(); | CBlockIndex *oldTip = ::ChainActive().Tip(); | ||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | ||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
CBlockIndex *newTip = ::ChainActive().Tip(); | CBlockIndex *newTip = ::ChainActive().Tip(); | ||||
NodeContext node; | NodeContext node; | ||||
auto chain = interfaces::MakeChain(node); | auto chain = interfaces::MakeChain(node, Params()); | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
// Prune the older block file. | // Prune the older block file. | ||||
PruneOneBlockFile(oldTip->GetBlockPos().nFile); | PruneOneBlockFile(oldTip->GetBlockPos().nFile); | ||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); | UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); | ||||
// Verify importmulti RPC returns failure for a key whose creation time is | // Verify importmulti RPC returns failure for a key whose creation time is | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { | ||||
const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW; | const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW; | ||||
SetMockTime(KEY_TIME); | SetMockTime(KEY_TIME); | ||||
m_coinbase_txns.emplace_back( | m_coinbase_txns.emplace_back( | ||||
CreateAndProcessBlock({}, | CreateAndProcessBlock({}, | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | GetScriptForRawPubKey(coinbaseKey.GetPubKey())) | ||||
.vtx[0]); | .vtx[0]); | ||||
NodeContext node; | NodeContext node; | ||||
auto chain = interfaces::MakeChain(node); | auto chain = interfaces::MakeChain(node, Params()); | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
std::string backup_file = (GetDataDir() / "wallet.backup").string(); | std::string backup_file = (GetDataDir() / "wallet.backup").string(); | ||||
// Import key into wallet and call dumpwallet to create backup file. | // Import key into wallet and call dumpwallet to create backup file. | ||||
{ | { | ||||
std::shared_ptr<CWallet> wallet = | std::shared_ptr<CWallet> wallet = | ||||
Show All 40 Lines | |||||
// Check that GetImmatureCredit() returns a newly calculated value instead of | // Check that GetImmatureCredit() returns a newly calculated value instead of | ||||
// the cached value after a MarkDirty() call. | // the cached value after a MarkDirty() call. | ||||
// | // | ||||
// This is a regression test written to verify a bugfix for the immature credit | // This is a regression test written to verify a bugfix for the immature credit | ||||
// function. Similar tests probably should be written for the other credit and | // function. Similar tests probably should be written for the other credit and | ||||
// debit functions. | // debit functions. | ||||
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) { | ||||
NodeContext node; | NodeContext node; | ||||
auto chain = interfaces::MakeChain(node); | auto chain = interfaces::MakeChain(node, Params()); | ||||
CWallet wallet(Params(), chain.get(), WalletLocation(), | CWallet wallet(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
CWalletTx wtx(&wallet, m_coinbase_txns.back()); | CWalletTx wtx(&wallet, m_coinbase_txns.back()); | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | CWalletTx &AddTx(CRecipient recipient) { | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
auto it = wallet->mapWallet.find(tx->GetId()); | auto it = wallet->mapWallet.find(tx->GetId()); | ||||
BOOST_CHECK(it != wallet->mapWallet.end()); | BOOST_CHECK(it != wallet->mapWallet.end()); | ||||
it->second.SetMerkleBranch(::ChainActive().Tip()->GetBlockHash(), 1); | it->second.SetMerkleBranch(::ChainActive().Tip()->GetBlockHash(), 1); | ||||
return it->second; | return it->second; | ||||
} | } | ||||
NodeContext m_node; | NodeContext m_node; | ||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node); | std::unique_ptr<interfaces::Chain> m_chain = | ||||
interfaces::MakeChain(m_node, Params()); | |||||
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. | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) { | ||||
BOOST_CHECK_EQUAL(list.size(), 1U); | BOOST_CHECK_EQUAL(list.size(), 1U); | ||||
BOOST_CHECK_EQUAL(boost::get<PKHash>(list.begin()->first).ToString(), | BOOST_CHECK_EQUAL(boost::get<PKHash>(list.begin()->first).ToString(), | ||||
coinbaseAddress); | coinbaseAddress); | ||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U); | ||||
} | } | ||||
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) { | ||||
NodeContext node; | NodeContext node; | ||||
auto chain = interfaces::MakeChain(node); | auto chain = interfaces::MakeChain(node, Params()); | ||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
Params(), chain.get(), WalletLocation(), WalletDatabase::CreateDummy()); | Params(), chain.get(), WalletLocation(), WalletDatabase::CreateDummy()); | ||||
wallet->SetMinVersion(FEATURE_LATEST); | wallet->SetMinVersion(FEATURE_LATEST); | ||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS); | wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS); | ||||
BOOST_CHECK(!wallet->TopUpKeyPool(1000)); | BOOST_CHECK(!wallet->TopUpKeyPool(1000)); | ||||
CTxDestination dest; | CTxDestination dest; | ||||
std::string error; | std::string error; | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
!wallet->GetNewDestination(OutputType::LEGACY, "", dest, error)); | !wallet->GetNewDestination(OutputType::LEGACY, "", dest, error)); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |