         (.toByteArray baos))))
 
   (check
-    [model id result]
+    [this model result]
     (if-let [block (get model id)]
-      (bytes= (.toBuffer ^PersistentBytes @block) result)
-      (nil? result))))
-
-
-(defop :open-range
+      (is (bytes= (.toBuffer ^PersistentBytes @block) result))
+      (is (nil? result)))))
+
+
+(defop OpenBlockRange
+  [id start end]
 
   (gen-args
     [blocks]

                           (sort)
                         (:limit query)
                           (take (:limit query)))]
      (and (is (sequential? result))
           (is (= (count result) (count expected-ids)))
           (is (every? #(check-op model (cons :stat %))
                       (map vector expected-ids result)))))))


(defop :get

  (gen-args choose-id)

  (check
    [model id result]
    (if-let [block (get model id)]
      (do
        (is (some? (:id result)))
        (is (integer? (:size result)))
        (is (= id (:id result)))
        (is (= (:size block) (:size result))))
      (nil? result))))


(defop :put!

  (gen-args choose-block)

  (check
    [model block result]
    (= block result))

  (update
    [model block]
    (assoc model (:id block) block)))


(defop :delete!

  (gen-args choose-id)

  (check
    [model id result]
    (if (contains? model id)
      (true? result)
      (false? result)))

  (update
    [model id]
    (dissoc model id)))


(defop :get-batch

  (gen-args
    [blocks]
    (gen/set (choose-id blocks)))

  (check
    [model ids result]
    (and (is (coll? result))
         (is (= (set (keep model ids))
                (set result))))))


(defop :put-batch!

  (gen-args
    [blocks]
    (gen/set (choose-block blocks)))

  (check
    [model blocks result]
    (and (coll? result)
         (= (set blocks) (set result))))

  (update
    [model blocks]
    (into model (map (juxt :id identity) blocks))))


(defop :delete-batch!

  (gen-args
    [blocks]
    (gen/set (choose-id blocks)))

  (check
    [model ids result]
    (and (set? result)
         (= result (set (filter (set ids) (keys model))))))

  (update
    [model ids]
    (apply dissoc model ids)))


(defop :erase!!

  (apply
    [store _]
    (block/erase!! store))

  (update
    [model _]
    (empty model)))


(defop :scan

  (gen-args
    [_]
    (gen/elements
      [nil
       (fn scan-pred
         [stat]
         (< (:size stat) 256))]))

  (check
    [model p result]
    (let [blocks (cond->> (vals model) p (filter p))]
      (and (= (count blocks) (:count result))
           (= (reduce + (map :size blocks)) (:size result))
           (map? (:sizes result))
           (every? integer? (keys (:sizes result)))
           (= (count blocks) (reduce + (vals (:sizes result))))
           (every? (partial sum/probably-contains? result) (map :id blocks))))))


(defop :open

  (gen-args choose-id)

  (apply
    [store id]
    (when-let [block (block/get store id)]
      (let [baos (java.io.ByteArrayOutputStream.)]
        (with-open [content (block/open block)]

    [multihash.core :as multihash]
    [multihash.digest :as digest]
    [puget.color.ansi :as ansi]
    [puget.printer :as puget]
    [test.carly.core :as carly :refer [defop]])
  (:import
    blocks.data.Block
    blocks.data.PersistentBytes
