smaller commit :)
This commit is contained in:
1 parent
bce64fc8f6
commit
d4bc2490ff
8 files changed
+51
-18
No files matched your search
@@ -7,7 +7,6 @@
|
|||||||
[skirmish.order] ;; for spec side effect
|
[skirmish.order] ;; for spec side effect
|
||||||
[skirmish.rest.util :refer [build-response build-response-body]]
|
[skirmish.rest.util :refer [build-response build-response-body]]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[kinsky.client]
|
|
||||||
[slingshot.slingshot :refer [try+ throw+]]
|
[slingshot.slingshot :refer [try+ throw+]]
|
||||||
[clojure.core.async :refer [chan go-loop close! <! sub]]))
|
[clojure.core.async :refer [chan go-loop close! <! sub]]))
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
(:require [org.httpkit.server :refer [run-server]]
|
(:require [org.httpkit.server :refer [run-server]]
|
||||||
[compojure.handler :refer [api]]
|
[compojure.handler :refer [api]]
|
||||||
[skirmish.util :refer [block-thread]]
|
[skirmish.util :refer [block-thread]]
|
||||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
|
||||||
[skirmish.bookkeeper.bookkeeper :refer [create-routes-for-bookkeeper]]
|
[skirmish.bookkeeper.bookkeeper :refer [create-routes-for-bookkeeper]]
|
||||||
[ring.middleware.cors :refer [wrap-cors]]))
|
[ring.middleware.cors :refer [wrap-cors]]))
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
(ns skirmish.exchange.core
|
(ns skirmish.exchange.core
|
||||||
(:require [skirmish.util :refer [block-thread]]
|
(:require [skirmish.util :refer [block-thread]]
|
||||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
||||||
[skirmish.exchange.exchange :refer [create-exchange-for-security empty-book]]
|
[skirmish.exchange.exchange :refer [create-exchange-for-security empty-book]]))
|
||||||
[kinsky.async]
|
|
||||||
[kinsky.client]))
|
|
||||||
|
|
||||||
(defn create-exchange-for [exchange-api]
|
(defn create-exchange-for [exchange-api]
|
||||||
(let [initial-book empty-book
|
(let [initial-book empty-book
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
(:require [org.httpkit.server :refer [run-server]]
|
(:require [org.httpkit.server :refer [run-server]]
|
||||||
[compojure.handler :refer [api]]
|
[compojure.handler :refer [api]]
|
||||||
[skirmish.util :refer [block-thread]]
|
[skirmish.util :refer [block-thread]]
|
||||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
|
||||||
[skirmish.exchange-gateway.exchange-gateway :refer [create-routes-for-exchange]]
|
[skirmish.exchange-gateway.exchange-gateway :refer [create-routes-for-exchange]]
|
||||||
[ring.middleware.cors :refer [wrap-cors]]))
|
[ring.middleware.cors :refer [wrap-cors]]))
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,31 @@
|
|||||||
:db/cardinality :db.cardinality/one
|
:db/cardinality :db.cardinality/one
|
||||||
:db/unique :db.unique/identity
|
:db/unique :db.unique/identity
|
||||||
:db/doc "The sec id."}
|
:db/doc "The sec id."}
|
||||||
|
{
|
||||||
|
:db/ident :skirmish.security/type
|
||||||
|
:db/valueType :db.type/keyword
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/unique :db.unique/identity
|
||||||
|
:db/doc "The type of security. For instance :equity or :currency."}
|
||||||
|
|
||||||
|
{
|
||||||
|
:db/ident :skirmish.security/description
|
||||||
|
:db/valueType :db.type/string
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/unique :db.unique/identity
|
||||||
|
:db/doc "The description of the currency. Please be verbose."}
|
||||||
|
{
|
||||||
|
:db/ident :skirmish.security/emitter
|
||||||
|
:db/valueType :db.type/string
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/unique :db.unique/identity
|
||||||
|
:db/doc "The public key of the emmiter. This is not yet supported."}
|
||||||
|
{
|
||||||
|
:db/ident :skirmish.security/symbol
|
||||||
|
:db/valueType :db.type/string
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/unique :db.unique/identity
|
||||||
|
:db/doc "The symbol of the security for pretty printing."}
|
||||||
{
|
{
|
||||||
:db/ident :skirmish.security/interest-rate
|
:db/ident :skirmish.security/interest-rate
|
||||||
:db/valueType :db.type/long
|
:db/valueType :db.type/long
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
[skirmish.util :refer [block-thread]]
|
[skirmish.util :refer [block-thread]]
|
||||||
[slingshot.slingshot :refer [try+ throw+]]
|
[slingshot.slingshot :refer [try+ throw+]]
|
||||||
[compojure.route :refer [not-found]]
|
[compojure.route :refer [not-found]]
|
||||||
[skirmish.middleware.core :refer [create-exchange-apis-for]]
|
|
||||||
[skirmish.exchange-gateway.exchange-gateway :refer [create-routes-for-exchange]]
|
[skirmish.exchange-gateway.exchange-gateway :refer [create-routes-for-exchange]]
|
||||||
[skirmish.rest.util :refer [build-response get-body]]
|
[skirmish.rest.util :refer [build-response get-body]]
|
||||||
[skirmish.ledger.accounts]
|
[skirmish.ledger.accounts]
|
||||||
@@ -52,7 +51,12 @@
|
|||||||
|
|
||||||
|
|
||||||
(s/def ::security (s/cat :sec-id keyword?
|
(s/def ::security (s/cat :sec-id keyword?
|
||||||
:interest-rate nat-int?))
|
:interest-rate nat-int?
|
||||||
|
:type #{:equity :currency}
|
||||||
|
:description string?
|
||||||
|
:emitter string?
|
||||||
|
:symbol (s/? string?)))
|
||||||
|
|
||||||
|
|
||||||
(defn get-new-security [raw-securities]
|
(defn get-new-security [raw-securities]
|
||||||
(if (s/valid? ::security raw-securities)
|
(if (s/valid? ::security raw-securities)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
(ns skirmish.middleware.core
|
(ns skirmish.middleware.core
|
||||||
(:require [clojure.core.async :as async]
|
(:require [clojure.core.async :as async]
|
||||||
[skirmish.exchange.exchange :refer [empty-book create-exchange-for-security]] ;; remove this import.
|
|
||||||
[kinsky.async]
|
[kinsky.async]
|
||||||
[kinsky.client]))
|
[kinsky.client]))
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,21 @@
|
|||||||
|
|
||||||
(def sec->hash-set #(apply hash-set %))
|
(def sec->hash-set #(apply hash-set %))
|
||||||
|
|
||||||
|
(def mock-securities [[:sec-1 100 :equity "first equity" "rot13"]
|
||||||
|
[:sec-2 200 :equity "second equity" "rot13"]
|
||||||
|
[:sec-3 300 :equity "third equity" "rot13"]])
|
||||||
|
|
||||||
|
(def mock-currencies [[:zimbabwean-dollar 1000000 :currency "zimbabwean dollar" "rot13" "zd"]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn create-some-securities [conn]
|
(defn create-some-securities [conn]
|
||||||
(let [cs (create-security conn)
|
(let [cs (create-security conn)
|
||||||
create-security-1 {:body (edn->stream [:sec-1 100]) :headers {"accept" "application/edn"}}
|
create-security-1 {:body (edn->stream (get mock-securities 0)) :headers {"accept" "application/edn"}}
|
||||||
create-security-2 {:body (edn->stream [:sec-2 200]) :headers {"accept" "application/edn"}}
|
create-security-2 {:body (edn->stream (get mock-securities 1)) :headers {"accept" "application/edn"}}
|
||||||
create-security-3 {:body (edn->stream [:sec-3 300]) :headers {"accept" "application/edn"}}
|
create-security-3 {:body (edn->stream (get mock-securities 2)) :headers {"accept" "application/edn"}}
|
||||||
create-security-4 {:body (edn->stream [:zimbabwean-dollar 1000000]) :headers {"accept" "application/edn"}}]
|
create-security-4 {:body (edn->stream (first mock-currencies)) :headers {"accept" "application/edn"}}]
|
||||||
(->> create-security-1 cs (s/assert ::ok))
|
(->> create-security-1 cs (s/assert ::ok))
|
||||||
(->> create-security-2 cs (s/assert ::ok))
|
(->> create-security-2 cs (s/assert ::ok))
|
||||||
(->> create-security-3 cs (s/assert ::ok))
|
(->> create-security-3 cs (s/assert ::ok))
|
||||||
@@ -67,15 +75,15 @@
|
|||||||
(facts "about the securities"
|
(facts "about the securities"
|
||||||
(fact "We should be able to create a security"
|
(fact "We should be able to create a security"
|
||||||
(let [conn (create-conn)
|
(let [conn (create-conn)
|
||||||
security [:new-currency 100]
|
security [:new-currency 100 :currency "currency for test" "rot13" "NC"]
|
||||||
request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
||||||
resp ((create-security conn) request)]
|
resp ((create-security conn) request)]
|
||||||
resp => (spec-check ::ok)
|
resp => (spec-check ::ok)
|
||||||
resp => (location? "/api/1/ledger/securities/new-currency"))) ;;
|
resp => (location? "/api/1/ledger/securities/new-currency")))
|
||||||
|
|
||||||
(fact "We should not be able to create a security that already exists"
|
(fact "We should not be able to create a security that already exists"
|
||||||
(let [conn (create-conn)
|
(let [conn (create-conn)
|
||||||
security [:new-currency 100]
|
security [:new-currency 100 :currency "currency for test" "rot13" "NC"]
|
||||||
request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
||||||
resp-1 ((create-security conn) request)
|
resp-1 ((create-security conn) request)
|
||||||
resp-2 ((create-security conn) request)]
|
resp-2 ((create-security conn) request)]
|
||||||
@@ -87,7 +95,7 @@
|
|||||||
|
|
||||||
(fact "we should be able to get-security if it does exists"
|
(fact "we should be able to get-security if it does exists"
|
||||||
(let [conn (create-conn)
|
(let [conn (create-conn)
|
||||||
security [:new-currency 100]
|
security [:new-currency 100 :currency "currency for test" "rot13" "NC"]
|
||||||
create-request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
create-request {:body (edn->stream security) :headers {"accept" "application/edn"}}
|
||||||
_ ((create-security conn) create-request)
|
_ ((create-security conn) create-request)
|
||||||
request {:route-params {:sec-id :new-currency} :headers {"accept" "application/edn"}}
|
request {:route-params {:sec-id :new-currency} :headers {"accept" "application/edn"}}
|
||||||
@@ -106,7 +114,8 @@
|
|||||||
(let [conn (create-conn)
|
(let [conn (create-conn)
|
||||||
request {:route-params {} :headers {"accept" "application/edn"}}
|
request {:route-params {} :headers {"accept" "application/edn"}}
|
||||||
empty-res ((get-available-securities conn) request)
|
empty-res ((get-available-securities conn) request)
|
||||||
create-security-1 {:body (edn->stream [:new-currency 100]) :headers {"accept" "application/edn"}}
|
new-currency [:new-currency 100 :currency "currency for test" "rot13" "NC"]
|
||||||
|
create-security-1 {:body (edn->stream new-currency) :headers {"accept" "application/edn"}}
|
||||||
_ ((create-security conn) create-security-1)
|
_ ((create-security conn) create-security-1)
|
||||||
one-res ((get-available-securities conn) request)]
|
one-res ((get-available-securities conn) request)]
|
||||||
empty-res => (spec-check ::ok)
|
empty-res => (spec-check ::ok)
|
||||||
|
|||||||
Reference in new issue
Block a user