summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Network/BitTorrent/Core/NodeSpec.hs39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/Network/BitTorrent/Core/NodeSpec.hs b/tests/Network/BitTorrent/Core/NodeSpec.hs
index b3bdf134..3f27f9eb 100644
--- a/tests/Network/BitTorrent/Core/NodeSpec.hs
+++ b/tests/Network/BitTorrent/Core/NodeSpec.hs
@@ -1,13 +1,16 @@
1{-# OPTIONS -fno-warn-orphans #-}
1module Network.BitTorrent.Core.NodeSpec (spec) where 2module Network.BitTorrent.Core.NodeSpec (spec) where
2import Control.Applicative 3import Control.Applicative
4import Data.Serialize as S
5import Data.String
3import Test.Hspec 6import Test.Hspec
4import Test.QuickCheck 7import Test.QuickCheck
5 8
6import Network.BitTorrent.Core.Node 9import Network.BitTorrent.Core
7import Network.BitTorrent.Core.PeerAddrSpec () 10import Network.BitTorrent.Core.PeerAddrSpec ()
8 11
9instance Arbitrary NodeId where 12instance Arbitrary NodeId where
10 arbitrary = undefined 13 arbitrary = fromString <$> vector 20
11 14
12instance Arbitrary a => Arbitrary (NodeAddr a) where 15instance Arbitrary a => Arbitrary (NodeAddr a) where
13 arbitrary = NodeAddr <$> arbitrary <*> arbitrary 16 arbitrary = NodeAddr <$> arbitrary <*> arbitrary
@@ -16,4 +19,34 @@ instance Arbitrary a => Arbitrary (NodeInfo a) where
16 arbitrary = NodeInfo <$> arbitrary <*> arbitrary 19 arbitrary = NodeInfo <$> arbitrary <*> arbitrary
17 20
18spec :: Spec 21spec :: Spec
19spec = return () \ No newline at end of file 22spec = do
23 describe "NodeId" $ do
24 it "properly serialized" $ do
25 S.decode "mnopqrstuvwxyz123456"
26 `shouldBe` Right ("mnopqrstuvwxyz123456" :: NodeId)
27
28 S.encode ("mnopqrstuvwxyz123456" :: NodeId)
29 `shouldBe` "mnopqrstuvwxyz123456"
30
31 it "properly serialized (iso)" $ property $ \ nid ->
32 S.decode (S.encode nid) `shouldBe`
33 Right (nid :: NodeId)
34
35 describe "NodeAddr" $ do
36 it "properly serialized" $ do
37 S.decode "\127\0\0\1\1\2" `shouldBe`
38 Right ("127.0.0.1:258" :: NodeAddr IPv4)
39
40 it "properly serialized (iso)" $ property $ \ nid ->
41 S.decode (S.encode nid) `shouldBe`
42 Right (nid :: NodeAddr IPv4)
43
44 describe "NodeInfo" $ do
45 it "properly serialized" $ do
46 S.decode "mnopqrstuvwxyz123456\
47 \\127\0\0\1\1\2" `shouldBe` Right
48 (NodeInfo "mnopqrstuvwxyz123456" "127.0.0.1:258" :: NodeInfo IPv4)
49
50 it "properly serialized (iso)" $ property $ \ nid ->
51 S.decode (S.encode nid) `shouldBe`
52 Right (nid :: NodeInfo IPv4)