Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show All 23 Lines | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
#include <vector> | #include <vector> | ||||
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) | ||||
static void AddKey(CWallet &wallet, const CKey &key) { | static void AddKey(CWallet &wallet, const CKey &key) { | ||||
auto spk_man = wallet.GetLegacyScriptPubKeyMan(); | auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan(); | ||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore); | LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore); | ||||
spk_man->AddKeyPubKey(key, key.GetPubKey()); | spk_man->AddKeyPubKey(key, key.GetPubKey()); | ||||
} | } | ||||
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; | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) { | ||||
// Verify importmulti RPC returns failure for a key whose creation time is | // Verify importmulti RPC returns failure for a key whose creation time is | ||||
// before the missing block, and success for a key whose creation time is | // before the missing block, and success for a key whose creation time is | ||||
// after. | // after. | ||||
{ | { | ||||
std::shared_ptr<CWallet> wallet = | std::shared_ptr<CWallet> wallet = | ||||
std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | |||||
AddWallet(wallet); | AddWallet(wallet); | ||||
UniValue keys; | UniValue keys; | ||||
keys.setArray(); | keys.setArray(); | ||||
UniValue key; | UniValue key; | ||||
key.setObject(); | key.setObject(); | ||||
key.pushKV("scriptPubKey", | key.pushKV("scriptPubKey", | ||||
HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey()))); | HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey()))); | ||||
key.pushKV("timestamp", 0); | key.pushKV("timestamp", 0); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { | ||||
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 = | ||||
std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
auto spk_man = wallet->GetLegacyScriptPubKeyMan(); | auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan(); | ||||
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); | LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); | ||||
spk_man->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = | spk_man->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = | ||||
KEY_TIME; | KEY_TIME; | ||||
spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | ||||
JSONRPCRequest request; | JSONRPCRequest request; | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
::dumpwallet(GetConfig(), request); | ::dumpwallet(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet); | ||||
} | } | ||||
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME | // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME | ||||
// were scanned, and no prior blocks were scanned. | // were scanned, and no prior blocks were scanned. | ||||
{ | { | ||||
std::shared_ptr<CWallet> wallet = | std::shared_ptr<CWallet> wallet = | ||||
std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | std::make_shared<CWallet>(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | |||||
JSONRPCRequest request; | JSONRPCRequest request; | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
::importwallet(GetConfig(), request); | ::importwallet(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet); | ||||
Show All 14 Lines | |||||
// 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, Params()); | auto chain = interfaces::MakeChain(node, Params()); | ||||
CWallet wallet(Params(), chain.get(), WalletLocation(), | CWallet wallet(Params(), chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
auto spk_man = wallet.GetLegacyScriptPubKeyMan(); | auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan(); | ||||
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); | ||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore); | LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore); | ||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), | wallet.SetLastBlockProcessed(::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | static void PollutePubKey(CPubKey &pubkey) { | ||||
assert(!pubkey.IsFullyValid()); | assert(!pubkey.IsFullyValid()); | ||||
assert(pubkey.IsValid()); | assert(pubkey.IsValid()); | ||||
} | } | ||||
// Test watch-only logic for PubKeys | // Test watch-only logic for PubKeys | ||||
BOOST_AUTO_TEST_CASE(WatchOnlyPubKeys) { | BOOST_AUTO_TEST_CASE(WatchOnlyPubKeys) { | ||||
CKey key; | CKey key; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
LegacyScriptPubKeyMan *spk_man = m_wallet.GetLegacyScriptPubKeyMan(); | LegacyScriptPubKeyMan *spk_man = | ||||
m_wallet.GetOrCreateLegacyScriptPubKeyMan(); | |||||
BOOST_CHECK(!spk_man->HaveWatchOnly()); | BOOST_CHECK(!spk_man->HaveWatchOnly()); | ||||
// uncompressed valid PubKey | // uncompressed valid PubKey | ||||
key.MakeNewKey(false); | key.MakeNewKey(false); | ||||
pubkey = key.GetPubKey(); | pubkey = key.GetPubKey(); | ||||
assert(!pubkey.IsCompressed()); | assert(!pubkey.IsCompressed()); | ||||
TestWatchOnlyPubKey(spk_man, pubkey); | TestWatchOnlyPubKey(spk_man, pubkey); | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup) { | ||||
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, Params()); | 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->SetupLegacyScriptPubKeyMan(); | |||||
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() |