     (is (= 1 (q/chain-length @db/db)))))
 
 (deftest test-forwarding-received-blocks-to-peers
-  (q/add-peer! db/db {:port test-port-2 :host "127.0.0.1"})
+  (q/add-peer! db/db {:port test-port :host "127.0.0.1"})
   (let [b (miner/mine (blocks/generate-block [(miner/coinbase)]))]
     (handler {:message "submit_block" :payload b} sock-info)
     (is (= 1 (q/chain-length @db/db)))

             (json-body req))))))

(deftest test-forwards-received-block-to-peers-only-if-new
  (q/add-peer! db/db {:port test-port-2 :host "127.0.0.1"})
  (let [b (miner/mine (blocks/generate-block [(miner/coinbase)]))]
    (is (= b (:payload (handler {:message "submit_block" :payload b} sock-info))))
    (is (= 1 (q/chain-length @db/db)))

   :local-port test-port
   :outgoing-port 51283})

(def peer-requests (atom {}))
(defn peer-handler [req]
  (let [req (update req :body slurp)]
    (swap! peer-requests update (:uri req) conj req)
    {:status 200}))

(defn with-peer [f]
  (reset! peer-requests {})
  (let [p (jetty/run-jetty (routes peer-handler)
                           {:port test-port :join? false})]
    (try
      (f)
      (finally (do (.stop p)
                   (reset! peer-requests {}))))))

(defn with-db [f]
  (reset! db/db db/empty-db)
