test: direct messages
This commit is contained in:
parent
30ed35a14e
commit
6b11221205
2 changed files with 55 additions and 1 deletions
|
|
@ -92,6 +92,12 @@
|
||||||
"content": "BwstXDkQJAHnLOrWFzBRDHdMoF4hoXSCwgmR+K2uw237yss/i639rpR2iOIYJP4z?iv=5pTRQh6NBKfe1hyhwh2WEw==",
|
"content": "BwstXDkQJAHnLOrWFzBRDHdMoF4hoXSCwgmR+K2uw237yss/i639rpR2iOIYJP4z?iv=5pTRQh6NBKfe1hyhwh2WEw==",
|
||||||
"sig": "5da31b8a51dcc9fc9665db6199084696b705fc415e1be684b82fe39f3cbd271c2d707fd5a532232205a016e99ed1ef12abdacb52d139d7f5746cb693de71e5aa"
|
"sig": "5da31b8a51dcc9fc9665db6199084696b705fc415e1be684b82fe39f3cbd271c2d707fd5a532232205a016e99ed1ef12abdacb52d139d7f5746cb693de71e5aa"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"direct_message01_response": [
|
||||||
|
"ok",
|
||||||
|
"28c96b6e80681c18a690e0e0dc6ca4e72b9d291d1d2576bc8949a07bb4bee225",
|
||||||
|
true,
|
||||||
|
""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"bob": {
|
"bob": {
|
||||||
|
|
@ -235,6 +241,19 @@
|
||||||
"15f6e6bd6cb538167d4430ea6bd7c0cfb99b400ca3e8879a114e90f74b3f20b2",
|
"15f6e6bd6cb538167d4430ea6bd7c0cfb99b400ca3e8879a114e90f74b3f20b2",
|
||||||
true,
|
true,
|
||||||
""
|
""
|
||||||
|
],
|
||||||
|
"subscribe_to_direct_messages": [
|
||||||
|
"REQ",
|
||||||
|
"notifications:d685447c43c7c18dbbea61923cf0b63e1ab46bed",
|
||||||
|
{
|
||||||
|
"kinds": [
|
||||||
|
4
|
||||||
|
],
|
||||||
|
"#p": [
|
||||||
|
"d685447c43c7c18dbbea61923cf0b63e1ab46bed69b153a48279a95c40bd414a"
|
||||||
|
],
|
||||||
|
"limit": 400
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +54,7 @@ async def test_alice_and_bob():
|
||||||
|
|
||||||
await bob_writes_to_alice(ws_alice, ws_bob)
|
await bob_writes_to_alice(ws_alice, ws_bob)
|
||||||
|
|
||||||
|
await alice_writes_to_bob(ws_alice, ws_bob)
|
||||||
|
|
||||||
def init_clients():
|
def init_clients():
|
||||||
client_manager = NostrClientManager()
|
client_manager = NostrClientManager()
|
||||||
|
|
@ -210,7 +211,7 @@ async def bob_writes_to_alice(ws_alice: MockWebSocket, ws_bob: MockWebSocket):
|
||||||
|
|
||||||
await ws_bob.wire_mock_data(bob["direct_message01"])
|
await ws_bob.wire_mock_data(bob["direct_message01"])
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(ws_bob.sent_messages) == 1
|
len(ws_bob.sent_messages) == 1
|
||||||
), "Bob: Expected confirmation for direct message"
|
), "Bob: Expected confirmation for direct message"
|
||||||
|
|
@ -227,3 +228,37 @@ async def bob_writes_to_alice(ws_alice: MockWebSocket, ws_bob: MockWebSocket):
|
||||||
bob["direct_message01"][1],
|
bob["direct_message01"][1],
|
||||||
]
|
]
|
||||||
), "Alice: Wrong direct message received"
|
), "Alice: Wrong direct message received"
|
||||||
|
|
||||||
|
|
||||||
|
async def alice_writes_to_bob(ws_alice, ws_bob):
|
||||||
|
ws_alice.sent_messages.clear()
|
||||||
|
ws_bob.sent_messages.clear()
|
||||||
|
|
||||||
|
await ws_alice.wire_mock_data(alice["direct_message01"])
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
len(ws_alice.sent_messages) == 1
|
||||||
|
), "Alice: Expected confirmation for direct message"
|
||||||
|
assert ws_alice.sent_messages[0] == dumps(
|
||||||
|
alice["direct_message01_response"]
|
||||||
|
), "Alice: Wrong confirmation for direct message"
|
||||||
|
assert len(ws_bob.sent_messages) == 0, "Bob: no subscription, no message"
|
||||||
|
|
||||||
|
await ws_bob.wire_mock_data(bob["subscribe_to_direct_messages"])
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
len(ws_bob.sent_messages) == 2
|
||||||
|
), "Bob: Receive message and EOSE after subscribe"
|
||||||
|
|
||||||
|
assert ws_bob.sent_messages[0] == dumps(
|
||||||
|
[
|
||||||
|
"EVENT",
|
||||||
|
"notifications:d685447c43c7c18dbbea61923cf0b63e1ab46bed",
|
||||||
|
alice["direct_message01"][1],
|
||||||
|
]
|
||||||
|
), "Bob: Finaly receives direct message from Alice"
|
||||||
|
assert ws_bob.sent_messages[1] == dumps(
|
||||||
|
["EOSE", "notifications:d685447c43c7c18dbbea61923cf0b63e1ab46bed"]
|
||||||
|
), "Bob: Received all stored events"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue