Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
// Copyright (c) 2012-2019 The Bitcoin Core developers | // Copyright (c) 2012-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <util/ref.h> | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/rpcdump.h> | #include <wallet/rpcdump.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <wallet/test/wallet_test_fixture.h> | #include <wallet/test/wallet_test_fixture.h> | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | // after. | ||||
CKey futureKey; | CKey futureKey; | ||||
futureKey.MakeNewKey(true); | futureKey.MakeNewKey(true); | ||||
key.pushKV("scriptPubKey", | key.pushKV("scriptPubKey", | ||||
HexStr(GetScriptForRawPubKey(futureKey.GetPubKey()))); | HexStr(GetScriptForRawPubKey(futureKey.GetPubKey()))); | ||||
key.pushKV("timestamp", | key.pushKV("timestamp", | ||||
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); | ||||
JSONRPCRequest request; | util::Ref 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(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. " | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | // Import key into wallet and call dumpwallet to create backup file. | ||||
.nCreateTime = KEY_TIME; | .nCreateTime = KEY_TIME; | ||||
spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->SetLastBlockProcessed( | wallet->SetLastBlockProcessed( | ||||
::ChainActive().Height(), | ::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
} | } | ||||
JSONRPCRequest request; | util::Ref 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(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()); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | wallet->SetupLegacyScriptPubKeyMan(); | ||||
JSONRPCRequest request; | util::Ref 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(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet); | ||||
▲ Show 20 Lines • Show All 352 Lines • Show Last 20 Lines |