[sales] Use correct slot price
This commit is contained in:
parent
057de4e928
commit
bf11ef5b55
|
@ -127,5 +127,11 @@ func slotId*(requestId: array[32, byte], slot: UInt256): array[32, byte] =
|
||||||
func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] =
|
func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] =
|
||||||
slotId(request.id, slot)
|
slotId(request.id, slot)
|
||||||
|
|
||||||
|
func pricePerSlot*(ask: StorageAsk): UInt256 =
|
||||||
|
ask.duration * ask.reward
|
||||||
|
|
||||||
|
func price*(ask: StorageAsk): UInt256 =
|
||||||
|
ask.slots.u256 * ask.pricePerSlot
|
||||||
|
|
||||||
func price*(request: StorageRequest): UInt256 =
|
func price*(request: StorageRequest): UInt256 =
|
||||||
request.ask.slots.u256 * request.ask.duration * request.ask.reward
|
request.ask.price
|
||||||
|
|
|
@ -97,7 +97,7 @@ func findAvailability(sales: Sales, ask: StorageAsk): ?Availability =
|
||||||
for availability in sales.available:
|
for availability in sales.available:
|
||||||
if ask.size <= availability.size and
|
if ask.size <= availability.size and
|
||||||
ask.duration <= availability.duration and
|
ask.duration <= availability.duration and
|
||||||
ask.reward >= availability.minPrice:
|
ask.pricePerSlot >= availability.minPrice:
|
||||||
return some availability
|
return some availability
|
||||||
|
|
||||||
proc finish(agent: SalesAgent, success: bool) =
|
proc finish(agent: SalesAgent, success: bool) =
|
||||||
|
|
|
@ -10,13 +10,13 @@ suite "Sales":
|
||||||
let availability = Availability.init(
|
let availability = Availability.init(
|
||||||
size=100.u256,
|
size=100.u256,
|
||||||
duration=60.u256,
|
duration=60.u256,
|
||||||
minPrice=42.u256
|
minPrice=600.u256
|
||||||
)
|
)
|
||||||
var request = StorageRequest(
|
var request = StorageRequest(
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
duration: 60.u256,
|
duration: 60.u256,
|
||||||
size: 100.u256,
|
size: 100.u256,
|
||||||
reward:42.u256,
|
reward: 10.u256,
|
||||||
slots: 4
|
slots: 4
|
||||||
),
|
),
|
||||||
content: StorageContent(
|
content: StorageContent(
|
||||||
|
@ -77,6 +77,13 @@ suite "Sales":
|
||||||
discard await market.requestStorage(tooBig)
|
discard await market.requestStorage(tooBig)
|
||||||
check sales.available == @[availability]
|
check sales.available == @[availability]
|
||||||
|
|
||||||
|
test "ignores request when reward is too low":
|
||||||
|
sales.add(availability)
|
||||||
|
var tooCheap = request
|
||||||
|
tooCheap.ask.reward = request.ask.reward - 1
|
||||||
|
discard await market.requestStorage(tooCheap)
|
||||||
|
check sales.available == @[availability]
|
||||||
|
|
||||||
test "retrieves and stores data locally":
|
test "retrieves and stores data locally":
|
||||||
var storingCid: string
|
var storingCid: string
|
||||||
var storingAvailability: Availability
|
var storingAvailability: Availability
|
||||||
|
|
Loading…
Reference in New Issue