From 62253eb04e3ad1225d2a87a3c9647c6c092114df Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 26 Dec 2013 01:26:27 +0400 Subject: Test ping and find_node bencoding --- tests/Network/BitTorrent/DHT/MessageSpec.hs | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/Network/BitTorrent/DHT/MessageSpec.hs (limited to 'tests/Network') 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 @@ +module Network.BitTorrent.DHT.MessageSpec (spec) where +import Test.Hspec +import Data.BEncode as BE +import Network.BitTorrent.Core +import Network.BitTorrent.DHT.Message + + +spec :: Spec +spec = do + describe "ping" $ do + it "properly bencoded" $ do + BE.decode "d2:id20:abcdefghij0123456789e" + `shouldBe` Right (Query "abcdefghij0123456789" Ping) + + BE.encode (Query "abcdefghij0123456789" Ping) + `shouldBe` "d2:id20:abcdefghij0123456789e" + + BE.decode "d2:id20:mnopqrstuvwxyz123456e" + `shouldBe` Right (Response "mnopqrstuvwxyz123456" Ping) + + BE.encode (Response "mnopqrstuvwxyz123456" Ping) + `shouldBe` "d2:id20:mnopqrstuvwxyz123456e" + + describe "find_node" $ do + it "properly bencoded" $ do + BE.decode "d2:id20:abcdefghij0123456789\ + \6:target20:mnopqrstuvwxyz123456e" + `shouldBe` Right (Query "abcdefghij0123456789" + (FindNode "mnopqrstuvwxyz123456")) + + BE.encode (Query "abcdefghij0123456789" + (FindNode "mnopqrstuvwxyz123456")) + `shouldBe` + "d2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e" + + let addr = "127.0.0.1:256" :: NodeAddr IPv4 + let nid = "0123456789abcdefghij" + BE.decode "d2:id20:0123456789abcdefghij\ + \5:nodes26:mnopqrstuvwxyz123456\127\0\0\1\&56\ + \e" + `shouldBe` Right (Response nid (NodeFound [NodeInfo nid addr])) \ No newline at end of file -- cgit v1.2.3