def test_status_close_channel():
"""Test ability to get a channel's status and close it."""
channel_server._db = DatabaseSQLite3(':memory:', db_dir='')
test_client = _create_client_txs()
# Test that channel close fails when no channel exists
with pytest.raises(PaymentChannelNotFoundError):
channel_server.close('fake', BAD_SIGNATURE)
# Open the channel and make a payment
deposit_txid = channel_server.open(test_client.deposit_tx, test_client.redeem_script)
payment_txid = channel_server.receive_payment(deposit_txid, test_client.payment_tx)
channel_server.redeem(payment_txid)
# Test that channel close fails without a valid signature
with pytest.raises(TransactionVerificationError):
closed = channel_server.close(deposit_txid, BAD_SIGNATURE)
# Test that channel close succeeds
good_signature = codecs.encode(cust_wallet._private_key.sign(deposit_txid).to_der(), 'hex_codec')
closed = channel_server.close(deposit_txid, good_signature)
assert closed
评论列表
文章目录