-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzz: add target for
ScriptPubKeyMan
(legacy)
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2022 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <test/fuzz/FuzzedDataProvider.h> | ||
#include <test/fuzz/fuzz.h> | ||
#include <test/fuzz/util.h> | ||
#include <test/util/setup_common.h> | ||
#include <wallet/context.h> | ||
#include <wallet/scriptpubkeyman.h> | ||
#include <wallet/wallet.h> | ||
#include <wallet/test/util.h> | ||
#include <validation.h> | ||
|
||
namespace wallet { | ||
namespace { | ||
const TestingSetup* g_setup; | ||
|
||
void initialize_spkm() | ||
{ | ||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(); | ||
g_setup = testing_setup.get(); | ||
} | ||
|
||
FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) | ||
{ | ||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | ||
const auto& node{g_setup->m_node}; | ||
Chainstate* chainstate = &node.chainman->ActiveChainstate(); | ||
std::unique_ptr<CWallet> wallet{std::make_unique<CWallet>(node.chain.get(), "", CreateMockableWalletDatabase())}; | ||
{ | ||
LOCK(wallet->cs_wallet); | ||
wallet->SetLastBlockProcessed(chainstate->m_chain.Height(), chainstate->m_chain.Tip()->GetBlockHash()); | ||
} | ||
|
||
LegacyScriptPubKeyMan& legacy_spkm{*wallet->GetOrCreateLegacyScriptPubKeyMan()}; | ||
SignatureData data; | ||
CScript watch_script; | ||
|
||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { | ||
CallOneOf( | ||
fuzzed_data_provider, | ||
[&] { | ||
CKey key; | ||
key.MakeNewKey(fuzzed_data_provider.ConsumeBool()); | ||
(void)legacy_spkm.AddKey(key); | ||
}, | ||
[&] { | ||
CScript script{ConsumeScript(fuzzed_data_provider)}; | ||
(void)legacy_spkm.AddCScript(script); | ||
}, | ||
[&] { | ||
CScript script{ConsumeScript(fuzzed_data_provider)}; | ||
(void)legacy_spkm.IsMine(script); | ||
}, | ||
[&] { | ||
CScript script{ConsumeScript(fuzzed_data_provider)}; | ||
(void)legacy_spkm.CanProvide(script, data); | ||
}, | ||
[&] { | ||
CKeyID address(ConsumeUInt160(fuzzed_data_provider)); | ||
CKey key_out; | ||
(void)legacy_spkm.GetKey(address, key_out); | ||
}, | ||
[&] { | ||
CKeyID address(ConsumeUInt160(fuzzed_data_provider)); | ||
CPubKey pub_key; | ||
(void)legacy_spkm.GetWatchPubKey(address, pub_key); | ||
}, | ||
[&] { | ||
watch_script = ConsumeScript(fuzzed_data_provider); | ||
}, | ||
[&] { | ||
(void)legacy_spkm.LoadWatchOnly(watch_script); | ||
}, | ||
[&] { | ||
(void)legacy_spkm.RemoveWatchOnly(watch_script); | ||
}, | ||
[&] { | ||
(void)legacy_spkm.HaveWatchOnly(watch_script); | ||
} | ||
); | ||
} | ||
} | ||
|
||
} // namespace | ||
} // namespace wallet |