summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/DHT
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-08 07:53:52 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-08 07:53:52 +0400
commit64f26fba49e7ae933a0ccdcd7cdbb56c5c6a7df7 (patch)
tree05aa86f2dd3ecff40b6fde9b40e02a0d4e404e91 /tests/Network/BitTorrent/DHT
parent3ddfd24a0b158bdf06f654a373f82e0591cb9b8f (diff)
Use newer krpc package
Diffstat (limited to 'tests/Network/BitTorrent/DHT')
-rw-r--r--tests/Network/BitTorrent/DHT/MessageSpec.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs
index af694470..0d84c919 100644
--- a/tests/Network/BitTorrent/DHT/MessageSpec.hs
+++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs
@@ -1,6 +1,7 @@
1{-# LANGUAGE RecordWildCards #-} 1{-# LANGUAGE RecordWildCards #-}
2module Network.BitTorrent.DHT.MessageSpec (spec) where 2module Network.BitTorrent.DHT.MessageSpec (spec) where
3import Control.Monad.Reader 3import Control.Monad.Reader
4import Control.Monad.Logger
4import Control.Concurrent 5import Control.Concurrent
5import Data.BEncode as BE 6import Data.BEncode as BE
6import Data.ByteString.Lazy as BL 7import Data.ByteString.Lazy as BL
@@ -8,7 +9,8 @@ import Data.Default
8import Data.List as L 9import Data.List as L
9import Network.BitTorrent.Core 10import Network.BitTorrent.Core
10import Network.BitTorrent.DHT.Message 11import Network.BitTorrent.DHT.Message
11import Network.KRPC 12import qualified Network.KRPC as KRPC (def)
13import Network.KRPC hiding (def)
12import Network.Socket (PortNumber) 14import Network.Socket (PortNumber)
13import Test.Hspec 15import Test.Hspec
14import Test.QuickCheck 16import Test.QuickCheck
@@ -18,6 +20,10 @@ import Network.BitTorrent.CoreSpec ()
18import Network.BitTorrent.DHT.TokenSpec () 20import Network.BitTorrent.DHT.TokenSpec ()
19import Data.Torrent.InfoHashSpec () 21import Data.Torrent.InfoHashSpec ()
20 22
23
24instance MonadLogger IO where
25 monadLoggerLog _ _ _ _ = return ()
26
21remoteAddr :: SockAddr 27remoteAddr :: SockAddr
22remoteAddr = SockAddrInet 6881 (256 * 256 * 256 + 127) 28remoteAddr = SockAddrInet 6881 (256 * 256 * 256 + 127)
23 29
@@ -29,12 +35,12 @@ thisPort = 60001
29 35
30rpc :: ReaderT (Manager IO) IO a -> IO a 36rpc :: ReaderT (Manager IO) IO a -> IO a
31rpc action = do 37rpc action = do
32 withManager thisAddr [] $ runReaderT $ do 38 withManager KRPC.def thisAddr [] $ runReaderT $ do
33 listen 39 listen
34 action 40 action
35 41
36isProtocolError :: KError -> Bool 42isQueryError :: QueryFailure -> Bool
37isProtocolError KError {..} = errorCode == ProtocolError 43isQueryError _ = True
38 44
39prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation 45prop_bencode :: Eq a => Show a => BEncode a => a -> Expectation
40prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x 46prop_bencode x = BE.decode (BL.toStrict (BE.encode x)) `shouldBe` Right x
@@ -196,5 +202,5 @@ spec = do
196 let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4] 202 let _ = peers :: Either [NodeInfo IPv4] [PeerAddr IPv4]
197 let invalidToken = "" 203 let invalidToken = ""
198 query remoteAddr (Query nid (Announce False def thisPort invalidToken))) 204 query remoteAddr (Query nid (Announce False def thisPort invalidToken)))
199 `shouldThrow` isProtocolError 205 `shouldThrow` isQueryError
200 return () 206 return ()