| 4407 | |
| 4408 | |
| 4409 | def test_offer(node_factory, bitcoind): |
| 4410 | plugin = os.path.join(os.path.dirname(__file__), 'plugins/currencyUSDAUD5000.py') |
| 4411 | l1 = node_factory.get_node(options={'disable-plugin': 'cln-currencyrate', 'plugin': plugin}) |
| 4412 | |
| 4413 | # Try empty description |
| 4414 | ret = l1.rpc.call('offer', [9, '']) |
| 4415 | l1.rpc.decode(ret['bolt12']) |
| 4416 | |
| 4417 | bolt12tool = os.path.join(os.path.dirname(__file__), "..", "devtools", "bolt12-cli") |
| 4418 | # Try different amount strings |
| 4419 | for amount in ['1msat', '0.1btc', 'any', '1USD', '1.10AUD']: |
| 4420 | ret = l1.rpc.call('offer', {'amount': amount, |
| 4421 | 'description': 'test for ' + amount}) |
| 4422 | offer = only_one(l1.rpc.call('listoffers', [ret['offer_id']])['offers']) |
| 4423 | |
| 4424 | assert offer['bolt12'] == ret['bolt12'] |
| 4425 | assert offer['offer_id'] == ret['offer_id'] |
| 4426 | |
| 4427 | output = subprocess.check_output([bolt12tool, 'decode', |
| 4428 | offer['bolt12']]).decode('ASCII') |
| 4429 | if amount == 'any': |
| 4430 | assert 'amount' not in output |
| 4431 | else: |
| 4432 | assert 'amount' in output |
| 4433 | |
| 4434 | # Try wrong amount precision: |
| 4435 | with pytest.raises(RpcError, match='Currency AUD requires 2 minor units'): |
| 4436 | l1.rpc.call('offer', {'amount': '1.100AUD', |
| 4437 | 'description': 'test for invalid amount'}) |
| 4438 | |
| 4439 | with pytest.raises(RpcError, match='Currency AUD requires 2 minor units'): |
| 4440 | l1.rpc.call('offer', {'amount': '1.1AUD', |
| 4441 | 'description': 'test for invalid amount'}) |
| 4442 | |
| 4443 | # Make sure it fails on unknown currencies. |
| 4444 | with pytest.raises(RpcError, match='No values available for currency EUR'): |
| 4445 | l1.rpc.call('offer', {'amount': '1.00EUR', |
| 4446 | 'description': 'test for unknown currency'}) |
| 4447 | |
| 4448 | # Test label and description |
| 4449 | weird_label = 'label \\ " \t \n' |
| 4450 | weird_desc = 'description \\ " \t \n ナンセンス 1杯' |
| 4451 | ret = l1.rpc.call('offer', {'amount': '0.1btc', |
| 4452 | 'description': weird_desc, |
| 4453 | 'label': weird_label}) |
| 4454 | offer = only_one(l1.rpc.call('listoffers', [ret['offer_id']])['offers']) |
| 4455 | assert offer['label'] == weird_label |
| 4456 | |
| 4457 | output = subprocess.check_output([bolt12tool, 'decode', |
| 4458 | offer['bolt12']]).decode('UTF-8') |
| 4459 | assert 'description: ' + weird_desc in output |
| 4460 | |
| 4461 | # Test issuer |
| 4462 | weird_issuer = 'description \\ " \t \n ナンセンス 1杯' |
| 4463 | ret = l1.rpc.call('offer', {'amount': '100000sat', |
| 4464 | 'description': 'issuer test', |
| 4465 | 'issuer': weird_issuer}) |
| 4466 | offer = only_one(l1.rpc.call('listoffers', [ret['offer_id']])['offers']) |