diff options
Diffstat (limited to 'tests/Network')
-rw-r--r-- | tests/Network/BitTorrent/DHT/MessageSpec.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs index 3b1f5acd..6f3c7489 100644 --- a/tests/Network/BitTorrent/DHT/MessageSpec.hs +++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs | |||
@@ -21,6 +21,16 @@ import Data.TorrentSpec () | |||
21 | import Network.BitTorrent.CoreSpec () | 21 | import Network.BitTorrent.CoreSpec () |
22 | import Network.BitTorrent.DHT.TokenSpec () | 22 | import Network.BitTorrent.DHT.TokenSpec () |
23 | 23 | ||
24 | -- Arbitrary queries and responses. | ||
25 | instance Arbitrary Ping where arbitrary = pure Ping | ||
26 | instance Arbitrary FindNode where arbitrary = FindNode <$> arbitrary | ||
27 | instance Arbitrary ip => Arbitrary (NodeFound ip) where arbitrary = NodeFound <$> arbitrary | ||
28 | instance Arbitrary GetPeers where arbitrary = GetPeers <$> arbitrary | ||
29 | instance Arbitrary ip => Arbitrary (GotPeers ip) where arbitrary = GotPeers <$> arbitrary <*> arbitrary | ||
30 | instance Arbitrary Announce where arbitrary = Announce <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary | ||
31 | instance Arbitrary Announced where arbitrary = pure Announced | ||
32 | instance Arbitrary x => Arbitrary (Query x) where arbitrary = Query <$> arbitrary <*> arbitrary <*> arbitrary | ||
33 | instance Arbitrary x => Arbitrary (Response x) where arbitrary = Response <$> arbitrary <*> arbitrary | ||
24 | 34 | ||
25 | instance MonadLogger IO where | 35 | instance MonadLogger IO where |
26 | monadLoggerLog _ _ _ _ = return () | 36 | monadLoggerLog _ _ _ _ = return () |
@@ -168,7 +178,7 @@ spec = do | |||
168 | \5:token8:aoeusnth\ | 178 | \5:token8:aoeusnth\ |
169 | \e" `shouldBe` Right | 179 | \e" `shouldBe` Right |
170 | (Query "abcdefghij0123456789" False | 180 | (Query "abcdefghij0123456789" False |
171 | (Announce False "mnopqrstuvwxyz123456" 6881 "aoeusnth")) | 181 | (Announce False "mnopqrstuvwxyz123456" Nothing 6881 "aoeusnth")) |
172 | 182 | ||
173 | BE.decode "d2:id20:abcdefghij0123456789\ | 183 | BE.decode "d2:id20:abcdefghij0123456789\ |
174 | \12:implied_porti1e\ | 184 | \12:implied_porti1e\ |
@@ -177,7 +187,7 @@ spec = do | |||
177 | \5:token8:aoeusnth\ | 187 | \5:token8:aoeusnth\ |
178 | \e" `shouldBe` Right | 188 | \e" `shouldBe` Right |
179 | (Query "abcdefghij0123456789" False | 189 | (Query "abcdefghij0123456789" False |
180 | (Announce True "mnopqrstuvwxyz123456" 6881 "aoeusnth")) | 190 | (Announce True "mnopqrstuvwxyz123456" Nothing 6881 "aoeusnth")) |
181 | 191 | ||
182 | 192 | ||
183 | BE.decode "d2:id20:mnopqrstuvwxyz123456e" | 193 | BE.decode "d2:id20:mnopqrstuvwxyz123456e" |
@@ -185,7 +195,7 @@ spec = do | |||
185 | (Response "mnopqrstuvwxyz123456" Announced) | 195 | (Response "mnopqrstuvwxyz123456" Announced) |
186 | 196 | ||
187 | it "properly bencoded (iso)" $ property $ \ nid flag topic port token -> do | 197 | it "properly bencoded (iso)" $ property $ \ nid flag topic port token -> do |
188 | prop_bencode (Query nid False (Announce flag topic port token)) | 198 | prop_bencode (Query nid False (Announce flag topic Nothing port token)) |
189 | prop_bencode (Response nid (Announced)) | 199 | prop_bencode (Response nid (Announced)) |
190 | 200 | ||
191 | 201 | ||
@@ -194,7 +204,7 @@ spec = do | |||
194 | Response _remoteId Announced <- rpc $ do | 204 | Response _remoteId Announced <- rpc $ do |
195 | Response _ GotPeers {..} <- query remoteAddr (Query nid False (GetPeers def)) | 205 | Response _ GotPeers {..} <- query remoteAddr (Query nid False (GetPeers def)) |
196 | let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4] | 206 | let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4] |
197 | query remoteAddr (Query nid False (Announce False def thisPort grantedToken)) | 207 | query remoteAddr (Query nid False (Announce False def Nothing thisPort grantedToken)) |
198 | return () | 208 | return () |
199 | 209 | ||
200 | it "does fail on invalid token" $ do | 210 | it "does fail on invalid token" $ do |
@@ -206,6 +216,6 @@ spec = do | |||
206 | let q :: MonadKRPC h m => SockAddr -> Query Announce | 216 | let q :: MonadKRPC h m => SockAddr -> Query Announce |
207 | -> m (Response Announced) | 217 | -> m (Response Announced) |
208 | q = query | 218 | q = query |
209 | q remoteAddr (Query nid False (Announce False def thisPort invalidToken))) | 219 | q remoteAddr (Query nid False (Announce False def Nothing thisPort invalidToken))) |
210 | `shouldThrow` isQueryError | 220 | `shouldThrow` isQueryError |
211 | return () | 221 | return () |