spec :: Spec
spec = do
  rpcSpec (Proxy :: Proxy DhtPacket)
  binarySpec (Proxy :: Proxy DhtPacket)
  readShowSpec (Proxy :: Proxy DhtPacket)

  it "encodes and decodes packets" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Just payload

  it "fails to decode packets with the wrong secret key" $
    property $ \senderKeyPair (KeyPair _ receiverPublicKey) badSecretKey nonce payload ->
      encodeAndDecodeString senderKeyPair (KeyPair badSecretKey receiverPublicKey) nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Partial)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeCharAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Fail)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeIntAndDecodeNodeInfo senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "should decode empty CipherText correctly" $
    expectDecoded
      [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      ] $
      DhtPacket
        (read "\"0000000000000000000000000000000000000000000000000000000000000000\"")
        (read "\"000000000000000000000000000000000000000000000000\"")
        (read "\"00000000000000000000000000000000\"")
spec :: Spec
spec = do
  rpcSpec (Proxy :: Proxy DhtPacket)
  binarySpec (Proxy :: Proxy DhtPacket)
  readShowSpec (Proxy :: Proxy DhtPacket)

  it "encodes and decodes packets" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Just payload

  it "fails to decode packets with the wrong secret key" $
    property $ \senderKeyPair (KeyPair _ receiverPublicKey) badSecretKey nonce payload ->
      encodeAndDecodeString senderKeyPair (KeyPair badSecretKey receiverPublicKey) nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Partial)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeCharAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Fail)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeIntAndDecodeNodeInfo senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "should decode empty CipherText correctly" $
    expectDecoded
      [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      ] $
      DhtPacket
        (read "\"0000000000000000000000000000000000000000000000000000000000000000\"")
        (read "\"000000000000000000000000000000000000000000000000\"")
        (read "\"00000000000000000000000000000000\"")
spec = do
  rpcSpec (Proxy :: Proxy DhtPacket)
  binarySpec (Proxy :: Proxy DhtPacket)
  readShowSpec (Proxy :: Proxy DhtPacket)

  it "encodes and decodes packets" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Just payload

  it "fails to decode packets with the wrong secret key" $
    property $ \senderKeyPair (KeyPair _ receiverPublicKey) badSecretKey nonce payload ->
      encodeAndDecodeString senderKeyPair (KeyPair badSecretKey receiverPublicKey) nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Partial)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeCharAndDecodeString senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "fails to decode packets with the wrong payload type (Fail)" $
    property $ \senderKeyPair receiverKeyPair nonce payload ->
      encodeIntAndDecodeNodeInfo senderKeyPair receiverKeyPair nonce payload `shouldBe` Nothing

  it "should decode empty CipherText correctly" $
    expectDecoded
      [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      ] $
      DhtPacket
        (read "\"0000000000000000000000000000000000000000000000000000000000000000\"")
        (read "\"000000000000000000000000000000000000000000000000\"")
        (read "\"00000000000000000000000000000000\"")