going somewhere
This commit is contained in:
1 parent
b7af65b705
commit
d5c6360f88
12 files changed
+176
-41
No files matched your search
@@ -0,0 +1,6 @@
|
||||
(ns skirmish.ledger.core-test
|
||||
(:require [clojure.test :refer :all])
|
||||
(:require [skirmish.ledger.core :refer [get-amount-in-account]]))
|
||||
|
||||
(deftest get-amount-in-account-test)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[skirmish.ledger.core :refer :all]
|
||||
[skirmish.rest.util :refer [edn->stream]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[infix.macros :refer [infix]]
|
||||
[skirmish.ledger.accounts :refer [create-connection schema]]))
|
||||
|
||||
(defn spec-check [spec]
|
||||
@@ -99,14 +100,14 @@
|
||||
request {:route-params {:sec-id :new-currency} :headers {"accept" "application/edn"}}
|
||||
resp ((get-security conn) request)]
|
||||
resp => (spec-check ::ok)
|
||||
(body resp) => {:sec-id :new-currency
|
||||
:interest-rate 100
|
||||
:name nil
|
||||
:description nil
|
||||
(body resp) => {:sec-id :new-currency
|
||||
:interest-rate 100
|
||||
:name nil
|
||||
:description nil
|
||||
:number-of-decimal nil
|
||||
:symbol nil
|
||||
:type nil
|
||||
:volume 0}))
|
||||
:symbol nil
|
||||
:type nil
|
||||
:volume 0}))
|
||||
|
||||
(fact "we should not be able to get-security if it does not exists"
|
||||
(let [conn (create-conn)
|
||||
@@ -140,8 +141,8 @@
|
||||
(facts "about the emitting securities"
|
||||
(fact "should not work if invalid request"
|
||||
(let [conn (create-some-securities (create-conn))
|
||||
req-1 {:body (edn->stream [10 :not-a-string]) :route-params {:sec-id "sec-1"} :headers {"accept" "application/edn"}}
|
||||
req-2 {:body (edn->stream [-10 "foo"]) :route-params {:sec-id "sec-1"} :headers {"accept" "application/edn"}}
|
||||
req-1 {:body (edn->stream [10 :not-a-string]) :route-params {:sec-id "sec-1"} :headers {"accept" "application/edn"}}
|
||||
req-2 {:body (edn->stream [-10 "foo"]) :route-params {:sec-id "sec-1"} :headers {"accept" "application/edn"}}
|
||||
req-3 {:body (edn->stream [90 "account-id"]) :route-params {:sec-id "invalid-sec-id"} :headers {"accept" "application/edn"}}]
|
||||
((emit-securities conn) req-1) => (spec-check ::status-400)
|
||||
((emit-securities conn) req-2) => (spec-check ::status-400)
|
||||
@@ -175,7 +176,7 @@
|
||||
{:account-public-key "2-sec-1" :url "http://localhost:1604/api/1/ledger/accounts/2-sec-1"}
|
||||
{:account-public-key "2-sec-2" :url "http://localhost:1604/api/1/ledger/accounts/2-sec-2"}]]
|
||||
((get-available-accounts conn) req) => (spec-check ::ok)
|
||||
(-> ((get-available-accounts conn) req) body :accounts sec->hash-set) => (sec->hash-set expt)))
|
||||
(-> ((get-available-accounts conn) req) body :accounts sec->hash-set) => (sec->hash-set expt)))
|
||||
|
||||
(fact "we should be able to get account"
|
||||
(let [conn (create-some-securities-and-accounts (create-conn))
|
||||
@@ -198,9 +199,59 @@
|
||||
((get-account conn) req) => (spec-check ::status-404))))
|
||||
|
||||
|
||||
(facts "about interest computation"
|
||||
(fact "about very basic interest rates"
|
||||
(let [amount 1000
|
||||
interest-rate (* 10 100) ;; daily 10% interest rates
|
||||
negative-interest-rate (- interest-rate)
|
||||
start #inst"2020-09-05T00:00:00.000-00:00"
|
||||
start+1d #inst"2020-09-06T00:00:00.000-00:00"
|
||||
start+2d #inst"2020-09-07T00:00:00.000-00:00"]
|
||||
(compute-simple-face-value amount interest-rate start start) => (roughly amount)
|
||||
(compute-simple-face-value amount interest-rate start start+1d) => (roughly 1105.1670808)
|
||||
(compute-simple-face-value amount interest-rate start start+2d) => (roughly 1221.3942766)
|
||||
(compute-simple-face-value amount negative-interest-rate start start+2d) => (roughly 818.7250672)
|
||||
(compute-simple-face-value amount 0 start start+2d) => (roughly amount)))
|
||||
(fact "split-interest-rates"
|
||||
(let [d-1d #inst"2020-09-04T00:00:00.000-00:00"
|
||||
d-½d #inst"2020-09-04T12:00:00.000-00:00"
|
||||
d #inst"2020-09-05T00:00:00.000-00:00"
|
||||
d+½d #inst"2020-09-05T12:00:00.000-00:00"
|
||||
d+1d #inst"2020-09-06T00:00:00.000-00:00"
|
||||
d+1½d #inst"2020-09-06T12:00:00.000-00:00"
|
||||
d+2d #inst"2020-09-07T00:00:00.000-00:00"
|
||||
d+2½d #inst"2020-09-07T12:00:00.000-00:00"
|
||||
d+3d #inst"2020-09-08T00:00:00.000-00:00"
|
||||
d+3½d #inst"2020-09-08T12:00:00.000-00:00";;
|
||||
interest-rates [[10 d] [15 d+1d] [20 d+2d]]]
|
||||
(split-interest-rates interest-rates d+½d d+3d) => [[10 d+½d d+1d] [15 d+1d d+2d] [20 d+2d d+3d]]
|
||||
(split-interest-rates interest-rates d+3d d+3½d) => [[20 d+3d d+3½d]]
|
||||
(split-interest-rates interest-rates d-1d d-½d) => [[0 d-1d d-½d]]
|
||||
(split-interest-rates interest-rates d d+½d) => [[10 d d+½d]]
|
||||
(split-interest-rates interest-rates d+2½d d+2½d) => [[20 d+2½d d+2½d]]))
|
||||
(fact "compute-face-value"
|
||||
(let [d-1d #inst"2020-09-04T00:00:00.000-00:00"
|
||||
d-½d #inst"2020-09-04T12:00:00.000-00:00"
|
||||
d #inst"2020-09-05T00:00:00.000-00:00"
|
||||
d+½d #inst"2020-09-05T12:00:00.000-00:00"
|
||||
d+1d #inst"2020-09-06T00:00:00.000-00:00"
|
||||
d+1½d #inst"2020-09-06T12:00:00.000-00:00"
|
||||
d+2d #inst"2020-09-07T00:00:00.000-00:00"
|
||||
d+2½d #inst"2020-09-07T12:00:00.000-00:00"
|
||||
d+3d #inst"2020-09-08T00:00:00.000-00:00"
|
||||
d+3½d #inst"2020-09-08T12:00:00.000-00:00"
|
||||
amount 10000000
|
||||
interest-rates [[10 d] [15 d+1d] [20 d+2d]]]
|
||||
(compute-face-value amount interest-rates d+½d d+½d) => amount
|
||||
(compute-face-value amount interest-rates d-1d d-½d) => amount
|
||||
(compute-face-value amount interest-rates d-1d d+3d) => 10045101)))
|
||||
|
||||
;(split-interest-rates interest-rates d+3d d+½d) => [[10 d d+½d]])))
|
||||
|
||||
|
||||
;; TOD
|
||||
|
||||
|
||||
;; TODO
|
||||
|
||||
;; 4. transfer sec from one account to the other.
|
||||
;; 5. account for interest
|
||||
|
||||
Reference in new issue
Block a user