Skip to content

Commit

Permalink
Merge pull request #529 from fluree/fix/default-context-at-t-after-load
Browse files Browse the repository at this point in the history
Fix default-context-at-t after load
  • Loading branch information
cap10morgan authored Jul 14, 2023
2 parents 938d2ef + 3197523 commit a1f0e7b
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 139 deletions.
3 changes: 2 additions & 1 deletion src/fluree/db/json_ld/reify.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@
(= -1 t-new)
(into commit-data/commit-schema-flakes)))
ecount* (assoc ecount const/$_predicate pid
const/$_default sid)]
const/$_default sid
const/$_shard @last-sid)]
(when (empty? all-flakes)
(commit-error "Commit has neither assertions or retractions!"
commit-metadata))
Expand Down
3 changes: 2 additions & 1 deletion src/fluree/db/ledger/json_ld.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
(jld-commit/commit ledger db* opts*)))

(defn default-context
"Returns default context at t (must be internal negative value)"
"Returns default context at t (should be an ISO datetime string or an integer
t value)"
[ledger t]
(go-try
(let [latest-db (db ledger nil)
Expand Down
180 changes: 90 additions & 90 deletions test/fluree/db/query/history_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -680,93 +680,93 @@
(with-redefs [fluree.db.util.core/current-time-iso (constantly "1970-01-01T00:12:00.00000Z")]
(testing "history commit details on a loaded file ledger"
(with-tmp-dir storage-path
(let [ledger-name "loaded-history-file"
conn @(fluree/connect
{:method :file
:storage-path storage-path
:defaults
{:context test-utils/default-context
:context-type :keyword
:did (did/private->did-map
test-utils/default-private-key)}})
ledger @(fluree/create conn ledger-name
{:defaultContext
["" {:ex "http://example.org/ns/"}]})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-1"
:ex/y "bar-1"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-2"
:ex/y "bar-2"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-3"
:ex/y "bar-3"})
_ @(test-utils/transact ledger {:id :ex/cat
:ex/x "foo-cat"
:ex/y "bar-cat"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-cat"
:ex/y "bar-cat"}
{:message "meow"})
loaded-ledger (test-utils/retry-load conn ledger-name 100)]
(is (pred-match?
[#:f{:assert [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:commit {"https://www.w3.org/2018/credentials#issuer"
{:id test-utils/did?}
:f/address test-utils/address?
:f/alias ledger-name
:f/branch "main"
:f/defaultContext {:id test-utils/context-id?}
:f/data #:f{:address test-utils/address?
:assert [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:flakes 65
:previous {:id test-utils/db-id?}
:retract [{:ex/x "foo-2"
:ex/y "bar-2"
:id :ex/alice}]
:size pos-int?
:t 3}
:f/previous {:id test-utils/commit-id?}
:f/time 720000
:f/v 0
:id test-utils/commit-id?}
:retract [{:ex/x "foo-2"
:ex/y "bar-2"
:id :ex/alice}]
:t 3}
#:f{:assert [{:ex/x "foo-cat"
:ex/y "bar-cat"
:id :ex/alice}]
:commit {"https://www.w3.org/2018/credentials#issuer"
{:id test-utils/did?}
:f/address test-utils/address?
:f/alias ledger-name
:f/branch "main"
:f/defaultContext {:id test-utils/context-id?}
:f/data #:f{:address test-utils/address?
:assert [{:ex/x "foo-cat"
:ex/y "bar-cat"
:id :ex/alice}]
:flakes 104
:previous {:id test-utils/db-id?}
:retract [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:size pos-int?
:t 5}
:f/message "meow"
:f/previous {:id test-utils/commit-id?}
:f/time 720000
:f/v 0
:id test-utils/commit-id?}
:retract [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:t 5}]
@(fluree/history loaded-ledger {:history :ex/alice
:commit-details true
:t {:from 3}}))))))))
(let [ledger-name "loaded-history-file"
conn @(fluree/connect
{:method :file
:storage-path storage-path
:defaults
{:context test-utils/default-context
:context-type :keyword
:did (did/private->did-map
test-utils/default-private-key)}})
ledger @(fluree/create conn ledger-name
{:defaultContext
["" {:ex "http://example.org/ns/"}]})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-1"
:ex/y "bar-1"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-2"
:ex/y "bar-2"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-3"
:ex/y "bar-3"})
_ @(test-utils/transact ledger {:id :ex/cat
:ex/x "foo-cat"
:ex/y "bar-cat"})
_ @(test-utils/transact ledger {:id :ex/alice
:ex/x "foo-cat"
:ex/y "bar-cat"}
{:message "meow"})
loaded-ledger (test-utils/retry-load conn ledger-name 100)]
(is (pred-match?
[#:f{:assert [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:commit {"https://www.w3.org/2018/credentials#issuer"
{:id test-utils/did?}
:f/address test-utils/address?
:f/alias ledger-name
:f/branch "main"
:f/defaultContext {:id test-utils/context-id?}
:f/data #:f{:address test-utils/address?
:assert [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:flakes 65
:previous {:id test-utils/db-id?}
:retract [{:ex/x "foo-2"
:ex/y "bar-2"
:id :ex/alice}]
:size pos-int?
:t 3}
:f/previous {:id test-utils/commit-id?}
:f/time 720000
:f/v 0
:id test-utils/commit-id?}
:retract [{:ex/x "foo-2"
:ex/y "bar-2"
:id :ex/alice}]
:t 3}
#:f{:assert [{:ex/x "foo-cat"
:ex/y "bar-cat"
:id :ex/alice}]
:commit {"https://www.w3.org/2018/credentials#issuer"
{:id test-utils/did?}
:f/address test-utils/address?
:f/alias ledger-name
:f/branch "main"
:f/defaultContext {:id test-utils/context-id?}
:f/data #:f{:address test-utils/address?
:assert [{:ex/x "foo-cat"
:ex/y "bar-cat"
:id :ex/alice}]
:flakes 104
:previous {:id test-utils/db-id?}
:retract [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:size pos-int?
:t 5}
:f/message "meow"
:f/previous {:id test-utils/commit-id?}
:f/time 720000
:f/v 0
:id test-utils/commit-id?}
:retract [{:ex/x "foo-3"
:ex/y "bar-3"
:id :ex/alice}]
:t 5}]
@(fluree/history loaded-ledger {:history :ex/alice
:commit-details true
:t {:from 3}}))))))))
Loading

0 comments on commit a1f0e7b

Please sign in to comment.