             [block-chain.http :as server]
             [block-chain.db :as db]
             [block-chain.queries :as q]
+            [block-chain.peer-client :as pc]
             [block-chain.blocks :as blocks]
-            [clojure.math.numeric-tower :as math]
             [block-chain.wallet :as wallet]
             [block-chain.miner :as miner]
             [block-chain.utils :refer :all]


(def base-url "http://localhost:9292")

(def easy-difficulty (hex-string (math/expt 2 248)))
(def chain (atom []))

(def key-a (wallet/generate-keypair 512))
(def key-b (wallet/generate-keypair 512))

(def a-coinbase (miner/coinbase (:address key-a)))
(def a-paid (blocks/generate-block [a-coinbase]
                                  {:target easy-difficulty}))

(miner/mine-and-commit chain a-paid)
(def sample-block (first @chain))

(def next-block (miner/mine
                 (blocks/generate-block [(miner/coinbase (:address key-a))]
                                        {:target easy-difficulty
                                         :blocks @chain})))

;; A pays B 5
(def sample-transaction (miner/generate-payment key-a
                                         (:address key-b)
                                         15
                                         @chain))

(defn post-req [path data]
  (update

  (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)
  (is  (= {:message "latest_block" :payload sample-block}
          (:body (get-req "/latest_block")))))

(deftest test-get-block-height
  (is (= 1 (pc/block-height {:host "localhost" :port "9292"}))))

(deftest test-get-block-info
  (swap! db/block-chain conj sample-block)
