Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | // after. | ||||
newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1); | newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1); | ||||
key.pushKV("internal", UniValue(true)); | key.pushKV("internal", UniValue(true)); | ||||
keys.push_back(key); | keys.push_back(key); | ||||
util::Ref context; | util::Ref context; | ||||
JSONRPCRequest request(context); | JSONRPCRequest request(context); | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(keys); | request.params.push_back(keys); | ||||
UniValue response = importmulti(GetConfig(), request); | UniValue response = importmulti().HandleRequest(GetConfig(), request); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
response.write(), | response.write(), | ||||
strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":" | strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":" | ||||
"\"Rescan failed for key with creation timestamp %d. " | "\"Rescan failed for key with creation timestamp %d. " | ||||
"There was an error reading a block from time %d, which " | "There was an error reading a block from time %d, which " | ||||
"is after or within %d seconds of key creation, and " | "is after or within %d seconds of key creation, and " | ||||
"could contain transactions pertaining to the key. As a " | "could contain transactions pertaining to the key. As a " | ||||
"result, transactions and coins using this key may not " | "result, transactions and coins using this key may not " | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | // Import key into wallet and call dumpwallet to create backup file. | ||||
wallet->SetLastBlockProcessed( | wallet->SetLastBlockProcessed( | ||||
::ChainActive().Height(), | ::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
} | } | ||||
util::Ref context; | util::Ref context; | ||||
JSONRPCRequest request(context); | JSONRPCRequest request(context); | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
::dumpwallet(GetConfig(), request); | ::dumpwallet().HandleRequest(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::make_shared<CWallet>( | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
chain.get(), WalletLocation(), CreateDummyWalletDatabase()); | chain.get(), WalletLocation(), CreateDummyWalletDatabase()); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | wallet->SetupLegacyScriptPubKeyMan(); | ||||
util::Ref context; | util::Ref context; | ||||
JSONRPCRequest request(context); | JSONRPCRequest request(context); | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->SetLastBlockProcessed(::ChainActive().Height(), | wallet->SetLastBlockProcessed(::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
::importwallet(GetConfig(), request); | ::importwallet().HandleRequest(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet); | ||||
BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U); | BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U); | ||||
BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); | BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); | ||||
for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { | for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { | ||||
bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetId()); | bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetId()); | ||||
bool expected = i >= 100; | bool expected = i >= 100; | ||||
BOOST_CHECK_EQUAL(found, expected); | BOOST_CHECK_EQUAL(found, expected); | ||||
▲ Show 20 Lines • Show All 567 Lines • Show Last 20 Lines |