(node_factory)
| 148 | @pytest.mark.openchannel("v1") |
| 149 | @pytest.mark.openchannel("v2") |
| 150 | def test_pay(node_factory): |
| 151 | l1, l2 = node_factory.line_graph(2, opts={'allow-deprecated-apis': True}) |
| 152 | |
| 153 | inv = l2.rpc.invoice(123000, "test_pay", "description")["bolt11"] |
| 154 | before = int(time.time()) |
| 155 | details = l1.rpc.call("renepay", {"invstring": inv, "dev_use_shadow": False}) |
| 156 | after = time.time() |
| 157 | preimage = details["payment_preimage"] |
| 158 | assert details["status"] == "complete" |
| 159 | assert details["amount_msat"] == Millisatoshi(123000) |
| 160 | assert details["destination"] == l2.info["id"] |
| 161 | assert details["created_at"] >= before |
| 162 | assert details["created_at"] <= after |
| 163 | |
| 164 | invoices = l2.rpc.listinvoices("test_pay")["invoices"] |
| 165 | assert len(invoices) == 1 |
| 166 | invoice = invoices[0] |
| 167 | assert ( |
| 168 | invoice["status"] == "paid" |
| 169 | and invoice["paid_at"] >= before |
| 170 | and invoice["paid_at"] <= after |
| 171 | ) |
| 172 | |
| 173 | # Repeat payments are NOPs (if valid): we can hand null. |
| 174 | l1.rpc.call("renepay", {"invstring": inv, "dev_use_shadow": False}) |
| 175 | # This won't work: can't provide an amount (even if correct!) |
| 176 | with pytest.raises(RpcError): |
| 177 | l1.rpc.call("renepay", {"invstring": inv, "amount_msat": 123000}) |
| 178 | with pytest.raises(RpcError): |
| 179 | l1.rpc.call("renepay", {"invstring": inv, "amount_msat": 122000}) |
| 180 | |
| 181 | # Check pay_index is not null |
| 182 | outputs = l2.db_query( |
| 183 | 'SELECT pay_index IS NOT NULL AS q FROM invoices WHERE label="label";' |
| 184 | ) |
| 185 | assert len(outputs) == 1 and outputs[0]["q"] != 0 |
| 186 | |
| 187 | # Check payment of any-amount invoice. |
| 188 | for i in range(5): |
| 189 | label = "any{}".format(i) |
| 190 | inv2 = l2.rpc.invoice("any", label, "description")["bolt11"] |
| 191 | # Must provide an amount! |
| 192 | with pytest.raises(RpcError): |
| 193 | l1.rpc.call("renepay", {"invstring": inv2, "dev_use_shadow": False}) |
| 194 | |
| 195 | l1.rpc.call( |
| 196 | "renepay", |
| 197 | { |
| 198 | "invstring": inv2, |
| 199 | "dev_use_shadow": False, |
| 200 | "amount_msat": random.randint(1000, 999999), |
| 201 | }, |
| 202 | ) |
| 203 | |
| 204 | # Should see 6 completed payments |
| 205 | assert len(l1.rpc.listsendpays()["payments"]) == 6 |
| 206 | |
| 207 | # Test listsendpays indexed by bolt11. |
nothing calls this directly
no test coverage detected