2023-08-21 10:26:43 +00:00
|
|
|
import pkg/asynctest
|
|
|
|
import pkg/questionable
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/codex/contracts/requests
|
|
|
|
import pkg/codex/sales/states/initialproving
|
|
|
|
import pkg/codex/sales/states/cancelled
|
|
|
|
import pkg/codex/sales/states/failed
|
|
|
|
import pkg/codex/sales/states/filling
|
|
|
|
import pkg/codex/sales/salesagent
|
|
|
|
import pkg/codex/sales/salescontext
|
2023-12-11 10:29:15 +00:00
|
|
|
import pkg/codex/market
|
2023-08-21 10:26:43 +00:00
|
|
|
import ../../examples
|
|
|
|
import ../../helpers
|
2023-12-11 10:29:15 +00:00
|
|
|
import ../../helpers/mockmarket
|
2023-08-21 10:26:43 +00:00
|
|
|
|
|
|
|
asyncchecksuite "sales state 'initialproving'":
|
|
|
|
let proof = exampleProof()
|
|
|
|
let request = StorageRequest.example
|
|
|
|
let slotIndex = (request.ask.slots div 2).u256
|
2023-12-11 10:29:15 +00:00
|
|
|
let market = MockMarket.new()
|
2023-08-21 10:26:43 +00:00
|
|
|
|
|
|
|
var state: SaleInitialProving
|
|
|
|
var agent: SalesAgent
|
2023-12-11 10:29:15 +00:00
|
|
|
var receivedChallenge: ProofChallenge
|
2023-08-21 10:26:43 +00:00
|
|
|
|
|
|
|
setup:
|
2023-12-11 10:29:15 +00:00
|
|
|
let onProve = proc (slot: Slot, challenge: ProofChallenge): Future[seq[byte]] {.async.} =
|
|
|
|
receivedChallenge = challenge
|
|
|
|
return proof
|
|
|
|
let context = SalesContext(
|
|
|
|
onProve: onProve.some,
|
|
|
|
market: market
|
|
|
|
)
|
2023-08-21 10:26:43 +00:00
|
|
|
agent = newSalesAgent(context,
|
|
|
|
request.id,
|
|
|
|
slotIndex,
|
|
|
|
request.some)
|
|
|
|
state = SaleInitialProving.new()
|
|
|
|
|
|
|
|
test "switches to cancelled state when request expires":
|
|
|
|
let next = state.onCancelled(request)
|
|
|
|
check !next of SaleCancelled
|
|
|
|
|
|
|
|
test "switches to failed state when request fails":
|
|
|
|
let next = state.onFailed(request)
|
|
|
|
check !next of SaleFailed
|
|
|
|
|
|
|
|
test "switches to filling state when initial proving is complete":
|
|
|
|
let next = await state.run(agent)
|
|
|
|
check !next of SaleFilling
|
|
|
|
check SaleFilling(!next).proof == proof
|
2023-12-11 10:29:15 +00:00
|
|
|
|
|
|
|
test "onProve callback provides proof challenge":
|
|
|
|
market.proofChallenge = ProofChallenge.example
|
|
|
|
|
|
|
|
let future = state.run(agent)
|
|
|
|
|
|
|
|
check receivedChallenge == market.proofChallenge
|