| 39 | static size_t *max; |
| 40 | |
| 41 | static 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 | |
| 91 | static bool test_sync_write(int fd, const void *msg TAKES) |
| 92 | { |
no test coverage detected