| 2444 | |
| 2445 | |
| 2446 | def test_dev_demux(node_factory): |
| 2447 | l1 = node_factory.get_node(may_fail=True, |
| 2448 | broken_log=' lightningd: ') |
| 2449 | |
| 2450 | # Check should work. |
| 2451 | l1.rpc.check(command_to_check='dev', subcommand='crash') |
| 2452 | l1.rpc.check(command_to_check='dev', subcommand='slowcmd', msec=1000) |
| 2453 | l1.rpc.check(command_to_check='dev', subcommand='rhash', secret='00' * 32) |
| 2454 | with pytest.raises(RpcError, match=r'Unknown subcommand'): |
| 2455 | l1.rpc.check(command_to_check='dev', subcommand='foobar') |
| 2456 | with pytest.raises(RpcError, match=r'unknown parameter'): |
| 2457 | l1.rpc.check(command_to_check='dev', subcommand='crash', unk=1) |
| 2458 | with pytest.raises(RpcError, match=r"msec: should be an integer: invalid token"): |
| 2459 | l1.rpc.check(command_to_check='dev', subcommand='slowcmd', msec='aaa') |
| 2460 | with pytest.raises(RpcError, match=r'missing required parameter'): |
| 2461 | l1.rpc.check(command_to_check='dev', subcommand='rhash') |
| 2462 | with pytest.raises(RpcError, match=r'missing required parameter'): |
| 2463 | l1.rpc.check(command_to_check='dev') |
| 2464 | |
| 2465 | # Non-check failures should fail, in both object and array form. |
| 2466 | with pytest.raises(RpcError, match=r'Unknown subcommand'): |
| 2467 | l1.rpc.call('dev', {'subcommand': 'foobar'}) |
| 2468 | with pytest.raises(RpcError, match=r'Unknown subcommand'): |
| 2469 | l1.rpc.call('dev', ['foobar']) |
| 2470 | with pytest.raises(RpcError, match=r'unknown parameter'): |
| 2471 | l1.rpc.call('dev', {'subcommand': 'crash', 'unk': 1}) |
| 2472 | with pytest.raises(RpcError, match=r'too many parameters'): |
| 2473 | l1.rpc.call('dev', ['crash', 1]) |
| 2474 | with pytest.raises(RpcError, match=r"msec: should be an integer: invalid token"): |
| 2475 | l1.rpc.call('dev', {'subcommand': 'slowcmd', 'msec': 'aaa'}) |
| 2476 | with pytest.raises(RpcError, match=r"msec: should be an integer: invalid token"): |
| 2477 | l1.rpc.call('dev', ['slowcmd', 'aaa']) |
| 2478 | with pytest.raises(RpcError, match=r'missing required parameter'): |
| 2479 | l1.rpc.call('dev', {'subcommand': 'rhash'}) |
| 2480 | with pytest.raises(RpcError, match=r'missing required parameter'): |
| 2481 | l1.rpc.call('dev', ['rhash']) |
| 2482 | with pytest.raises(RpcError, match=r'missing required parameter'): |
| 2483 | l1.rpc.call('dev') |
| 2484 | |
| 2485 | # Help should list them all. |
| 2486 | assert 'subcommand=crash|rhash|slowcmd' in l1.rpc.help('dev')['help'][0]['command'] |
| 2487 | |
| 2488 | # These work |
| 2489 | assert l1.rpc.call('dev', ['slowcmd', '7'])['msec'] == 7 |
| 2490 | assert l1.rpc.call('dev', {'subcommand': 'slowcmd', 'msec': '7'})['msec'] == 7 |
| 2491 | assert l1.rpc.call('dev', {'subcommand': 'rhash', 'secret': '00' * 32})['rhash'] == '66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925' |
| 2492 | |
| 2493 | with pytest.raises(RpcError): |
| 2494 | l1.rpc.call('dev', {'subcommand': 'crash'}) |
| 2495 | |
| 2496 | |
| 2497 | @pytest.mark.openchannel('v1') |