   (is  (= {:message "block_info" :payload sample-block}
           (:body (get-req (str "/blocks/" (get-in sample-block [:header :hash])))))))
 
-(deftest test-get-latest-block
-  (swap! db/block-chain conj sample-block)
+(deftest test-get-latest-block (swap! db/block-chain conj sample-block)
   (is  (= {:message "latest_block" :payload sample-block}
           (:body (get-req "/latest_block")))))
 
 (deftest test-get-block-height
-  (is  (= {:message "block_height" :payload 1}
-          (:body (get-req "/block_height")))))
+  (is (= 1 (pc/block-height {:host "localhost" :port "9292"}))))
 
 (deftest test-get-block-info
   (swap! db/block-chain conj sample-block)

  (f)
  (server/stop!))

(def init-db (-> db/empty-db
                 (q/add-block sample-block)))

(defn with-db [f]
  (reset! db/db init-db)
  (reset! db/peers #{})
  (reset! db/transaction-pool #{})
  (reset! db/block-chain @chain)
  (f)
  (reset! db/db init-db)
  (reset! db/peers #{})
  (reset! db/transaction-pool #{})
  (reset! db/block-chain @chain))

(use-fixtures :once with-server)
(use-fixtures :each with-db)

          (:body (get-req "/blocks")))))

(deftest test-submitting-invalid-block-returns-validation-errors
  (let [resp (post-req "/blocks" (update-in next-block [:transactions 0 :outputs 0 :amount] inc))]
    (is (= "block-rejected" (:message (:body resp))))
    (is (= 400 (:status resp)))
    (is (= (sort ["Block's coinbase transaction is malformed or has incorrect amount."])
           (sort (:payload (:body resp)))))))

(deftest test-getting-blocks-since-height
  (miner/mine-and-commit-db)
  (miner/mine-and-commit-db)
  (is (= (map q/bhash (drop 1 (reverse (q/longest-chain @db/db))))
         (pc/blocks-since {:host "localhost" :port "9292"}
                          (q/bhash (last (q/longest-chain @db/db)))))))
