summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/DHT
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/BitTorrent/DHT')
-rw-r--r--tests/Network/BitTorrent/DHT/MessageSpec.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs
new file mode 100644
index 00000000..e8a76f14
--- /dev/null
+++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs
@@ -0,0 +1,41 @@
1module Network.BitTorrent.DHT.MessageSpec (spec) where
2import Test.Hspec
3import Data.BEncode as BE
4import Network.BitTorrent.Core
5import Network.BitTorrent.DHT.Message
6
7
8spec :: Spec
9spec = do
10 describe "ping" $ do
11 it "properly bencoded" $ do
12 BE.decode "d2:id20:abcdefghij0123456789e"
13 `shouldBe` Right (Query "abcdefghij0123456789" Ping)
14
15 BE.encode (Query "abcdefghij0123456789" Ping)
16 `shouldBe` "d2:id20:abcdefghij0123456789e"
17
18 BE.decode "d2:id20:mnopqrstuvwxyz123456e"
19 `shouldBe` Right (Response "mnopqrstuvwxyz123456" Ping)
20
21 BE.encode (Response "mnopqrstuvwxyz123456" Ping)
22 `shouldBe` "d2:id20:mnopqrstuvwxyz123456e"
23
24 describe "find_node" $ do
25 it "properly bencoded" $ do
26 BE.decode "d2:id20:abcdefghij0123456789\
27 \6:target20:mnopqrstuvwxyz123456e"
28 `shouldBe` Right (Query "abcdefghij0123456789"
29 (FindNode "mnopqrstuvwxyz123456"))
30
31 BE.encode (Query "abcdefghij0123456789"
32 (FindNode "mnopqrstuvwxyz123456"))
33 `shouldBe`
34 "d2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e"
35
36 let addr = "127.0.0.1:256" :: NodeAddr IPv4
37 let nid = "0123456789abcdefghij"
38 BE.decode "d2:id20:0123456789abcdefghij\
39 \5:nodes26:mnopqrstuvwxyz123456\127\0\0\1\&56\
40 \e"
41 `shouldBe` Right (Response nid (NodeFound [NodeInfo nid addr])) \ No newline at end of file