MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_sync_read

Function test_sync_read

tests/fuzz/fuzz-open_channel.c:41–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39static size_t *max;
40
41static u8 *test_sync_read(const tal_t *ctx, int fd)
42{
43 if (fd == REQ_FD) /* lightningd message */
44 {
45 u32 mindepth = 10;
46 return towire_openingd_got_offer_reply(ctx, NULL, NULL, NULL, NULL, mindepth);
47 }
48 else if (fd == HSM_FD) /* HSMD message */
49 {
50 hsmd_reads++;
51 if (hsmd_reads == 1)
52 return towire_hsmd_setup_channel_reply(ctx);
53 else if (hsmd_reads == 2)
54 return towire_hsmd_validate_commitment_tx_reply(ctx, NULL, &dummy_pubkey);
55 else if (hsmd_reads == 3) {
56 struct sha256_double h;
57 struct bitcoin_signature sig;
58
59 memset(&h, 0, sizeof(h));
60 sign_hash(&dummy_privkey, &h, &sig.s);
61 sig.sighash_type = SIGHASH_ALL;
62
63 return towire_hsmd_sign_tx_reply(ctx, &sig);
64 }
65 else
66 assert(false && "Too many HSMD reads!");
67 }
68 else if (fd == PEER_FD) /* Peer message */
69 {
70 /* Choose between creating a valid message and a fuzzed one. */
71 if (fromwire_u8(cursor, max) % 2 == 0) {
72 struct sha256_double h;
73 struct bitcoin_signature sig;
74 struct bitcoin_outpoint out;
75
76 memset(&h, 1, sizeof(h));
77 sign_hash(&dummy_privkey, &h, &sig.s);
78 memset(&out.txid, 1, sizeof(out.txid));
79 out.n = 0;
80
81 return towire_funding_created(ctx, &state->channel_id,
82 &out.txid, out.n, &sig.s);
83 }
84 else
85 return create_fuzz_msg(ctx);
86 }
87 else
88 assert(false && "Unknown caller!");
89}
90
91static bool test_sync_write(int fd, const void *msg TAKES)
92{

Callers 2

test_peer_readFunction · 0.85

Calls 3

sign_hashFunction · 0.85
create_fuzz_msgFunction · 0.85
fromwire_u8Function · 0.50

Tested by

no test coverage detected