Skip to content

Commit

Permalink
Test for notifications over grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikDeSmedt committed Feb 16, 2024
1 parent a1af975 commit eb12955
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/test_cln_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,60 @@ def test_grpc_decode(node_factory):
string=inv.bolt11
))
print(res)


def test_grpc_block_added_notifications(node_factory, bitcoind):
grpc_port = reserve()

l1 = node_factory.get_node(options={"grpc-port": str(grpc_port)})

# Test the block_added notification
# Start listening to block added events over grpc
block_added_stream = l1.grpc.SubscribeBlockAdded(clnpb.StreamBlockAddedRequest())
bitcoind.generate_block(10)
for block_added_event in block_added_stream:
assert block_added_event.hash is not None
assert block_added_event.height is not None

# If we don't break out of the loop we'll
# be waiting for ever
break


def test_grpc_connect_notification(node_factory):
grpc_port = reserve()

l1 = node_factory.get_node(options={"grpc-port": str(grpc_port)})
l2 = node_factory.get_node()

# Test the connect notification
connect_stream = l1.grpc.SubscribeConnect(clnpb.StreamConnectRequest())
l2.connect(l1)

for connect_event in connect_stream:
breakpoint()
assert connect_event.id.hex() == l2.info["id"]
break


def test_grpc_custommsg_notification(node_factory):
grpc_port = reserve()

l1 = node_factory.get_node(options={"grpc-port": str(grpc_port)})
l2 = node_factory.get_node()

# Test the connect notification
custommsg_stream = l1.grpc.SubscribeCustomMsg(clnpb.StreamCustomMsgRequest())
l2.connect(l1)

# Send the custom-msg to node l1
# The payload doesn't matter.
# It just needs to be valid hex which encodes to an odd BOLT-8 msg id
l2.rpc.sendcustommsg(l1.info["id"], "3131313174657374")

for custommsg in custommsg_stream:
breakpoint()
assert custommsg.peer_id.hex() == l2.info["id"]
assert custommsg.payload.hex() == "3131313174657374"
assert custommsg.payload == b"1111test"
breakpoint()

0 comments on commit eb12955

Please sign in to comment.