mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-02 13:33:10 +00:00
fix(api): availability creation validation (#1212)
This commit is contained in:
parent
19a5e05c13
commit
f144099377
@ -478,6 +478,23 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
|
||||
Http422, "Total size must be larger then zero", headers = headers
|
||||
)
|
||||
|
||||
if restAv.duration == 0:
|
||||
return RestApiResponse.error(
|
||||
Http422, "duration must be larger then zero", headers = headers
|
||||
)
|
||||
|
||||
if restAv.minPricePerBytePerSecond == 0:
|
||||
return RestApiResponse.error(
|
||||
Http422,
|
||||
"minPricePerBytePerSecond must be larger then zero",
|
||||
headers = headers,
|
||||
)
|
||||
|
||||
if restAv.totalCollateral == 0:
|
||||
return RestApiResponse.error(
|
||||
Http422, "totalCollateral must be larger then zero", headers = headers
|
||||
)
|
||||
|
||||
if not reservations.hasAvailable(restAv.totalSize):
|
||||
return
|
||||
RestApiResponse.error(Http422, "Not enough storage quota", headers = headers)
|
||||
|
||||
@ -380,5 +380,44 @@ asyncchecksuite "Rest API validation":
|
||||
response.status == 422
|
||||
(await response.body) == "Cannot set until to a negative value"
|
||||
|
||||
test "creating availability fails when duration is zero":
|
||||
let response = await client.postAvailabilityRaw(
|
||||
totalSize = 12.uint64,
|
||||
duration = 0.uint64,
|
||||
minPricePerBytePerSecond = 1.u256,
|
||||
totalCollateral = 22.u256,
|
||||
until = -1.SecondsSince1970.some,
|
||||
)
|
||||
|
||||
check:
|
||||
response.status == 422
|
||||
(await response.body) == "duration must be larger then zero"
|
||||
|
||||
test "creating availability fails when minPricePerBytePerSecond is zero":
|
||||
let response = await client.postAvailabilityRaw(
|
||||
totalSize = 12.uint64,
|
||||
duration = 1.uint64,
|
||||
minPricePerBytePerSecond = 0.u256,
|
||||
totalCollateral = 22.u256,
|
||||
until = -1.SecondsSince1970.some,
|
||||
)
|
||||
|
||||
check:
|
||||
response.status == 422
|
||||
(await response.body) == "minPricePerBytePerSecond must be larger then zero"
|
||||
|
||||
test "creating availability fails when totalCollateral is zero":
|
||||
let response = await client.postAvailabilityRaw(
|
||||
totalSize = 12.uint64,
|
||||
duration = 1.uint64,
|
||||
minPricePerBytePerSecond = 2.u256,
|
||||
totalCollateral = 0.u256,
|
||||
until = -1.SecondsSince1970.some,
|
||||
)
|
||||
|
||||
check:
|
||||
response.status == 422
|
||||
(await response.body) == "totalCollateral must be larger then zero"
|
||||
|
||||
waitFor node.stop()
|
||||
node.removeDataDir()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user