Public Vars

Back

Throwable->map (clj)

(source)

function

(Throwable->map o)
Constructs a data representation for a Throwable with keys: :cause - root cause message :phase - error phase :via - cause chain, with cause keys: :type - exception class symbol :message - exception message :data - ex-data :at - top stack element :trace - root cause stack elements

Examples

fluree/db
(ns fluree.db.json-ld.credential-test
  (:require [fluree.db.json-ld.credential :as cred]
            [clojure.core.async :as async]
            #?(:clj [clojure.test :as t :refer [deftest testing is]]
               :cljs [cljs.test :as t :refer [deftest testing is] :include-macros true])
            [fluree.db.json-ld.api :as fluree]
            [fluree.db.test-utils :as test-utils]
            [fluree.db.did :as did]))

       (testing "verify incorrect signature"
         (let [wrong-cred (assoc example-credential "credentialSubject" {"@context" {"a" "http://a.com/"} "a:foo" "DIFFERENT!"})]
           (is (= "Verification failed."
                  (-> (async/<!! (cred/verify wrong-cred))
                      (Throwable->map)
                      (:cause))))))

           query {"@context" context
                  "select"   {(:id auth) ["*"]}}]
       (is (= [{"id" "ct:open", "ct:foo" "bar"}]
              @(fluree/query db0 {"@context" context
                                  "select"   {"ct:open" ["*"]}}))
           "can see everything when no identity is asserted")
       (is (= "Applying policy without a role is not yet supported."
              (-> @(fluree/query db0 (async/<!! (cred/generate {"@context" context
                                                                "select"   {"open" ["*"]}}
                                                               (:private auth))))
                  (Throwable->map)
                  :cause))
           "cannot see anything before policies are mapped to identities")
       (is (= [root-user]
              @(fluree/query db1 query)))
       (is (= [{"id" (:id auth) "ct:name" "D" "ct:favnums" [2 3 4 5 6] "f:role" {"id" "role:cool"}}]
              @(fluree/query db2 query))
           "modify transaction in credential")

               {"f:t"       3,
                "f:assert"  [{"ct:name" "D", "ct:favnums" [4 5 6], :id (:id auth)}],
                "f:retract" [{"ct:name" "Daniel", "ct:favnums" 1, :id (:id auth)}]}]
              @(fluree/history ledger (async/<!! (cred/generate {:context context
                                                                 :history (:id auth)
                                                                 :t {:from 1}}
                                                                (:private auth)))))
           "history query credential - allowing access")
       (is (= "Subject identity does not exist: \"did:fluree:TfHgFTQQiJMHaK1r1qxVPZ3Ridj9pCozqnh\""
              (-> @(fluree/history ledger (async/<!! (cred/generate {:history (:id auth) :t {:from 1}} (:private pleb-auth))))
                  (Throwable->map)
                  (:cause)))
           "history query credential - forbidding access"))))
fluree/ledger
(ns fluree.db.ledger.smart-functions-test
  (:require [clojure.test :refer :all]
            [clojure.core.async :refer [<!!]]
            [fluree.db.test-helpers :as test]
            [fluree.db.api :as fdb]
            [fluree.db.util.json :as json]
            [fluree.db.query.http-signatures :as http-sig]
            [byte-streams :as bs]
            [org.httpkit.client :as http]))

      (is (= "Unknown function: clojure.core/str"
             (-> chat-tx-resp test/safe-Throwable->map :cause)))))

      (is (= "Unknown function: clojure.core/+"
             (-> chat-tx-resp test/safe-Throwable->map :cause))))))

(deftest predicate-spec-non-negative-test
  (let [ledger        (test/rand-ledger test/ledger-chat)
        _             (test/transact-schema ledger "chat.edn")
        _             (test/transact-schema ledger "chat-preds.edn")
        non-neg-spec  [{:_id  "_fn$nonNeg",
                        :name "nonNegative?",
                        :doc  "Checks that a value is non-negative",
                        :code "(<= 0 (?o))"}
                       {:_id  ["_predicate/name" "person/favNums"],
                        :spec ["_fn$nonNeg"]}]
        add-spec-resp (<!! (fdb/transact-async (:conn test/system)
                                               ledger non-neg-spec))
        test-spec     [{:_id "person", :handle "aJay", :favNums [12 -4 57]}]
        test-resp     (-> (<!! (fdb/transact-async (:conn test/system)
                                                   ledger test-spec))
                          test/safe-Throwable->map :cause)]

(deftest full-name-req-test
  (testing "missing fullName is rejected"
    (let [ledger         (test/rand-ledger test/ledger-chat)
          _              (test/transact-schema ledger "chat.edn")
          _              (test/transact-schema ledger "chat-preds.edn")
          full-name-spec [{:_id     ["_collection/name" "person"]
                           :spec    ["_fn$fullNameReq"]
                           :specDoc "A person is required to have a fullName."}
                          {:_id  "_fn$fullNameReq",
                           :name "fullNameReq",
                           :code "(boolean (get (query (str \"{\\\"select\\\": [\\\"*\\\"], \\\"from\\\": \" (?sid) \"}\")) \"person/fullName\"))"}]
          add-spec-resp  (<!! (fdb/transact-async (:conn test/system) ledger
                                                  full-name-spec))
          test-spec      [{:_id "person", :handle "noFullName"}]
          test-resp      (-> (<!! (fdb/transact-async (:conn test/system) ledger
                                                      test-spec))
                             test/safe-Throwable->map :cause)]

  (testing "fullName can't be retracted"
    (let [ledger         (test/rand-ledger test/ledger-chat)
          _              (test/transact-schema ledger "chat.edn")
          _              (test/transact-schema ledger "chat-preds.edn")
          full-name-spec [{:_id     ["_collection/name" "person"]
                           :spec    ["_fn$fullNameReq"]
                           :specDoc "A person is required to have a fullName."}
                          {:_id  "_fn$fullNameReq",
                           :name "fullNameReq",
                           :code "(boolean (get (query (str \"{\\\"select\\\": [\\\"*\\\"], \\\"from\\\": \" (?sid) \"}\")) \"person/fullName\"))"}]
          add-spec-resp  (<!! (fdb/transact-async (:conn test/system) ledger
                                                  full-name-spec))
          add-person     [{:_id "person", :handle "deleteMe", :fullName "To Be Deleted"}]
          _              (<!! (fdb/transact-async (:conn test/system) ledger add-person))
          test-spec-1    [{:_id ["person/handle" "deleteMe"] :fullName nil}]
          test-resp-1    (-> (<!! (fdb/transact-async (:conn test/system) ledger test-spec-1))
                             test/safe-Throwable->map :cause)
          test-spec-2    [{:_id ["person/handle" "deleteMe"] :_action "delete"}]
          test-resp-2    (<!! (fdb/transact-async (:conn test/system) ledger test-spec-2))]

    (testing "permissioned transaction"
      (let [jdoeChat     [{:_id    "chat$1", :message "Hey there!"
                           :person ["person/handle" "jdoe"]}]
            addOther     (-> (<!! (fdb/transact-async (:conn test/system) ledger
                                                      jdoeChat zsmith))
                             test/safe-Throwable->map
                             :cause)
            addOwn       (<!! (fdb/transact-async (:conn test/system) ledger
                                                  jdoeChat jdoe))
            chat$1       (get (:tempids addOwn) "chat$1")
            jdoeChatEdit [{:_id chat$1 :message "Attempting to edit"}]
            editOther    (-> (<!! (fdb/transact-async (:conn test/system) ledger
                                                      jdoeChatEdit zsmith))
                             test/safe-Throwable->map
                             :cause)
            editOwn      (<!! (fdb/transact-async (:conn test/system) ledger
                                                  jdoeChatEdit jdoe))]
fluree/ledger
(ns fluree.db.ledger.docs.schema.collections
  (:require [clojure.test :refer :all]
            [fluree.db.test-helpers :as test]
            [fluree.db.ledger.docs.getting-started.basic-schema :as basic]
            [fluree.db.api :as fdb]
            [clojure.core.async :as async]
            [clojure.string :as str]))


(deftest collection-upsert
  (testing "Attempt to upsert _collection/name, then set upsert")
  (let [txn [{:_id "_collection", :name "_user", :doc "The user's collection"}]
        res (-> (async/<!! (fdb/transact-async (basic/get-conn)
                                               test/ledger-chat
                                               txn
                                               {:timeout 120000}))
                test/safe-Throwable->map
                :cause)
        set-upsert [{:_id ["_predicate/name" "_collection/name"], :upsert true}]
        upsertRes  (async/<!! (fdb/transact-async (basic/get-conn)
                                                  test/ledger-chat
                                                  set-upsert
                                                  {:timeout 120000}))
        attemptToUpsertRes  (async/<!! (fdb/transact-async (basic/get-conn) test/ledger-chat txn))]
fluree/ledger
(ns fluree.db.ledger.docs.identity.auth
  (:require [clojure.test :refer :all]
            [fluree.db.test-helpers :as test]
            [fluree.db.ledger.docs.getting-started.basic-schema :as basic]
            [fluree.db.api :as fdb]
            [fluree.db.api.auth :as fdb-auth]
            [clojure.core.async :as async]
            [clojure.string :as str]))


(deftest createAuthority
  ;; TODO - sometimes fails, does this have to do with padding in crypto?
  (let [{:keys [private public id]} (fdb-auth/new-private-key)
        opts          {:timeout 240000}
        addAuth       [{:_id "_auth$authority"
                        :id  id}
                       {:_id       "_auth"
                        :id        "testAuth"
                        :authority ["_auth$authority"]
                        :roles     ["_role$editUser"]}
                       {:_id   "_role$editUser"
                        :id    "editUser"
                        :rules ["_rule$editPerson"]}
                       {:_id               "_rule$editPerson"
                        :id                "editPerson"
                        :collection        "person"
                        :collectionDefault true
                        :fns               [["_fn/name" "true"]]
                        :ops               ["all"]}]
        addAuthResp   (async/<!! (fdb/transact-async
                                   (basic/get-conn)
                                   test/ledger-chat
                                   addAuth
                                   opts))
        addPerson     [{:_id "person" :handle "authority"}]
        opts-with-auth (merge opts {:auth        "testAuth"
                                    :private-key private})
        addPersonResp (async/<!! (fdb/transact-async
                                   (basic/get-conn)
                                   test/ledger-chat
                                   addPerson
                                   opts-with-auth))
        testResp      (-> (async/<!! (fdb/transact-async
                                       (basic/get-conn)
                                       test/ledger-chat
                                       addPerson
                                       {:auth "testAuth"}))
                          test/safe-Throwable->map
                          :cause)]
    (is (= 200 (:status addAuthResp)))
fluree/ledger
(ns fluree.db.ledger.docs.examples.supply-chain
  (:require [clojure.test :refer :all]
            [fluree.db.test-helpers :as test]
            [fluree.db.ledger.docs.getting-started.basic-schema :as basic]
            [fluree.db.api :as fdb]
            [clojure.core.async :as async]
            [clojure.java.io :as io]
            [clojure.tools.reader.edn :as edn]
            [clojure.string :as str]))

;; Invalid transaction - Block 10
(deftest invalid-txns-10
  (let [addGrowerToPO      [{:_id ["purchaseOrder/id" "123"], :grower ["organization/name" "McDonald's Farm"]}]
        addGrowerToPOResp  (-> (async/<!! (fdb/transact-async (basic/get-conn) test/ledger-supplychain addGrowerToPO farm-opts))
                               test/safe-Throwable->map
                               :cause)
        createShipment     [{:_id                     "shipment$1",
                             :name                    "123BeanShip",
                             :sentBy                  ["organization/name" "McDonald's Farm"],
                             :intendedRecipient       ["organization/name" "The Roastery"],
                             :intendedReceiptLocation "Miami, FL",
                             :sentLocation            "McDonLand",
                             :itemDescription         "Got the beans harvested!",
                             :id                      "growShip123",
                             :sentDate                "#(now)"}
                            {:_id ["purchaseOrder/id" "123"], :shipments ["shipment$1"]}]
        createShipmentResp (-> (async/<!! (fdb/transact-async (basic/get-conn) test/ledger-supplychain createShipment cafe-opts))
                               test/safe-Throwable->map
                               :cause)]