import std/sets import std/sequtils import std/sugar import std/times import pkg/asynctest import pkg/chronos import pkg/datastore import pkg/questionable import pkg/questionable/results import pkg/codex/sales import pkg/codex/sales/salesdata import pkg/codex/sales/salescontext import pkg/codex/sales/reservations import pkg/codex/sales/slotqueue import pkg/codex/stores/repostore import pkg/codex/proving import pkg/codex/blocktype as bt import pkg/codex/node import ../helpers/mockmarket import ../helpers/mockclock import ../helpers/eventually import ../examples import ./helpers asyncchecksuite "Sales": let proof = exampleProof() var availability: Availability var request: StorageRequest var sales: Sales var market: MockMarket var clock: MockClock var proving: Proving var reservations: Reservations var repo: RepoStore var queue: SlotQueue var itemsProcessed: seq[SlotQueueItem] setup: availability = Availability.init( size=100.u256, duration=60.u256, minPrice=600.u256, maxCollateral=400.u256 ) request = StorageRequest( ask: StorageAsk( slots: 4, slotSize: 100.u256, duration: 60.u256, reward: 10.u256, collateral: 200.u256, ), content: StorageContent( cid: "some cid" ), expiry: (getTime() + initDuration(hours=1)).toUnix.u256 ) market = MockMarket.new() clock = MockClock.new() proving = Proving.new() let repoDs = SQLiteDatastore.new(Memory).tryGet() let metaDs = SQLiteDatastore.new(Memory).tryGet() repo = RepoStore.new(repoDs, metaDs) await repo.start() sales = Sales.new(market, clock, proving, repo) reservations = sales.context.reservations sales.onStore = proc(request: StorageRequest, slot: UInt256, onBatch: BatchProc): Future[?!void] {.async.} = return success() queue = sales.context.slotQueue proving.onProve = proc(slot: Slot): Future[seq[byte]] {.async.} = return proof await sales.start() request.expiry = (clock.now() + 42).u256 itemsProcessed = @[] teardown: await sales.stop() await repo.stop() proc getAvailability: ?!Availability = waitFor reservations.get(availability.id) proc notProcessed(itemsProcessed: seq[SlotQueueItem], request: StorageRequest): bool = let items = SlotQueueItem.init(request) for i in 0.. agent.data == expected)