         "The validation message indicates the error")))
 
 (deftest a-purchase-creates-a-lot-record
-  (let [context (serialization/realize storage-spec purchase-context)
-        ira (find-account context "IRA")
-        commodity (find-commodity context "AAPL")
-        result (trading/buy storage-spec {:commodity-id (:id commodity)
+  (let [context (serialization/realize (env :db) purchase-context)
+        ira (find-account context "IRA")
+        commodity (find-commodity context "AAPL")
+        _ (trading/buy (env :db) {:commodity-id (:id commodity)
                                      :account-id (:id ira)
                                      :trade-date (t/local-date 2016 1 2)
                                      :shares 100M

        inv-exp (->> context
                     :accounts
                     (filter #(= "Investment Expenses" (:name %)))
                     first)
        commodity (find-commodity context "AAPL")
        result (trading/buy storage-spec (-> context
                                             purchase-attributes
                                             (assoc :fee 5M
                                                    :fee-account-id (:id inv-exp))))]
    (is (= 995M (:quantity (accounts/reload storage-spec ira)))
        "The investment account balance reflects the fee")
    (is (= 5M (:quantity (accounts/reload storage-spec inv-exp)))
        "The investment expense account reflects the fee")))

(deftest purchase-requires-a-trade-date
  (let [context (serialization/realize storage-spec purchase-context)
        ira (find-account context "IRA")
        commodity (find-commodity context "AAPL")
        result (trading/buy storage-spec (-> context
                                             (purchase-attributes)
                                             (dissoc :trade-date)))]
    (is (= ["Trade date is required"]

                                "Short-term Capital Gains"
                                "Long-term Capital Loss"
                                "Short-term Capital Loss")
        _ (trading/buy (env :db) {:trade-date (t/local-date 2015 3 2)
                                          :account-id (:id ira)
                                          :commodity-id (:id commodity)
                                          :shares 100M
                                          :value 1000M})
        _ (trading/buy (env :db) {:trade-date (t/local-date 2016 3 2)
                                          :account-id (:id ira)
                                          :commodity-id (:id commodity)
                                          :shares 100M
                                          :value 2000M})
        _ (trading/sell (env :db) {:trade-date (t/local-date 2017 3 2)
                                      :account-id (:id ira)
                                      :commodity-id (:id commodity)
                                      :shares 50M
