2023-03-09 11:23:45 +00:00
|
|
|
import std/json
|
|
|
|
import pkg/chronos
|
|
|
|
import ../contracts/time
|
|
|
|
import ../codex/helpers/eventually
|
2023-03-27 13:47:25 +00:00
|
|
|
import ./twonodes
|
2023-03-09 11:23:45 +00:00
|
|
|
import ./tokens
|
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
twonodessuite "Integration tests", debug1 = false, debug2 = false:
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
setup:
|
|
|
|
await provider.getSigner(accounts[0]).mint()
|
|
|
|
await provider.getSigner(accounts[1]).mint()
|
|
|
|
await provider.getSigner(accounts[1]).deposit()
|
|
|
|
|
|
|
|
test "nodes can print their peer information":
|
2023-03-27 13:47:25 +00:00
|
|
|
check client1.info() != client2.info()
|
2023-03-09 11:23:45 +00:00
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
test "nodes can set chronicles log level":
|
|
|
|
client1.setLogLevel("DEBUG;TRACE:codex")
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node accepts file uploads":
|
2023-03-27 13:47:25 +00:00
|
|
|
let cid1 = client1.upload("some file contents")
|
|
|
|
let cid2 = client1.upload("some other contents")
|
|
|
|
check cid1 != cid2
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node handles new storage availability":
|
2023-03-27 13:47:25 +00:00
|
|
|
let availability1 = client1.postAvailability(size=1, duration=2, minPrice=3)
|
|
|
|
let availability2 = client1.postAvailability(size=4, duration=5, minPrice=6)
|
|
|
|
check availability1 != availability2
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node lists storage that is for sale":
|
2023-03-27 13:47:25 +00:00
|
|
|
let availability = client1.postAvailability(size=1, duration=2, minPrice=3)
|
|
|
|
check availability in client1.getAvailabilities()
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node handles storage request":
|
2023-03-27 13:47:25 +00:00
|
|
|
let expiry = (await provider.currentTime()) + 30
|
|
|
|
let cid = client1.upload("some file contents")
|
|
|
|
let id1 = client1.requestStorage(cid, duration=1, reward=2, proofProbability=3, expiry=expiry)
|
|
|
|
let id2 = client1.requestStorage(cid, duration=4, reward=5, proofProbability=6, expiry=expiry)
|
|
|
|
check id1 != id2
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node retrieves purchase status":
|
2023-03-27 13:47:25 +00:00
|
|
|
let expiry = (await provider.currentTime()) + 30
|
|
|
|
let cid = client1.upload("some file contents")
|
|
|
|
let id = client1.requestStorage(cid, duration=1, reward=2, proofProbability=3, expiry=expiry)
|
|
|
|
let purchase = client1.getPurchase(id)
|
|
|
|
check purchase{"request"}{"ask"}{"duration"} == %"0x1"
|
|
|
|
check purchase{"request"}{"ask"}{"reward"} == %"0x2"
|
|
|
|
check purchase{"request"}{"ask"}{"proofProbability"} == %"0x3"
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "node remembers purchase status after restart":
|
2023-03-27 13:47:25 +00:00
|
|
|
let expiry = (await provider.currentTime()) + 30
|
|
|
|
let cid = client1.upload("some file contents")
|
|
|
|
let id = client1.requestStorage(cid, duration=1, reward=2, proofProbability=3, expiry=expiry)
|
|
|
|
check eventually client1.getPurchase(id){"state"}.getStr() == "submitted"
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
node1.restart()
|
2023-03-27 13:47:25 +00:00
|
|
|
client1.restart()
|
2023-03-09 11:23:45 +00:00
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
check eventually (not isNil client1.getPurchase(id){"request"}{"ask"})
|
|
|
|
check client1.getPurchase(id){"request"}{"ask"}{"duration"} == %"0x1"
|
|
|
|
check client1.getPurchase(id){"request"}{"ask"}{"reward"} == %"0x2"
|
2023-03-09 11:23:45 +00:00
|
|
|
|
|
|
|
test "nodes negotiate contracts on the marketplace":
|
2023-03-27 13:47:25 +00:00
|
|
|
# client 2 makes storage available
|
|
|
|
discard client2.postAvailability(size=0xFFFFF, duration=200, minPrice=300)
|
2023-03-09 11:23:45 +00:00
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
# client 1 requests storage
|
|
|
|
let expiry = (await provider.currentTime()) + 30
|
|
|
|
let cid = client1.upload("some file contents")
|
|
|
|
let purchase = client1.requestStorage(cid, duration=100, reward=400, proofProbability=3, expiry=expiry)
|
2023-03-09 11:23:45 +00:00
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
check eventually client1.getPurchase(purchase){"state"} == %"started"
|
|
|
|
check client1.getPurchase(purchase){"error"} == newJNull()
|
|
|
|
check client2.getAvailabilities().len == 0
|