Commit Graph

24 Commits

Author SHA1 Message Date
Rusty Russell
7fe22b29e7 pytest: test parsing of bolt12 invoice strings in runes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-27 16:09:23 +10:30
Rusty Russell
a3332dcc34 runes: handle lightning: prefix in invoice arguments
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-27 16:09:23 +10:30
Rusty Russell
8114b3b437 pytest: add test for rune pinv bolt11 parsing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-27 16:09:23 +10:30
Rusty Russell
4816550b0f lightningd: check rune parameter names with and without punctuation.
Changelog-Changed: runes: named parameters (e.g. `pnameamountmsat`) no longer need to remove underscores (i.e. `pnameamount_msat` now works as expected).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 11:18:36 +10:30
Rusty Russell
a880146e81 lightningd: name error messages a bit more readable.
Rather than speaking 'rune' we should speak english in error messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: @ShahanaFarooqui
2024-03-20 11:18:36 +10:30
Rusty Russell
ba9daa468d ccan: update to get rune error message fix.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 11:18:36 +10:30
Rusty Russell
1fedae4f83 pytest: make runes amount test more specific.
This reveals an inadequacy in our rune error reporting:
we complain a missing parameter is "not an integer field" instead
of "not present":

```
        # Rune requires amount_msat < 10,000!
>       with pytest.raises(RpcError, match='Not permitted: pnameamountmsat is not present') as exc_info:
E       AssertionError: Regex pattern did not match.
E        Regex: 'Not permitted: pnameamountmsat is not present'
E        Input: "RPC call failed: method: checkrune, payload: {'nodeid': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'rune': 'b3hXuEM7Pqzk-C7HUw83xzvHOV7fmuGaWjdo-wHdfg89MCZtZXRob2Q9cGF5JnBuYW1lYW1vdW50bXNhdDwxMDAwMA==', 'method': 'pay', 'params': {'bolt11': 'lnbcrt123n1pj7flqdsp5ndqgxpwk2hf50gzm0d4ssgjnd90cwkrc8udh7lfr5x583jms7yqspp5kn5stlnkv70celgw4vmdva9m7a57drd2403vnx4whq2p5nawkh3sdq5v3jhxcmjd9c8g6t0dccsxqyjw5qcqp99qxpqysgqhrgp7wp640gyujxk0mz4l6e6dxmqp7fz8pnnpnnqjfxg2scvuzfpwlxrj332u72p5g709eqr8rwaueruce84h0qmh6kc5c2zxgg9q4qps4cu8k'}}, error: {'code': 1502, 'message': 'Not permitted: pnameamountmsat is not an integer field'}"
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 11:18:36 +10:30
Rusty Russell
cdd58e2fe3 pytest: correctly test missing method for runes.
This makes it clear exactly what the expectation is/

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-17 14:58:40 +10:30
Tony Aldon
ebee48ca8c pytest: test checkrune when method parameter is the empty string.
Add test `test_rune_method_not_equal_and_method_empty` that reproduces
issue #6725.

This fails currently, so next commit fix it up.

Error:

```
>       with pytest.raises(RpcError, match='Not permitted: method not present'):
E       Failed: DID NOT RAISE <class 'pyln.client.lightning.RpcError'>

tests/test_runes.py:605: Failed
```
2023-10-12 20:42:43 +02:00
ShahanaFarooqui
9561094433 db: removed deprecated runes_uniqueid from vars table
Fixes: #6696

Changelog-Fixed: rune: use runes table `id` instead `runes_uniqueid` from `vars` because it returns incorrect unique id if rune/s migrated from datastore.
2023-10-03 08:56:53 +10:30
ShahanaFarooqui
9bcabbc912 runes: Reimplement rate in terms of per
Changelog-Changed: JSON-RPC: `checkrune` `rate` restriction is slightly stricter (exact division of time like `per`)
2023-10-03 06:57:54 +10:30
ShahanaFarooqui
f60882feaf tests/runes: per restriction test cases 2023-09-21 13:31:34 +09:30
ShahanaFarooqui
d745323f74 lightning/runes: added last_used in showrunes
Changelog-Added: JSON-RPC: `showrunes` new field `last_used`
2023-09-21 13:31:34 +09:30
Rusty Russell
785fe973a6 runes: ensure that uniqueid is a valid number.
It always is for runes we create, but in theory you can take our secret key
and make our own runes with your own tools.

(We correctly refuse runes without uniqueids if they're *not* ours
anyway: uniqueid is only used for our own runes).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell
ecb09778db lightningd: refuse to create rune with empty fields.
These look like uniqueids, and so can confuse us (I discovered this by
making a typo in a test!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell
bb38f83b88 checkrune: make nodeid and method optional.
nodeid is only useful when we know the peer we're talking to (e.g. commando).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
No-schema-diff-check: We're simply making optional, not deprecating!
2023-09-12 15:19:02 +09:30
Rusty Russell
b88583e346 db: migrate old runes table to fix up id fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 05:33:15 +09:30
Rusty Russell
2de304314a runes: insert rune with correct id field.
"id" is a magic name, so it was being populated by sqlite3
automatically, starting at 0.  Fortunately, we only fetched by id in
one place: to indicate the `stored` flag when asked about an explicit
rune in `showrunes`.

Reported-by: @ShahanaFarooqui
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `showrunes` on a specific rune would always say `stored`: false.
2023-08-31 05:33:15 +09:30
Rusty Russell
7429b1e7e1 pytest: test to show that we got db ids incorrect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 05:33:15 +09:30
Rusty Russell
11b5f31034 lightningd: clean up commando rune_counter from datastore on migration.
Pointed out by @ShahanaFarooqui, we leave a single unused entry in the datastore,
so we should clean that up too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell
925f9fcce5 lightningd: migrate (and delete) old commando blacklists.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell
dccbccf8f2 lightningd: migrate (and delete) old commando runes.
If they have invalid runes, we bail, but if they have runes which used
a different master secret (old commando.py allowed you to override
secret), we just complain and delete them.

Note that this requires more mocks in wallet/test/run-db.c...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Shahana Farooqui
49fdc0df99 runes: Renamed listrunes to showrunes 2023-07-25 11:07:43 +09:30
Rusty Russell
77d08d13a2 pytest: test for runes, based on commando tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30