MCPcopy Create free account
hub / github.com/ElementsProject/elements / FUZZ_TARGET_INIT

Function FUZZ_TARGET_INIT

src/test/fuzz/rpc.cpp:366–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366FUZZ_TARGET_INIT(rpc, initialize_rpc)
367{
368 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
369 SetMockTime(ConsumeTime(fuzzed_data_provider));
370 const std::string rpc_command = fuzzed_data_provider.ConsumeRandomLengthString(64);
371 if (!g_limit_to_rpc_command.empty() && rpc_command != g_limit_to_rpc_command) {
372 return;
373 }
374 const bool safe_for_fuzzing = std::find(RPC_COMMANDS_SAFE_FOR_FUZZING.begin(), RPC_COMMANDS_SAFE_FOR_FUZZING.end(), rpc_command) != RPC_COMMANDS_SAFE_FOR_FUZZING.end();
375 if (!safe_for_fuzzing) {
376 return;
377 }
378 std::vector<std::string> arguments;
379 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100) {
380 arguments.push_back(ConsumeRPCArgument(fuzzed_data_provider));
381 }
382 try {
383 rpc_testing_setup->CallRPC(rpc_command, arguments);
384 } catch (const UniValue& json_rpc_error) {
385 const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
386 // Once c++20 is allowed, starts_with can be used.
387 // if (error_msg.starts_with("Internal bug detected")) {
388 if (0 == error_msg.rfind("Internal bug detected", 0)) {
389 // Only allow the intentional internal bug
390 assert(error_msg.find("trigger_internal_bug") != std::string::npos);
391 }
392 }
393}

Callers

nothing calls this directly

Calls 13

SetMockTimeFunction · 0.85
ConsumeTimeFunction · 0.85
ConsumeRPCArgumentFunction · 0.85
ConsumeBoolMethod · 0.80
findMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected