mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-22 09:38:12 +00:00
When a storage request is handled by the sales module, a slot index was randomly assigned and then the slot was filled. Now, the random slot index is checked that its state is `SlotState.Free` before continuing with the download process. An additional sales agent state was added, preparing, that handles this step of assigning a random slot index. All state machine setup, such as retrieving the request and subscribing to events that were previously in the `SaleDownloading` state have been moved to `SalePreparing`. If all indices of the request have been filled, the state is changed to `SaleIgnored`. # Conflicts: # codex/sales.nim # codex/sales/states/downloading.nim # codex/sales/states/filling.nim # tests/contracts/testInteractions.nim
46 lines
1.3 KiB
Nim
46 lines
1.3 KiB
Nim
import pkg/asynctest
|
|
import pkg/codex/contracts/requests
|
|
import pkg/codex/sales
|
|
import pkg/codex/sales/salesagent
|
|
import pkg/codex/sales/salescontext
|
|
import pkg/codex/sales/states/filled
|
|
import pkg/codex/sales/states/errored
|
|
import pkg/codex/sales/states/finished
|
|
import ../../helpers/mockmarket
|
|
import ../../examples
|
|
|
|
suite "sales state 'filled'":
|
|
|
|
let request = StorageRequest.example
|
|
let slotIndex = (request.ask.slots div 2).u256
|
|
|
|
var market: MockMarket
|
|
var slot: MockSlot
|
|
var agent: SalesAgent
|
|
var state: SaleFilled
|
|
|
|
setup:
|
|
market = MockMarket.new()
|
|
slot = MockSlot(requestId: request.id,
|
|
host: Address.example,
|
|
slotIndex: slotIndex,
|
|
proof: @[])
|
|
let context = SalesContext(market: market)
|
|
agent = newSalesAgent(context,
|
|
request.id,
|
|
some slotIndex,
|
|
StorageRequest.none)
|
|
state = SaleFilled.new()
|
|
|
|
test "switches to finished state when slot is filled by me":
|
|
slot.host = await market.getSigner()
|
|
market.filled = @[slot]
|
|
let next = await state.run(agent)
|
|
check !next of SaleFinished
|
|
|
|
test "switches to error state when slot is filled by another host":
|
|
slot.host = Address.example
|
|
market.filled = @[slot]
|
|
let next = await state.run(agent)
|
|
check !next of SaleErrored
|