| 1847 | } |
| 1848 | |
| 1849 | static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx) |
| 1850 | { |
| 1851 | struct wallet_payment *t = tal(ctx, struct wallet_payment), *t2; |
| 1852 | struct wallet *w = create_test_wallet(ld, ctx); |
| 1853 | |
| 1854 | mempat(t, sizeof(*t)); |
| 1855 | t->destination = tal(t, struct node_id); |
| 1856 | memset(t->destination, 2, sizeof(struct node_id)); |
| 1857 | |
| 1858 | t->id = 0; |
| 1859 | t->msatoshi = AMOUNT_MSAT(100); |
| 1860 | t->msatoshi_sent = AMOUNT_MSAT(101); |
| 1861 | t->total_msat = t->msatoshi; |
| 1862 | t->status = PAYMENT_PENDING; |
| 1863 | t->payment_preimage = NULL; |
| 1864 | memset(&t->payment_hash, 1, sizeof(t->payment_hash)); |
| 1865 | t->partid = 0; |
| 1866 | t->groupid = 12345; |
| 1867 | |
| 1868 | db_begin_transaction(w->db); |
| 1869 | t2 = tal_dup(NULL, struct wallet_payment, t); |
| 1870 | wallet_payment_setup(w, t2); |
| 1871 | wallet_payment_store(w, take(t2)); |
| 1872 | t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash, 0, t->groupid); |
| 1873 | CHECK(t2 != NULL); |
| 1874 | CHECK(t2->status == t->status); |
| 1875 | CHECK(sha256_eq(&t2->payment_hash, &t->payment_hash)); |
| 1876 | CHECK(t2->partid == t->partid); |
| 1877 | CHECK(node_id_cmp(t2->destination, t->destination) == 0); |
| 1878 | CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi)); |
| 1879 | CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent)); |
| 1880 | CHECK(amount_msat_eq(t2->total_msat, t->total_msat)); |
| 1881 | CHECK(!t2->payment_preimage); |
| 1882 | |
| 1883 | t->status = PAYMENT_COMPLETE; |
| 1884 | t->payment_preimage = tal(w, struct preimage); |
| 1885 | memset(t->payment_preimage, 2, sizeof(*t->payment_preimage)); |
| 1886 | wallet_payment_set_status(w, &t->payment_hash, t->partid, t->groupid, |
| 1887 | t->status, t->payment_preimage); |
| 1888 | t2 = wallet_payment_by_hash(ctx, w, &t->payment_hash, t->partid, t->groupid); |
| 1889 | CHECK(t2 != NULL); |
| 1890 | CHECK(t2->status == t->status); |
| 1891 | CHECK(sha256_eq(&t2->payment_hash, &t->payment_hash)); |
| 1892 | CHECK(t2->partid == t->partid); |
| 1893 | CHECK(node_id_eq(t2->destination, t->destination)); |
| 1894 | CHECK(amount_msat_eq(t2->msatoshi, t->msatoshi)); |
| 1895 | CHECK(amount_msat_eq(t2->msatoshi_sent, t->msatoshi_sent)); |
| 1896 | CHECK(preimage_eq(t->payment_preimage, t2->payment_preimage)); |
| 1897 | |
| 1898 | db_commit_transaction(w->db); |
| 1899 | return true; |
| 1900 | } |
| 1901 | |
| 1902 | static bool test_wallet_payment_status_enum(void) |
| 1903 | { |
no test coverage detected