2021-02-01 16:19:53 +01:00
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/chronos
|
2021-01-14 13:54:03 +01:00
|
|
|
import pkg/ipfs/repo
|
2021-01-12 13:58:57 +01:00
|
|
|
|
|
|
|
suite "repo":
|
|
|
|
|
2021-01-14 14:21:07 +01:00
|
|
|
let obj = IpfsObject(data: @[1'u8, 2'u8, 3'u8])
|
2021-01-12 13:58:57 +01:00
|
|
|
var repo: Repo
|
|
|
|
|
|
|
|
setup:
|
|
|
|
repo = Repo()
|
|
|
|
|
2021-01-14 14:21:07 +01:00
|
|
|
test "stores IPFS objects":
|
|
|
|
repo.store(obj)
|
2021-01-12 13:58:57 +01:00
|
|
|
|
2021-01-14 14:21:07 +01:00
|
|
|
test "retrieves IPFS objects by their content id":
|
|
|
|
repo.store(obj)
|
2021-01-28 10:09:21 +01:00
|
|
|
check repo.retrieve(obj.cid).get() == obj
|
|
|
|
|
|
|
|
test "signals retrieval failure":
|
|
|
|
check repo.retrieve(obj.cid).isNone
|
2021-01-12 13:58:57 +01:00
|
|
|
|
2021-01-14 14:21:07 +01:00
|
|
|
test "knows which content ids are stored":
|
|
|
|
check repo.contains(obj.cid) == false
|
|
|
|
repo.store(obj)
|
|
|
|
check repo.contains(obj.cid) == true
|
2021-02-01 16:19:53 +01:00
|
|
|
|
|
|
|
test "waits for IPFS object to arrive":
|
|
|
|
let waiting = repo.wait(obj.cid, 1.minutes)
|
|
|
|
check not waiting.finished
|
|
|
|
repo.store(obj)
|
|
|
|
check waiting.finished
|
|
|
|
|
|
|
|
test "does not wait when IPFS object is already stored":
|
|
|
|
repo.store(obj)
|
|
|
|
check repo.wait(obj.cid, 1.minutes).finished
|