diff --git a/src/wallet/test/fuzz/scriptpubkeyman.cpp b/src/wallet/test/fuzz/scriptpubkeyman.cpp index 1066a3c268d..315efa0dca2 100644 --- a/src/wallet/test/fuzz/scriptpubkeyman.cpp +++ b/src/wallet/test/fuzz/scriptpubkeyman.cpp @@ -94,7 +94,7 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) LOCK(wallet.cs_wallet); wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); wallet.SetLastBlockProcessed(chainstate.m_chain.Height(), chainstate.m_chain.Tip()->GetBlockHash()); - wallet.m_keypool_size = 10; + wallet.m_keypool_size = 1; } auto wallet_desc{CreateWalletDescriptor(fuzzed_data_provider)}; @@ -102,22 +102,22 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) auto spk_manager{CreateDescriptor(wallet_desc->first, wallet_desc->second, wallet)}; if (spk_manager == nullptr) return; + if (fuzzed_data_provider.ConsumeBool()) { + auto wallet_desc{CreateWalletDescriptor(fuzzed_data_provider)}; + if (!wallet_desc.has_value()) { + return; + } + std::string error; + if (spk_manager->CanUpdateToWalletDescriptor(wallet_desc->first, error)) { + auto new_spk_manager{CreateDescriptor(wallet_desc->first, wallet_desc->second, wallet)}; + if (new_spk_manager != nullptr) spk_manager = new_spk_manager; + } + } + bool good_data{true}; - LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 300) { + LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 20) { CallOneOf( fuzzed_data_provider, - [&] { - auto wallet_desc{CreateWalletDescriptor(fuzzed_data_provider)}; - if (!wallet_desc.has_value()) { - good_data = false; - return; - } - std::string error; - if (spk_manager->CanUpdateToWalletDescriptor(wallet_desc->first, error)) { - auto new_spk_manager{CreateDescriptor(wallet_desc->first, wallet_desc->second, wallet)}; - if (new_spk_manager != nullptr) spk_manager = new_spk_manager; - } - }, [&] { const CScript script{ConsumeScript(fuzzed_data_provider)}; auto is_mine{spk_manager->IsMine(script)}; @@ -144,29 +144,11 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) }, [&] { auto spks{spk_manager->GetScriptPubKeys()}; - for (const CScript& spk : spks) { - if (fuzzed_data_provider.ConsumeBool()) { - spk_manager->MarkUnusedAddresses(spk); - } + if (!spks.empty()) { + auto& spk{PickValue(fuzzed_data_provider, spks)}; + (void)spk_manager->MarkUnusedAddresses(spk); } }, - [&] { - CKey key{ConsumePrivateKey(fuzzed_data_provider, /*compressed=*/fuzzed_data_provider.ConsumeBool())}; - if (!key.IsValid()) { - good_data = false; - return; - } - spk_manager->AddDescriptorKey(key, key.GetPubKey()); - spk_manager->TopUp(); - LOCK(spk_manager->cs_desc_man); - auto particular_key{spk_manager->GetKey(key.GetPubKey().GetID())}; - assert(*particular_key == key); - assert(spk_manager->HasPrivKey(key.GetPubKey().GetID())); - }, - [&] { - std::string descriptor; - (void)spk_manager->GetDescriptorString(descriptor, /*priv=*/fuzzed_data_provider.ConsumeBool()); - }, [&] { LOCK(spk_manager->cs_desc_man); auto wallet_desc{spk_manager->GetWalletDescriptor()}; @@ -209,6 +191,8 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) ); } + std::string descriptor; + (void)spk_manager->GetDescriptorString(descriptor, /*priv=*/fuzzed_data_provider.ConsumeBool()); (void)spk_manager->GetEndRange(); (void)spk_manager->GetKeyPoolSize(); }