contracts: update types

This commit is contained in:
Mark Spanbroek 2025-03-12 10:19:09 +01:00
parent 9b9d0b23fe
commit 312500fc8e
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
37 changed files with 445 additions and 424 deletions

View File

@ -43,5 +43,5 @@ proc toSecondsSince1970*(bytes: seq[byte]): SecondsSince1970 =
proc toSecondsSince1970*(num: uint64): SecondsSince1970 =
cast[int64](num)
proc toSecondsSince1970*(bigint: UInt256): SecondsSince1970 =
proc toSecondsSince1970*(bigint: StUint[40]): SecondsSince1970 =
bigint.truncate(int64)

View File

@ -11,7 +11,7 @@ type
collateral*: CollateralConfig
proofs*: ProofConfig
reservations*: SlotReservationsConfig
requestDurationLimit*: uint64
requestDurationLimit*: StUint[40]
CollateralConfig* = object
repairRewardPercentage*: uint8
@ -22,8 +22,8 @@ type
# percentage of the slashed amount going to the validators
ProofConfig* = object
period*: uint64 # proofs requirements are calculated per period (in seconds)
timeout*: uint64 # mark proofs as missing before the timeout (in seconds)
period*: StUint[40] # proofs requirements are calculated per period (in seconds)
timeout*: StUint[40] # mark proofs as missing before the timeout (in seconds)
downtime*: uint8 # ignore this much recent blocks for proof requirements
downtimeProduct*: uint8
zkeyHash*: string # hash of the zkey file which is linked to the verifier
@ -62,6 +62,9 @@ func fromTuple(_: type MarketplaceConfig, tupl: tuple): MarketplaceConfig =
requestDurationLimit: tupl[3],
)
func solidityType(_: type StUint[40]): string =
"uint40"
func solidityType*(_: type SlotReservationsConfig): string =
solidityType(SlotReservationsConfig.fieldTypes)

View File

@ -112,16 +112,16 @@ method zkeyHash*(market: OnChainMarket): string =
method periodicity*(market: OnChainMarket): Periodicity =
let period = market.configuration.proofs.period
return Periodicity(seconds: period)
return Periodicity(seconds: period.u64)
method proofTimeout*(market: OnChainMarket): uint64 =
return market.configuration.proofs.timeout
return market.configuration.proofs.timeout.u64
method repairRewardPercentage*(market: OnChainMarket): uint8 =
return market.configuration.collateral.repairRewardPercentage
method requestDurationLimit*(market: OnChainMarket): uint64 =
return market.configuration.requestDurationLimit
return market.configuration.requestDurationLimit.u64
method proofDowntime*(market: OnChainMarket): uint8 =
return market.configuration.proofs.downtime
@ -147,7 +147,7 @@ method requestStorage(
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to request storage"):
debug "Requesting storage"
await market.approveFunds(request.totalPrice())
await market.approveFunds(request.totalPrice().stuint(256))
discard await market.contract.requestStorage(request).confirm(1)
method getRequest*(
@ -211,7 +211,7 @@ method getHost(
method currentCollateral*(
market: OnChainMarket, slotId: SlotId
): Future[UInt256] {.async: (raises: [MarketError, CancelledError]).} =
): Future[UInt128] {.async: (raises: [MarketError, CancelledError]).} =
convertEthersError("Failed to get slot's current collateral"):
return await market.contract.currentCollateral(slotId)
@ -227,7 +227,7 @@ method fillSlot(
requestId: RequestId,
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
collateral: UInt128,
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to fill slot"):
logScope:
@ -235,7 +235,7 @@ method fillSlot(
slotIndex
try:
await market.approveFunds(collateral)
await market.approveFunds(collateral.stuint(256))
# Add 10% to gas estimate to deal with different evm code flow when we
# happen to be the last one to fill a slot in this request
@ -314,7 +314,7 @@ method markProofAsMissing*(
let gas = await market.contract.estimateGas.markProofAsMissing(id, period)
let overrides = TransactionOverrides(gasLimit: some (gas * 110) div 100)
discard await market.contract.markProofAsMissing(id, period, overrides).confirm(1)
discard await market.contract.markProofAsMissing(id, period.stuint(40), overrides).confirm(1)
method canProofBeMarkedAsMissing*(
market: OnChainMarket, id: SlotId, period: Period
@ -323,7 +323,7 @@ method canProofBeMarkedAsMissing*(
let contractWithoutSigner = market.contract.connect(provider)
let overrides = CallOverrides(blockTag: some BlockTag.pending)
try:
discard await contractWithoutSigner.markProofAsMissing(id, period, overrides)
discard await contractWithoutSigner.markProofAsMissing(id, period.stuint(40), overrides)
return true
except EthersError as e:
trace "Proof cannot be marked as missing", msg = e.msg
@ -361,7 +361,7 @@ method subscribeRequests*(
error "There was an error in Request subscription", msg = eventErr.msg
return
callback(event.requestId, event.ask, event.expiry)
callback(event.requestId, event.ask, event.expiry.truncate(uint64))
convertEthersError("Failed to subscribe to StorageRequested events"):
let subscription = await market.contract.subscribe(StorageRequested, onEvent)

View File

@ -58,7 +58,7 @@ proc configuration*(marketplace: Marketplace): MarketplaceConfig {.contract, vie
proc token*(marketplace: Marketplace): Address {.contract, view.}
proc currentCollateral*(
marketplace: Marketplace, id: SlotId
): UInt256 {.contract, view.}
): UInt128 {.contract, view.}
proc requestStorage*(
marketplace: Marketplace, request: StorageRequest
@ -155,7 +155,7 @@ proc submitProof*(
.}
proc markProofAsMissing*(
marketplace: Marketplace, id: SlotId, period: uint64
marketplace: Marketplace, id: SlotId, period: StUint[40]
): Confirmable {.
contract,
errors: [

View File

@ -18,16 +18,16 @@ type
client* {.serialize.}: Address
ask* {.serialize.}: StorageAsk
content* {.serialize.}: StorageContent
expiry* {.serialize.}: uint64
expiry* {.serialize.}: StorageDuration
nonce*: Nonce
StorageAsk* = object
proofProbability* {.serialize.}: UInt256
pricePerBytePerSecond* {.serialize.}: UInt256
collateralPerByte* {.serialize.}: UInt256
pricePerBytePerSecond* {.serialize.}: TokensPerSecond
collateralPerByte* {.serialize.}: UInt128
slots* {.serialize.}: uint64
slotSize* {.serialize.}: uint64
duration* {.serialize.}: uint64
duration* {.serialize.}: StorageDuration
maxSlotLoss* {.serialize.}: uint64
StorageContent* = object
@ -56,6 +56,9 @@ type
Cancelled
Repair
StorageDuration* = StUint[40]
TokensPerSecond* = StUint[96]
proc `==`*(x, y: Nonce): bool {.borrow.}
proc `==`*(x, y: RequestId): bool {.borrow.}
proc `==`*(x, y: SlotId): bool {.borrow.}
@ -66,6 +69,9 @@ proc hash*(x: Address): Hash {.borrow.}
func toArray*(id: RequestId | SlotId | Nonce): array[32, byte] =
array[32, byte](id)
func u64*(uint40: StUint[40]): uint64 =
uint40.truncate(uint64)
proc `$`*(id: RequestId | SlotId | Nonce): string =
id.toArray.toHex
@ -133,6 +139,12 @@ func solidityType*(_: type StorageAsk): string =
func solidityType*(_: type StorageRequest): string =
solidityType(StorageRequest.fieldTypes)
func solidityType*(_: type StUint[40]): string =
"uint40"
func solidityType*(_: type StUint[96]): string =
"uint96"
# Note: it seems to be ok to ignore the vbuffer offset for now
func encode*(encoder: var AbiEncoder, cid: Cid) =
encoder.write(cid.data.buffer)
@ -186,20 +198,20 @@ func slotId*(request: StorageRequest, slotIndex: uint64): SlotId =
func id*(slot: Slot): SlotId =
slotId(slot.request, slot.slotIndex)
func pricePerSlotPerSecond*(ask: StorageAsk): UInt256 =
ask.pricePerBytePerSecond * ask.slotSize.u256
func pricePerSlotPerSecond*(ask: StorageAsk): TokensPerSecond =
ask.pricePerBytePerSecond * ask.slotSize.to(TokensPerSecond)
func pricePerSlot*(ask: StorageAsk): UInt256 =
ask.duration.u256 * ask.pricePerSlotPerSecond
func pricePerSlot*(ask: StorageAsk): UInt128 =
ask.duration.stuint(128) * ask.pricePerSlotPerSecond.stuint(128)
func totalPrice*(ask: StorageAsk): UInt256 =
ask.slots.u256 * ask.pricePerSlot
func totalPrice*(ask: StorageAsk): UInt128 =
ask.slots.stuint(128) * ask.pricePerSlot
func totalPrice*(request: StorageRequest): UInt256 =
func totalPrice*(request: StorageRequest): UInt128 =
request.ask.totalPrice
func collateralPerSlot*(ask: StorageAsk): UInt256 =
ask.collateralPerByte * ask.slotSize.u256
func collateralPerSlot*(ask: StorageAsk): UInt128 =
ask.collateralPerByte * ask.slotSize.stuint(128)
func size*(ask: StorageAsk): uint64 =
ask.slots * ask.slotSize

View File

@ -37,7 +37,7 @@ type
StorageRequested* = object of MarketplaceEvent
requestId*: RequestId
ask*: StorageAsk
expiry*: uint64
expiry*: StorageDuration
SlotFilled* = object of MarketplaceEvent
requestId* {.indexed.}: RequestId
@ -130,7 +130,7 @@ method getHost*(
method currentCollateral*(
market: Market, slotId: SlotId
): Future[UInt256] {.base, async: (raises: [MarketError, CancelledError]).} =
): Future[UInt128] {.base, async: (raises: [MarketError, CancelledError]).} =
raiseAssert("not implemented")
method getActiveSlot*(market: Market, slotId: SlotId): Future[?Slot] {.base, async.} =
@ -141,7 +141,7 @@ method fillSlot*(
requestId: RequestId,
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
collateral: UInt128,
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")

View File

@ -489,13 +489,13 @@ proc iterateManifests*(self: CodexNodeRef, onManifest: OnManifest) {.async.} =
proc setupRequest(
self: CodexNodeRef,
cid: Cid,
duration: uint64,
duration: StorageDuration,
proofProbability: UInt256,
nodes: uint,
tolerance: uint,
pricePerBytePerSecond: UInt256,
collateralPerByte: UInt256,
expiry: uint64,
pricePerBytePerSecond: TokensPerSecond,
collateralPerByte: UInt128,
expiry: StorageDuration,
): Future[?!StorageRequest] {.async.} =
## Setup slots for a given dataset
##
@ -570,13 +570,13 @@ proc setupRequest(
proc requestStorage*(
self: CodexNodeRef,
cid: Cid,
duration: uint64,
duration: StorageDuration,
proofProbability: UInt256,
nodes: uint,
tolerance: uint,
pricePerBytePerSecond: UInt256,
collateralPerByte: UInt256,
expiry: uint64,
pricePerBytePerSecond: TokensPerSecond,
collateralPerByte: UInt128,
expiry: StorageDuration,
): Future[?!PurchaseId] {.async.} =
## Initiate a request for storage sequence, this might
## be a multistep procedure.

View File

@ -706,8 +706,7 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
)
let requestDurationLimit = contracts.purchasing.market.requestDurationLimit
if params.duration > requestDurationLimit:
if params.duration.u64 > requestDurationLimit:
return RestApiResponse.error(
Http422,
"Duration exceeds limit of " & $requestDurationLimit & " seconds",

View File

@ -13,11 +13,11 @@ export json
type
StorageRequestParams* = object
duration* {.serialize.}: uint64
duration* {.serialize.}: StorageDuration
proofProbability* {.serialize.}: UInt256
pricePerBytePerSecond* {.serialize.}: UInt256
collateralPerByte* {.serialize.}: UInt256
expiry* {.serialize.}: uint64
pricePerBytePerSecond* {.serialize.}: TokensPerSecond
collateralPerByte* {.serialize.}: UInt128
expiry* {.serialize.}: StorageDuration
nodes* {.serialize.}: ?uint
tolerance* {.serialize.}: ?uint

View File

@ -73,8 +73,8 @@ const DefaultMaxSize = 128'u16
proc profitability(item: SlotQueueItem): UInt256 =
let price =
StorageAsk(
duration: item.duration,
pricePerBytePerSecond: item.pricePerBytePerSecond,
duration: item.duration.stuint(40),
pricePerBytePerSecond: item.pricePerBytePerSecond.stuint(96),
slotSize: item.slotSize,
).pricePerSlot
return price.stuint(256) + item.repairReward
@ -155,8 +155,8 @@ proc init*(
requestId: requestId,
slotIndex: slotIndex,
slotSize: ask.slotSize,
duration: ask.duration,
pricePerBytePerSecond: ask.pricePerBytePerSecond,
duration: ask.duration.u64,
pricePerBytePerSecond: ask.pricePerBytePerSecond.stuint(256),
collateral: collateral,
expiry: expiry,
seen: seen,
@ -201,7 +201,7 @@ proc init*(
repairReward = 0.u256,
): seq[SlotQueueItem] =
return SlotQueueItem.init(
request.id, request.ask, request.expiry, collateral, repairReward
request.id, request.ask, request.expiry.u64, collateral, repairReward
)
proc inRange*(val: SomeUnsignedInt): bool =

View File

@ -51,7 +51,10 @@ method run*(
onClear(request, data.slotIndex)
if onCleanUp =? agent.onCleanUp:
await onCleanUp(reprocessSlot = false, returnedCollateral = returnedCollateral)
await onCleanUp(
reprocessSlot = false,
returnedCollateral = some currentCollateral.stuint(256),
)
warn "Sale cancelled due to timeout",
requestId = data.requestId, slotIndex = data.slotIndex

View File

@ -72,8 +72,11 @@ method run*(
without availability =?
await reservations.findAvailability(
request.ask.slotSize, request.ask.duration, request.ask.pricePerBytePerSecond,
request.ask.collateralPerByte, requestEnd,
request.ask.slotSize,
request.ask.duration.u64,
request.ask.pricePerBytePerSecond.stuint(256),
request.ask.collateralPerByte.stuint(256),
requestEnd.u64
):
debug "No availability found for request, ignoring"
@ -83,8 +86,12 @@ method run*(
without reservation =?
await reservations.createReservation(
availability.id, request.ask.slotSize, request.id, data.slotIndex,
request.ask.collateralPerByte, requestEnd,
availability.id,
request.ask.slotSize,
request.id,
data.slotIndex,
request.ask.collateralPerByte.stuint(256),
requestEnd.u64,
), error:
trace "Creation of reservation failed"
# Race condition:

View File

@ -64,7 +64,7 @@ type
slotIndex*: uint64
proof*: Groth16Proof
timestamp: ?SecondsSince1970
collateral*: UInt256
collateral*: UInt128
Subscriptions = object
onRequest: seq[RequestSubscription]
@ -124,13 +124,13 @@ proc new*(_: type MockMarket, clock: ?Clock = Clock.none): MockMarket =
validatorRewardPercentage: 20,
),
proofs: ProofConfig(
period: 10.Period,
timeout: 5.uint64,
period: 10.stuint(40),
timeout: 5.stuint(40),
downtime: 64.uint8,
downtimeProduct: 67.uint8,
),
reservations: SlotReservationsConfig(maxReservations: 3),
requestDurationLimit: (60 * 60 * 24 * 30).uint64,
requestDurationLimit: (60 * 60 * 24 * 30).stuint(40),
)
MockMarket(
signer: Address.example, config: config, canReserveSlot: true, clock: clock
@ -142,13 +142,13 @@ method getSigner*(
return market.signer
method periodicity*(mock: MockMarket): Periodicity =
return Periodicity(seconds: mock.config.proofs.period)
return Periodicity(seconds: mock.config.proofs.period.u64)
method proofTimeout*(market: MockMarket): uint64 =
return market.config.proofs.timeout
return market.config.proofs.timeout.u64
method requestDurationLimit*(market: MockMarket): uint64 =
return market.config.requestDurationLimit
return market.config.requestDurationLimit.u64
method proofDowntime*(market: MockMarket): uint8 =
return market.config.proofs.downtime
@ -165,7 +165,7 @@ method requestStorage*(
market.requested.add(request)
var subscriptions = market.subscriptions.onRequest
for subscription in subscriptions:
subscription.callback(request.id, request.ask, request.expiry)
subscription.callback(request.id, request.ask, request.expiry.u64)
method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} =
return market.activeRequests[market.signer]
@ -227,11 +227,11 @@ method getHost*(
method currentCollateral*(
market: MockMarket, slotId: SlotId
): Future[UInt256] {.async: (raises: [MarketError, CancelledError]).} =
): Future[UInt128] {.async: (raises: [MarketError, CancelledError]).} =
for slot in market.filled:
if slotId == slotId(slot.requestId, slot.slotIndex):
return slot.collateral
return 0.u256
return 0.u128
proc emitSlotFilled*(market: MockMarket, requestId: RequestId, slotIndex: uint64) =
var subscriptions = market.subscriptions.onSlotFilled
@ -273,7 +273,7 @@ proc fillSlot*(
slotIndex: uint64,
proof: Groth16Proof,
host: Address,
collateral = 0.u256,
collateral = 0.u128,
) =
if error =? market.errorOnFillSlot:
raise error
@ -295,7 +295,7 @@ method fillSlot*(
requestId: RequestId,
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
collateral: UInt128,
) {.async: (raises: [CancelledError, MarketError]).} =
market.fillSlot(requestId, slotIndex, proof, market.signer, collateral)

View File

@ -17,8 +17,8 @@ proc toSlotQueueItem*(item: MockSlotQueueItem): SlotQueueItem =
slotIndex = item.slotIndex,
ask = StorageAsk(
slotSize: item.slotSize,
duration: item.duration,
pricePerBytePerSecond: item.pricePerBytePerSecond,
duration: item.duration.stuint(40),
pricePerBytePerSecond: item.pricePerBytePerSecond.stuint(96),
),
expiry = item.expiry,
seen = item.seen,

View File

@ -117,7 +117,7 @@ asyncchecksuite "Test Node - Host contracts":
var request = StorageRequest.example
request.content.cid = verifiableBlock.cid
request.expiry =
(getTime() + DefaultBlockTtl.toTimesDuration + 1.hours).toUnix.uint64
(getTime() + DefaultBlockTtl.toTimesDuration + 1.hours).toUnix.stuint(40)
var fetchedBytes: uint = 0
let onBlocks = proc(blocks: seq[bt.Block]): Future[?!void] {.async.} =

View File

@ -188,11 +188,11 @@ asyncchecksuite "Test Node - Basic":
cid = manifestBlock.cid,
nodes = 5,
tolerance = 2,
duration = 100.uint64,
pricePerBytePerSecond = 1.u256,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 200.uint64,
collateralPerByte = 1.u256,
expiry = 200.stuint(40),
collateralPerByte = 1.u128,
)
).tryGet

View File

@ -19,7 +19,7 @@ asyncchecksuite "sales state 'cancelled'":
let slotIndex = request.ask.slots div 2
let clock = MockClock.new()
let currentCollateral = UInt256.example
let currentCollateral = UInt128.example
var market: MockMarket
var state: SaleCancelled

View File

@ -18,7 +18,7 @@ asyncchecksuite "sales state 'payout'":
let slotIndex = request.ask.slots div 2
let clock = MockClock.new()
let currentCollateral = UInt256.example
let currentCollateral = UInt128.example
var market: MockMarket
var state: SalePayout
@ -41,4 +41,4 @@ asyncchecksuite "sales state 'payout'":
)
let next = await state.run(agent)
check !next of SaleFinished
check SaleFinished(!next).returnedCollateral == some currentCollateral
check SaleFinished(!next).returnedCollateral == some collateral

View File

@ -34,12 +34,14 @@ asyncchecksuite "sales state 'preparing'":
var reservations: MockReservations
setup:
let collateral =
request.ask.collateralPerSlot.stuint(256) * request.ask.slots.u256
availability = Availability.init(
totalSize = request.ask.slotSize + 100.uint64,
freeSize = request.ask.slotSize + 100.uint64,
duration = request.ask.duration + 60.uint64,
minPricePerBytePerSecond = request.ask.pricePerBytePerSecond,
totalCollateral = request.ask.collateralPerSlot * request.ask.slots.u256,
duration = request.ask.duration.u64 + 60,
minPricePerBytePerSecond = request.ask.pricePerBytePerSecond.stuint(256),
totalCollateral = collateral,
enabled = true,
until = 0.SecondsSince1970,
)

View File

@ -44,14 +44,14 @@ asyncchecksuite "Sales - start":
ask: StorageAsk(
slots: 4,
slotSize: 100.uint64,
duration: 60.uint64,
pricePerBytePerSecond: 1.u256,
collateralPerByte: 1.u256,
duration: 60.stuint(40),
pricePerBytePerSecond: 1.stuint(96),
collateralPerByte: 1.u128,
),
content: StorageContent(
cid: Cid.init("zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob").tryGet
),
expiry: (getTime() + initDuration(hours = 1)).toUnix.uint64,
expiry: (getTime() + initDuration(hours = 1)).toUnix.stuint(40),
)
market = MockMarket.new()
@ -79,7 +79,7 @@ asyncchecksuite "Sales - start":
return success(proof)
itemsProcessed = @[]
expiry = (clock.now() + 42)
request.expiry = expiry.uint64
request.expiry = expiry.stuint(40)
teardown:
await sales.stop()
@ -130,7 +130,7 @@ asyncchecksuite "Sales":
var totalAvailabilitySize: uint64
var minPricePerBytePerSecond: UInt256
var requestedCollateralPerByte: UInt256
var requestedCollateralPerByte: UInt128
var totalCollateral: UInt256
var availability: Availability
var request: StorageRequest
@ -145,8 +145,8 @@ asyncchecksuite "Sales":
setup:
totalAvailabilitySize = 100.uint64
minPricePerBytePerSecond = 1.u256
requestedCollateralPerByte = 1.u256
totalCollateral = requestedCollateralPerByte * totalAvailabilitySize.stuint(256)
requestedCollateralPerByte = 1.u128
totalCollateral = requestedCollateralPerByte.stuint(256) * totalAvailabilitySize.stuint(256)
availability = Availability.init(
totalSize = totalAvailabilitySize,
freeSize = totalAvailabilitySize,
@ -160,14 +160,14 @@ asyncchecksuite "Sales":
ask: StorageAsk(
slots: 4,
slotSize: 100.uint64,
duration: 60.uint64,
pricePerBytePerSecond: minPricePerBytePerSecond,
collateralPerByte: 1.u256,
duration: 60.stuint(40),
pricePerBytePerSecond: minPricePerBytePerSecond.stuint(96),
collateralPerByte: 1.u128,
),
content: StorageContent(
cid: Cid.init("zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob").tryGet
),
expiry: (getTime() + initDuration(hours = 1)).toUnix.uint64,
expiry: (getTime() + initDuration(hours = 1)).toUnix.stuint(40),
)
market = MockMarket.new()
@ -233,7 +233,8 @@ asyncchecksuite "Sales":
availability = a.get # update id
proc notProcessed(itemsProcessed: seq[SlotQueueItem], request: StorageRequest): bool =
let items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
let collateral =request.ask.collateralPerSlot.stuint(256)
let items = SlotQueueItem.init(request, collateral)
for i in 0 ..< items.len:
if itemsProcessed.contains(items[i]):
return false
@ -280,7 +281,8 @@ asyncchecksuite "Sales":
done.complete()
createAvailability()
await market.requestStorage(request)
let items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
let collateral = request.ask.collateralPerSlot.stuint(256)
let items = SlotQueueItem.init(request, collateral)
check eventually items.allIt(itemsProcessed.contains(it))
test "removes request from slot queue once RequestFailed emitted":
@ -296,15 +298,15 @@ asyncchecksuite "Sales":
test "removes slot index from slot queue once SlotFilled emitted":
let request1 = await addRequestToSaturatedQueue()
market.emitSlotFilled(request1.id, 1.uint64)
let expected =
SlotQueueItem.init(request1, 1'u16, collateral = request1.ask.collateralPerSlot)
let collateral = request1.ask.collateralPerSlot.stuint(256)
let expected = SlotQueueItem.init(request1, 1'u16, collateral)
check always (not itemsProcessed.contains(expected))
test "removes slot index from slot queue once SlotReservationsFull emitted":
let request1 = await addRequestToSaturatedQueue()
market.emitSlotReservationsFull(request1.id, 1.uint64)
let expected =
SlotQueueItem.init(request1, 1'u16, collateral = request1.ask.collateralPerSlot)
let collateral = request1.ask.collateralPerSlot.stuint(256)
let expected = SlotQueueItem.init(request1, 1'u16, collateral)
check always (not itemsProcessed.contains(expected))
test "adds slot index to slot queue once SlotFreed emitted":
@ -320,14 +322,15 @@ asyncchecksuite "Sales":
market.emitSlotFreed(request.id, 2.uint64)
let expected =
SlotQueueItem.init(request, 2.uint16, collateral = request.ask.collateralPerSlot)
let collateral = request.ask.collateralPerSlot.stuint(256)
let expected = SlotQueueItem.init(request, 2.uint16, collateral)
check eventually itemsProcessed.contains(expected)
test "items in queue are readded (and marked seen) once ignored":
await market.requestStorage(request)
let items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
let collateral = request.ask.collateralPerSlot.stuint(256)
let items = SlotQueueItem.init(request, collateral)
check eventually queue.len > 0
# queue starts paused, allow items to be added to the queue
check eventually queue.paused
@ -348,7 +351,8 @@ asyncchecksuite "Sales":
test "queue is paused once availability is insufficient to service slots in queue":
createAvailability() # enough to fill a single slot
await market.requestStorage(request)
let items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
let collateral = request.ask.collateralPerSlot.stuint(256)
let items = SlotQueueItem.init(request, collateral)
check eventually queue.len > 0
# queue starts paused, allow items to be added to the queue
check eventually queue.paused
@ -396,12 +400,12 @@ asyncchecksuite "Sales":
# complete request
market.slotState[request.slotId(slotIndex)] = SlotState.Finished
clock.advance(request.ask.duration.int64)
clock.advance(request.ask.duration.truncate(int64))
check eventually getAvailability().freeSize == origSize
test "ignores download when duration not long enough":
availability.duration = request.ask.duration - 1
availability.duration = request.ask.duration.truncate(uint64) - 1
createAvailability()
await market.requestStorage(request)
check wasIgnored()
@ -413,7 +417,8 @@ asyncchecksuite "Sales":
check wasIgnored()
test "ignores request when reward is too low":
availability.minPricePerBytePerSecond = request.ask.pricePerBytePerSecond + 1
let price = request.ask.pricePerBytePerSecond.stuint(256)
availability.minPricePerBytePerSecond = price + 1
createAvailability()
await market.requestStorage(request)
check wasIgnored()

View File

@ -41,7 +41,8 @@ asyncchecksuite "Sales agent":
setup:
market = MockMarket.new()
market.requestExpiry[request.id] = getTime().toUnix() + request.expiry.int64
let expiry = getTime().toUnix() + request.expiry.toSecondsSince1970
market.requestExpiry[request.id] = expiry
clock = MockClock.new()
context = SalesContext(market: market, clock: clock)
slotIndex = 0.uint64

View File

@ -166,23 +166,23 @@ suite "Slot queue":
test "correctly compares SlotQueueItems":
var requestA = StorageRequest.example
requestA.ask.duration = 1.uint64
requestA.ask.pricePerBytePerSecond = 1.u256
check requestA.ask.pricePerSlot == 1.u256 * requestA.ask.slotSize.u256
requestA.ask.collateralPerByte = 100000.u256
requestA.expiry = 1001.uint64
requestA.ask.duration = 1.stuint(40)
requestA.ask.pricePerBytePerSecond = 1.stuint(96)
check requestA.ask.pricePerSlot == 1.u128 * requestA.ask.slotSize.u128
requestA.ask.collateralPerByte = 100000.u128
requestA.expiry = 1001.stuint(40)
var requestB = StorageRequest.example
requestB.ask.duration = 100.uint64
requestB.ask.pricePerBytePerSecond = 1000.u256
check requestB.ask.pricePerSlot == 100000.u256 * requestB.ask.slotSize.u256
requestB.ask.collateralPerByte = 1.u256
requestB.expiry = 1000.uint64
requestB.ask.duration = 100.stuint(40)
requestB.ask.pricePerBytePerSecond = 1000.stuint(96)
check requestB.ask.pricePerSlot == 100000.u128 * requestB.ask.slotSize.u128
requestB.ask.collateralPerByte = 1.u128
requestB.expiry = 1000.stuint(40)
let itemA =
SlotQueueItem.init(requestA, 0, collateral = requestA.ask.collateralPerSlot)
SlotQueueItem.init(requestA, 0, requestA.ask.collateralPerSlot.stuint(256))
let itemB =
SlotQueueItem.init(requestB, 0, collateral = requestB.ask.collateralPerSlot)
SlotQueueItem.init(requestB, 0, requestB.ask.collateralPerSlot.stuint(256))
check itemB < itemA # B higher priority than A
check itemA > itemB
@ -314,14 +314,14 @@ suite "Slot queue":
test "expands available all possible slot indices on init":
let request = StorageRequest.example
let items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
let items = SlotQueueItem.init(request, request.ask.collateralPerSlot.stuint(256))
check items.len.uint64 == request.ask.slots
var checked = 0
for slotIndex in 0'u16 ..< request.ask.slots.uint16:
check items.anyIt(
it ==
SlotQueueItem.init(
request, slotIndex, collateral = request.ask.collateralPerSlot
request, slotIndex, request.ask.collateralPerSlot.stuint(256)
)
)
inc checked
@ -357,8 +357,8 @@ suite "Slot queue":
let items = SlotQueueItem.init(
request.id,
request.ask,
request.expiry,
collateral = request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
)
check items.len.uint16 == maxUInt16
@ -371,8 +371,8 @@ suite "Slot queue":
discard SlotQueueItem.init(
request.id,
request.ask,
request.expiry,
collateral = request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
)
test "cannot push duplicate items":
@ -413,11 +413,11 @@ suite "Slot queue":
newSlotQueue(maxSize = 8, maxWorkers = 1, processSlotDelay = 10.millis)
let request0 = StorageRequest.example
var request1 = StorageRequest.example
request1.ask.collateralPerByte += 1.u256
request1.ask.collateralPerByte += 1.u128
let items0 =
SlotQueueItem.init(request0, collateral = request0.ask.collateralPerSlot)
SlotQueueItem.init(request0, request0.ask.collateralPerSlot.stuint(256))
let items1 =
SlotQueueItem.init(request1, collateral = request1.ask.collateralPerSlot)
SlotQueueItem.init(request1, request1.ask.collateralPerSlot.stuint(256))
check queue.push(items0).isOk
check queue.push(items1).isOk
let last = items1[items1.high]
@ -429,11 +429,11 @@ suite "Slot queue":
newSlotQueue(maxSize = 8, maxWorkers = 1, processSlotDelay = 10.millis)
let request0 = StorageRequest.example
var request1 = StorageRequest.example
request1.ask.collateralPerByte += 1.u256
request1.ask.collateralPerByte += 1.u128
let items0 =
SlotQueueItem.init(request0, collateral = request0.ask.collateralPerSlot)
SlotQueueItem.init(request0, request0.ask.collateralPerSlot.stuint(256))
let items1 =
SlotQueueItem.init(request1, collateral = request1.ask.collateralPerSlot)
SlotQueueItem.init(request1, request1.ask.collateralPerSlot.stuint(256))
check queue.push(items0).isOk
check queue.push(items1).isOk
queue.delete(request1.id)
@ -453,17 +453,17 @@ suite "Slot queue":
request4.ask.collateralPerByte = request3.ask.collateralPerByte + 1
request5.ask.collateralPerByte = request4.ask.collateralPerByte + 1
let item0 =
SlotQueueItem.init(request0, 0, collateral = request0.ask.collateralPerSlot)
SlotQueueItem.init(request0, 0, request0.ask.collateralPerSlot.stuint(256))
let item1 =
SlotQueueItem.init(request1, 0, collateral = request1.ask.collateralPerSlot)
SlotQueueItem.init(request1, 0, request1.ask.collateralPerSlot.stuint(256))
let item2 =
SlotQueueItem.init(request2, 0, collateral = request2.ask.collateralPerSlot)
SlotQueueItem.init(request2, 0, request2.ask.collateralPerSlot.stuint(256))
let item3 =
SlotQueueItem.init(request3, 0, collateral = request3.ask.collateralPerSlot)
SlotQueueItem.init(request3, 0, request3.ask.collateralPerSlot.stuint(256))
let item4 =
SlotQueueItem.init(request4, 0, collateral = request4.ask.collateralPerSlot)
SlotQueueItem.init(request4, 0, request4.ask.collateralPerSlot.stuint(256))
let item5 =
SlotQueueItem.init(request5, 0, collateral = request5.ask.collateralPerSlot)
SlotQueueItem.init(request5, 0, request5.ask.collateralPerSlot.stuint(256))
check queue.contains(item5) == false
check queue.push(@[item0, item1, item2, item3, item4, item5]).isOk
check queue.contains(item5)
@ -471,37 +471,37 @@ suite "Slot queue":
test "sorts items by profitability descending (higher pricePerBytePerSecond == higher priority == goes first in the list)":
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item1 =
SlotQueueItem.init(request, 1, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 1, request.ask.collateralPerSlot.stuint(256))
check item1 < item0
test "sorts items by collateral ascending (higher required collateral = lower priority == comes later in the list)":
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
let item1 = SlotQueueItem.init(
request, 1, collateral = request.ask.collateralPerSlot + 1.u256
request, 1, request.ask.collateralPerSlot.stuint(256) + 1.u256
)
check item1 > item0
test "sorts items by expiry descending (longer expiry = higher priority)":
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
request.expiry += 1
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
request.expiry += 1.stuint(40)
let item1 =
SlotQueueItem.init(request, 1, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 1, request.ask.collateralPerSlot.stuint(256))
check item1 < item0
test "sorts items by slot size descending (bigger dataset = higher profitability = higher priority)":
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
request.ask.slotSize += 1
let item1 =
SlotQueueItem.init(request, 1, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 1, request.ask.collateralPerSlot.stuint(256))
check item1 < item0
test "should call callback once an item is added":
@ -523,16 +523,16 @@ suite "Slot queue":
# calling the callback for each pushed/updated item
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item1 =
SlotQueueItem.init(request, 1, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 1, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item2 =
SlotQueueItem.init(request, 2, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 2, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item3 =
SlotQueueItem.init(request, 3, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 3, request.ask.collateralPerSlot.stuint(256))
check queue.push(item0).isOk
await sleepAsync(1.millis)
@ -558,16 +558,16 @@ suite "Slot queue":
# calling the callback for each pushed/updated item
var request = StorageRequest.example
let item0 =
SlotQueueItem.init(request, 0, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 0, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item1 =
SlotQueueItem.init(request, 1, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 1, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item2 =
SlotQueueItem.init(request, 2, collateral = request.ask.collateralPerSlot)
request.ask.pricePerBytePerSecond += 1.u256
SlotQueueItem.init(request, 2, request.ask.collateralPerSlot.stuint(256))
request.ask.pricePerBytePerSecond += 1.stuint(96)
let item3 =
SlotQueueItem.init(request, 3, collateral = request.ask.collateralPerSlot)
SlotQueueItem.init(request, 3, request.ask.collateralPerSlot.stuint(256))
check queue.push(item0).isOk
check queue.push(item1).isOk
@ -591,7 +591,7 @@ suite "Slot queue":
queue.pause
let request = StorageRequest.example
var items = SlotQueueItem.init(request, collateral = request.ask.collateralPerSlot)
var items = SlotQueueItem.init(request, request.ask.collateralPerSlot.stuint(256))
check queue.push(items).isOk
# check all items processed
check eventually queue.len == 0
@ -603,8 +603,8 @@ suite "Slot queue":
request.id,
0'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = true,
)
check queue.paused
@ -618,8 +618,8 @@ suite "Slot queue":
request.id,
1'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = false,
)
check queue.paused
@ -636,16 +636,16 @@ suite "Slot queue":
request.id,
0'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = false,
)
let seen = SlotQueueItem.init(
request.id,
1'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = true,
)
# push causes unpause
@ -664,16 +664,16 @@ suite "Slot queue":
request.id,
0'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = false,
)
let seen = SlotQueueItem.init(
request.id,
1'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = true,
)
# push seen item to ensure that queue is pausing
@ -696,16 +696,16 @@ suite "Slot queue":
request.id,
0'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = true,
)
let item1 = SlotQueueItem.init(
request.id,
1'u16,
request.ask,
request.expiry,
request.ask.collateralPerSlot,
request.expiry.u64,
request.ask.collateralPerSlot.stuint(256),
seen = true,
)
check queue.push(item0).isOk

View File

@ -29,8 +29,8 @@ asyncchecksuite "Purchasing":
ask: StorageAsk(
slots: uint8.example.uint64,
slotSize: uint32.example.uint64,
duration: uint16.example.uint64,
pricePerBytePerSecond: uint8.example.u256,
duration: uint16.example.stuint(40),
pricePerBytePerSecond: uint8.example.stuint(96),
)
)
@ -130,8 +130,8 @@ suite "Purchasing state machine":
ask: StorageAsk(
slots: uint8.example.uint64,
slotSize: uint32.example.uint64,
duration: uint16.example.uint64,
pricePerBytePerSecond: uint8.example.u256,
duration: uint16.example.stuint(40),
pricePerBytePerSecond: uint8.example.stuint(96),
)
)
@ -184,7 +184,8 @@ suite "Purchasing state machine":
test "moves to PurchaseStarted when request state is Started":
let request = StorageRequest.example
let purchase = Purchase.new(request, market, clock)
market.requestEnds[request.id] = clock.now() + request.ask.duration.int64
let duration = request.ask.duration.toSecondsSince1970
market.requestEnds[request.id] = clock.now() + duration
market.requested = @[request]
market.requestState[request.id] = RequestState.Started
let next = await PurchaseUnknown().run(purchase)
@ -217,7 +218,8 @@ suite "Purchasing state machine":
test "moves to PurchaseFailed state once RequestFailed emitted":
let request = StorageRequest.example
let purchase = Purchase.new(request, market, clock)
market.requestEnds[request.id] = clock.now() + request.ask.duration.int64
let duration = request.ask.duration.toSecondsSince1970
market.requestEnds[request.id] = clock.now() + duration
let future = PurchaseStarted().run(purchase)
market.emitRequestFailed(request.id)
@ -228,10 +230,11 @@ suite "Purchasing state machine":
test "moves to PurchaseFinished state once request finishes":
let request = StorageRequest.example
let purchase = Purchase.new(request, market, clock)
market.requestEnds[request.id] = clock.now() + request.ask.duration.int64
let duration = request.ask.duration.toSecondsSince1970
market.requestEnds[request.id] = clock.now() + duration
let future = PurchaseStarted().run(purchase)
clock.advance(request.ask.duration.int64 + 1)
clock.advance(duration + 1)
let next = await future
check !next of PurchaseFinished

View File

@ -51,8 +51,8 @@ asyncchecksuite "validation":
groupIndex = groupIndexForSlotId(slot.id, !validationGroups)
clock = MockClock.new()
market = MockMarket.new(clock = Clock(clock).some)
market.config.proofs.period = period
market.config.proofs.timeout = timeout
market.config.proofs.period = period.stuint(40)
market.config.proofs.timeout = timeout.stuint(40)
validation = newValidation(clock, market, maxSlots, validationGroups, groupIndex)
teardown:

View File

@ -18,7 +18,7 @@ ethersuite "Marketplace contracts":
var filledAt: UInt256
proc expectedPayout(endTimestamp: UInt256): UInt256 =
return (endTimestamp - filledAt) * request.ask.pricePerSlotPerSecond()
return (endTimestamp - filledAt) * request.ask.pricePerSlotPerSecond.stuint(256)
proc switchAccount(account: Signer) =
marketplace = marketplace.connect(account)
@ -35,17 +35,17 @@ ethersuite "Marketplace contracts":
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
let config = await marketplace.configuration()
periodicity = Periodicity(seconds: config.proofs.period)
periodicity = Periodicity(seconds: config.proofs.period.u64)
request = StorageRequest.example
request.client = await client.getAddress()
switchAccount(client)
discard await token.approve(marketplace.address, request.totalPrice).confirm(1)
discard await token.approve(marketplace.address, request.totalPrice.stuint(256)).confirm(1)
discard await marketplace.requestStorage(request).confirm(1)
switchAccount(host)
discard
await token.approve(marketplace.address, request.ask.collateralPerSlot).confirm(1)
await token.approve(marketplace.address, request.ask.collateralPerSlot.stuint(256)).confirm(1)
discard await marketplace.reserveSlot(request.id, 0.uint64).confirm(1)
let receipt = await marketplace.fillSlot(request.id, 0.uint64, proof).confirm(1)
filledAt = await ethProvider.blockTime(BlockTag.init(!receipt.blockNumber))
@ -65,7 +65,7 @@ ethersuite "Marketplace contracts":
proc startContract() {.async.} =
for slotIndex in 1 ..< request.ask.slots:
discard await token
.approve(marketplace.address, request.ask.collateralPerSlot)
.approve(marketplace.address, request.ask.collateralPerSlot.stuint(256))
.confirm(1)
discard await marketplace.reserveSlot(request.id, slotIndex.uint64).confirm(1)
discard await marketplace.fillSlot(request.id, slotIndex.uint64, proof).confirm(1)
@ -83,7 +83,7 @@ ethersuite "Marketplace contracts":
let endOfPeriod = periodicity.periodEnd(missingPeriod)
await ethProvider.advanceTimeTo(endOfPeriod.u256 + 1)
switchAccount(client)
discard await marketplace.markProofAsMissing(slotId, missingPeriod).confirm(1)
discard await marketplace.markProofAsMissing(slotId, missingPeriod.stuint(40)).confirm(1)
test "can be paid out at the end":
switchAccount(host)
@ -95,7 +95,7 @@ ethersuite "Marketplace contracts":
discard await marketplace.freeSlot(slotId).confirm(1)
let endBalance = await token.balanceOf(address)
check endBalance ==
(startBalance + expectedPayout(requestEnd.u256) + request.ask.collateralPerSlot)
(startBalance + expectedPayout(requestEnd.u256) + request.ask.collateralPerSlot.stuint(256))
test "cannot mark proofs missing for cancelled request":
let expiry = await marketplace.requestExpiry(request.id)
@ -105,4 +105,4 @@ ethersuite "Marketplace contracts":
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await ethProvider.advanceTime(periodicity.seconds.u256)
expect Marketplace_SlotNotAcceptingProofs:
discard await marketplace.markProofAsMissing(slotId, missingPeriod).confirm(1)
discard await marketplace.markProofAsMissing(slotId, missingPeriod.stuint(40)).confirm(1)

View File

@ -33,7 +33,7 @@ ethersuite "On-Chain Market":
proc expectedPayout(
r: StorageRequest, startTimestamp: UInt256, endTimestamp: UInt256
): UInt256 =
return (endTimestamp - startTimestamp) * r.ask.pricePerSlotPerSecond
return (endTimestamp - startTimestamp) * r.ask.pricePerSlotPerSecond.stuint(256)
proc switchAccount(account: Signer) {.async.} =
marketplace = marketplace.connect(account)
@ -49,7 +49,7 @@ ethersuite "On-Chain Market":
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
periodicity = Periodicity(seconds: config.proofs.period)
periodicity = Periodicity(seconds: config.proofs.period.u64)
request = StorageRequest.example
request.client = accounts[0]
@ -88,12 +88,12 @@ ethersuite "On-Chain Market":
let periodicity = market.periodicity
let config = await marketplace.configuration()
let periodLength = config.proofs.period
check periodicity.seconds == periodLength
check periodicity.seconds == periodLength.u64
test "can retrieve proof timeout":
let proofTimeout = market.proofTimeout
let config = await marketplace.configuration()
check proofTimeout == config.proofs.timeout
check proofTimeout == config.proofs.timeout.u64
test "supports marketplace requests":
await market.requestStorage(request)
@ -114,7 +114,7 @@ ethersuite "On-Chain Market":
let endBalanceClient = await token.balanceOf(clientAddress)
check endBalanceClient == (startBalanceClient + request.totalPrice)
check endBalanceClient == (startBalanceClient + request.totalPrice.stuint(256))
test "supports request subscriptions":
var receivedIds: seq[RequestId]
@ -326,7 +326,7 @@ ethersuite "On-Chain Market":
let missingPeriod =
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await advanceToNextPeriod()
discard await marketplace.markProofAsMissing(slotId, missingPeriod).confirm(1)
discard await marketplace.markProofAsMissing(slotId, missingPeriod.stuint(40)).confirm(1)
check eventually receivedIds == @[request.id]
await subscription.unsubscribe()
@ -524,7 +524,7 @@ ethersuite "On-Chain Market":
let endBalance = await token.balanceOf(address)
let expectedPayout = request.expectedPayout(filledAt, requestEnd.u256)
check endBalance == (startBalance + expectedPayout + request.ask.collateralPerSlot)
check endBalance == (startBalance + expectedPayout + request.ask.collateralPerSlot.stuint(256))
test "the request is added to cache after the first access":
await market.requestStorage(request)

View File

@ -40,6 +40,9 @@ proc example*[T](_: type seq[T]): seq[T] =
proc example*(_: type UInt256): UInt256 =
UInt256.fromBytes(array[32, byte].example)
proc example*(_: type UInt128): UInt128 =
UInt128.fromBytes(array[16, byte].example)
proc example*[T: distinct](_: type T): T =
type baseType = T.distinctBase
T(baseType.example)
@ -50,17 +53,17 @@ proc example*(_: type StorageRequest): StorageRequest =
ask: StorageAsk(
slots: 4,
slotSize: (1 * 1024 * 1024 * 1024).uint64, # 1 Gigabyte
duration: (10 * 60 * 60).uint64, # 10 hours
collateralPerByte: 1.u256,
duration: (10 * 60 * 60).stuint(40), # 10 hours
collateralPerByte: 1.u128,
proofProbability: 4.u256, # require a proof roughly once every 4 periods
pricePerBytePerSecond: 1.u256,
pricePerBytePerSecond: 1.stuint(96),
maxSlotLoss: 2, # 2 slots can be freed without data considered to be lost
),
content: StorageContent(
cid: Cid.init("zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob").tryGet,
merkleRoot: array[32, byte].example,
),
expiry: (60 * 60).uint64, # 1 hour ,
expiry: (60 * 60).stuint(40), # 1 hour ,
nonce: Nonce.example,
)
@ -72,9 +75,8 @@ proc example*(_: type Slot): Slot =
proc example*(_: type SlotQueueItem): SlotQueueItem =
let request = StorageRequest.example
let slot = Slot.example
SlotQueueItem.init(
request, slot.slotIndex.uint16, collateral = request.ask.collateralPerSlot
)
let collateral = request.ask.collateralPerSlot.stuint(256)
SlotQueueItem.init(request, slot.slotIndex.uint16, collateral)
proc example(_: type G1Point): G1Point =
G1Point(x: UInt256.example, y: UInt256.example)

View File

@ -217,11 +217,11 @@ proc space*(
proc requestStorageRaw*(
client: CodexClient,
cid: Cid,
duration: uint64,
pricePerBytePerSecond: UInt256,
duration: StUint[40],
pricePerBytePerSecond: StUint[96],
proofProbability: UInt256,
collateralPerByte: UInt256,
expiry: uint64 = 0,
collateralPerByte: UInt128,
expiry = 0.stuint(40),
nodes: uint = 3,
tolerance: uint = 1,
): Future[HttpClientResponseRef] {.
@ -240,7 +240,7 @@ proc requestStorageRaw*(
"tolerance": tolerance,
}
if expiry != 0:
if expiry != 0.stuint(40):
json["expiry"] = %($expiry)
return client.post(url, $json)
@ -248,11 +248,11 @@ proc requestStorageRaw*(
proc requestStorage*(
client: CodexClient,
cid: Cid,
duration: uint64,
pricePerBytePerSecond: UInt256,
duration: StUint[40],
pricePerBytePerSecond: StUint[96],
proofProbability: UInt256,
expiry: uint64,
collateralPerByte: UInt256,
expiry: StUint[40],
collateralPerByte: UInt128,
nodes: uint = 3,
tolerance: uint = 1,
): Future[?!PurchaseId] {.async: (raises: [CancelledError, HttpError]).} =

View File

@ -77,10 +77,10 @@ template marketplacesuite*(name: string, body: untyped) =
client: CodexClient,
cid: Cid,
proofProbability = 1.u256,
duration: uint64 = 12.periods,
pricePerBytePerSecond = 1.u256,
collateralPerByte = 1.u256,
expiry: uint64 = 4.periods,
duration = 12.periods.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
collateralPerByte = 1.u128,
expiry = 4.periods.stuint(40),
nodes = providers().len,
tolerance = 0,
): Future[PurchaseId] {.async: (raises: [CancelledError, HttpError]).} =
@ -104,7 +104,7 @@ template marketplacesuite*(name: string, body: untyped) =
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
let config = await marketplace.configuration()
period = config.proofs.period
period = config.proofs.period.u64
periodicity = Periodicity(seconds: period)
body

View File

@ -34,12 +34,12 @@ marketplacesuite "Bug #821 - node crashes during erasure coding":
let subscription = await marketplace.subscribe(StorageRequested, onStorageRequested)
# client requests storage but requires multiple slots to host the content
let id = await clientApi.requestStorage(
discard await clientApi.requestStorage(
cid,
duration = duration,
pricePerBytePerSecond = pricePerBytePerSecond,
expiry = expiry,
collateralPerByte = collateralPerByte,
duration = duration.stuint(40),
pricePerBytePerSecond = pricePerBytePerSecond.stuint(96),
expiry = expiry.stuint(40),
collateralPerByte = collateralPerByte.stuint(128),
nodes = 3,
tolerance = 1,
)

View File

@ -19,7 +19,7 @@ marketplacesuite "Marketplace":
var clientAccount: Address
const minPricePerBytePerSecond = 1.u256
const collateralPerByte = 1.u256
const collateralPerByte = 1.u128
const blocks = 8
const ecNodes = 3
const ecTolerance = 1
@ -52,10 +52,10 @@ marketplacesuite "Marketplace":
let cid = (await client.upload(data)).get
let id = await client.requestStorage(
cid,
duration = 20 * 60.uint64,
pricePerBytePerSecond = minPricePerBytePerSecond,
duration = 20 * 60.stuint(40),
pricePerBytePerSecond = minPricePerBytePerSecond.stuint(96),
proofProbability = 3.u256,
expiry = 10 * 60.uint64,
expiry = 10 * 60.stuint(40),
collateralPerByte = collateralPerByte,
nodes = ecNodes,
tolerance = ecTolerance,
@ -89,7 +89,7 @@ marketplacesuite "Marketplace":
discard (
await host.postAvailability(
totalSize = size,
duration = 20 * 60.uint64,
duration = duration,
minPricePerBytePerSecond = minPricePerBytePerSecond,
totalCollateral = size.u256 * minPricePerBytePerSecond,
)
@ -99,10 +99,10 @@ marketplacesuite "Marketplace":
let cid = (await client.upload(data)).get
let id = await client.requestStorage(
cid,
duration = duration,
pricePerBytePerSecond = minPricePerBytePerSecond,
duration = duration.stuint(40),
pricePerBytePerSecond = minPricePerBytePerSecond.stuint(96),
proofProbability = 3.u256,
expiry = 10 * 60.uint64,
expiry = (10 * 60).stuint(40),
collateralPerByte = collateralPerByte,
nodes = ecNodes,
tolerance = ecTolerance,
@ -135,7 +135,7 @@ marketplacesuite "Marketplace":
marketplacesuite "Marketplace payouts":
const minPricePerBytePerSecond = 1.u256
const collateralPerByte = 1.u256
const collateralPerByte = 1.u128
const blocks = 8
const ecNodes = 3
const ecTolerance = 1
@ -174,7 +174,7 @@ marketplacesuite "Marketplace payouts":
totalSize = totalAvailabilitySize,
duration = duration.uint64,
minPricePerBytePerSecond = minPricePerBytePerSecond,
totalCollateral = collateralPerByte * totalAvailabilitySize.u256,
totalCollateral = collateralPerByte.stuint(256) * totalAvailabilitySize.u256,
)
let cid = (await clientApi.upload(data)).get
@ -189,9 +189,9 @@ marketplacesuite "Marketplace payouts":
# client requests storage but requires multiple slots to host the content
let id = await clientApi.requestStorage(
cid,
duration = duration,
pricePerBytePerSecond = minPricePerBytePerSecond,
expiry = expiry,
duration = duration.stuint(40),
pricePerBytePerSecond = minPricePerBytePerSecond.stuint(96),
expiry = expiry.stuint(40),
collateralPerByte = collateralPerByte,
nodes = ecNodes,
tolerance = ecTolerance,

View File

@ -53,8 +53,8 @@ marketplacesuite "Hosts submit regular proofs":
let purchaseId = await client0.requestStorage(
cid,
expiry = expiry,
duration = duration,
expiry = expiry.stuint(40),
duration = duration.stuint(40),
nodes = ecNodes,
tolerance = ecTolerance,
)
@ -131,8 +131,8 @@ marketplacesuite "Simulate invalid proofs":
let purchaseId = (
await client0.requestStorage(
cid,
expiry = expiry,
duration = duration,
expiry = expiry.stuint(40),
duration = duration.stuint(40),
nodes = ecNodes,
tolerance = ecTolerance,
proofProbability = 1.u256,
@ -195,8 +195,8 @@ marketplacesuite "Simulate invalid proofs":
let purchaseId = await client0.requestStorage(
cid,
expiry = expiry,
duration = duration,
expiry = expiry.stuint(40),
duration = duration.stuint(40),
nodes = ecNodes,
tolerance = ecTolerance,
proofProbability = 1.u256,

View File

@ -12,21 +12,21 @@ twonodessuite "Purchasing":
let id1 = (
await client1.requestStorage(
cid,
duration = 100.uint64,
pricePerBytePerSecond = 1.u256,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 10.uint64,
collateralPerByte = 1.u256,
expiry = 10.stuint(40),
collateralPerByte = 1.u128,
)
).get
let id2 = (
await client1.requestStorage(
cid,
duration = 400.uint64,
pricePerBytePerSecond = 2.u256,
duration = 400.stuint(40),
pricePerBytePerSecond = 2.stuint(96),
proofProbability = 6.u256,
expiry = 10.uint64,
collateralPerByte = 2.u256,
expiry = 10.stuint(40),
collateralPerByte = 2.u128,
)
).get
check id1 != id2
@ -42,11 +42,11 @@ twonodessuite "Purchasing":
let id = (
await client1.requestStorage(
cid,
duration = 100.uint64,
pricePerBytePerSecond = 1.u256,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.uint64,
collateralPerByte = 1.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3,
tolerance = 1,
)
@ -55,11 +55,11 @@ twonodessuite "Purchasing":
let request = (await client1.getPurchase(id)).get.request.get
check request.content.cid.data.buffer.len > 0
check request.ask.duration == 100.uint64
check request.ask.pricePerBytePerSecond == 1.u256
check request.ask.duration == 100.stuint(40)
check request.ask.pricePerBytePerSecond == 1.stuint(96)
check request.ask.proofProbability == 3.u256
check request.expiry == 30.uint64
check request.ask.collateralPerByte == 1.u256
check request.expiry == 30.stuint(40)
check request.ask.collateralPerByte == 1.u128
check request.ask.slots == 3'u64
check request.ask.maxSlotLoss == 1'u64
@ -85,11 +85,11 @@ twonodessuite "Purchasing":
let id = (
await client1.requestStorage(
cid,
duration = 10 * 60.uint64,
pricePerBytePerSecond = 1.u256,
duration = (10 * 60).stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 5 * 60.uint64,
collateralPerByte = 1.u256,
expiry = 5 * 60.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 1.uint,
)
@ -104,11 +104,11 @@ twonodessuite "Purchasing":
await client1.purchaseStateIs(id, "submitted"), timeout = 3 * 60 * 1000
)
let request = (await client1.getPurchase(id)).get.request.get
check request.ask.duration == (10 * 60).uint64
check request.ask.pricePerBytePerSecond == 1.u256
check request.ask.duration == (10 * 60).stuint(40)
check request.ask.pricePerBytePerSecond == 1.stuint(96)
check request.ask.proofProbability == 3.u256
check request.expiry == (5 * 60).uint64
check request.ask.collateralPerByte == 1.u256
check request.expiry == (5 * 60).stuint(40)
check request.ask.collateralPerByte == 1.u128
check request.ask.slots == 3'u64
check request.ask.maxSlotLoss == 1'u64
@ -118,10 +118,10 @@ twonodessuite "Purchasing":
let responseMissing = await client1.requestStorageRaw(
cid,
duration = 1.uint64,
pricePerBytePerSecond = 1.u256,
duration = 1.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u256,
collateralPerByte = 1.u128,
)
check responseMissing.status == 422
check (await responseMissing.body) ==
@ -129,11 +129,11 @@ twonodessuite "Purchasing":
let responseBefore = await client1.requestStorageRaw(
cid,
duration = 10.uint64,
pricePerBytePerSecond = 1.u256,
duration = 10.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u256,
expiry = 10.uint64,
collateralPerByte = 1.u128,
expiry = 10.stuint(40),
)
check responseBefore.status == 422
check "Expiry must be greater than zero and less than the request's duration" in

View File

@ -1,3 +1,4 @@
import std/importutils
import std/net
import std/sequtils
@ -62,11 +63,11 @@ twonodessuite "REST API":
let response = (
await client1.requestStorageRaw(
cid,
duration = 10.uint64,
pricePerBytePerSecond = 1.u256,
duration = 10.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u256,
expiry = 9.uint64,
collateralPerByte = 1.u128,
expiry = 9.stuint(40),
)
)
@ -81,20 +82,18 @@ twonodessuite "REST API":
fmt"({minBlocks=}, {nodes=}, {tolerance=})", twoNodesConfig:
let data = await RandomChunker.example(blocks = minBlocks)
let cid = (await client1.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
var responseBefore = (
await client1.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte,
expiry, nodes.uint, tolerance.uint,
)
let response = await client1.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u128,
expiry = 30.stuint(40),
nodes = nodes.uint,
tolerance = tolerance.uint,
)
check responseBefore.status == 200
check response.status == 200
test "node accepts file uploads with content type", twoNodesConfig:
let headers = @[("Content-Type", "text/plain")]

View File

@ -20,33 +20,30 @@ multinodesuite "Rest API validation":
test "should return 422 when attempting delete of non-existing dataset", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 0
var responseBefore = await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte, expiry,
nodes.uint, tolerance.uint,
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u128,
expiry = 30.stuint(40),
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) == "Tolerance needs to be bigger then zero"
check response.status == 422
check (await response.body) == "Tolerance needs to be bigger then zero"
test "request storage fails for datasets that are too small", config:
let cid = (await client.upload("some file contents")).get
let response = (
await client.requestStorageRaw(
cid,
duration = 10.uint64,
pricePerBytePerSecond = 1.u256,
proofProbability = 3.u256,
collateralPerByte = 1.u256,
expiry = 9.uint64,
)
let response = await client.requestStorageRaw(
cid,
duration = 10.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
collateralPerByte = 1.u128,
expiry = 9.stuint(40),
)
check:
@ -58,47 +55,47 @@ multinodesuite "Rest API validation":
test "request storage fails if nodes and tolerance aren't correct", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let ecParams = @[(1, 1), (2, 1), (3, 2), (3, 3)]
for ecParam in ecParams:
let (nodes, tolerance) = ecParam
var responseBefore = (
let response = (
await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte,
expiry, nodes.uint, tolerance.uint,
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = nodes.uint,
tolerance =tolerance.uint,
)
)
check responseBefore.status == 422
check (await responseBefore.body) ==
check response.status == 422
check (await response.body) ==
"Invalid parameters: parameters must satify `1 < (nodes - tolerance) ≥ tolerance`"
test "request storage fails if tolerance > nodes (underflow protection)", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 0
var responseBefore = (
let response = (
await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte,
expiry, nodes.uint, tolerance.uint,
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
)
check responseBefore.status == 422
check (await responseBefore.body) == "Tolerance needs to be bigger then zero"
check response.status == 422
check (await response.body) == "Tolerance needs to be bigger then zero"
test "upload fails if content disposition contains bad filename", config:
let headers = @[("Content-Disposition", "attachment; filename=\"exam*ple.txt\"")]
@ -224,123 +221,111 @@ multinodesuite "Rest API validation":
test "request storage fails if tolerance is zero", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 0
var responseBefore = (
await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte,
expiry, nodes.uint, tolerance.uint,
)
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) == "Tolerance needs to be bigger then zero"
check response.status == 422
check (await response.body) == "Tolerance needs to be bigger then zero"
test "request storage fails if duration exceeds limit", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = (31 * 24 * 60 * 60).uint64
# 31 days TODO: this should not be hardcoded, but waits for https://github.com/codex-storage/nim-codex/issues/1056
let proofProbability = 3.u256
let expiry = 30.uint
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 2
let pricePerBytePerSecond = 1.u256
var responseBefore = (
await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte,
expiry, nodes.uint, tolerance.uint,
)
let response = await client.requestStorageRaw(
cid,
duration = (31 * 24 * 60 * 60).stuint(40), # 31 days TODO: this should not be hardcoded, but waits for https://github.com/codex-storage/nim-codex/issues/1056
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 2.uint,
)
check responseBefore.status == 422
check "Duration exceeds limit of" in (await responseBefore.body)
check response.status == 422
check "Duration exceeds limit of" in (await response.body)
test "request storage fails if expiry is zero", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 0.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 1
var responseBefore = await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte, expiry,
nodes.uint, tolerance.uint,
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 0.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) ==
check response.status == 422
check (await response.body) ==
"Expiry must be greater than zero and less than the request's duration"
test "request storage fails if proof probability is zero", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 0.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 1
var responseBefore = await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte, expiry,
nodes.uint, tolerance.uint,
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 0.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) == "Proof probability must be greater than zero"
check response.status == 422
check (await response.body) == "Proof probability must be greater than zero"
test "request storage fails if price per byte per second is zero", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 0.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 1.u256
let nodes = 3
let tolerance = 1
var responseBefore = await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte, expiry,
nodes.uint, tolerance.uint,
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 0.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 1.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) ==
check response.status == 422
check (await response.body) ==
"Price per byte per second must be greater than zero"
test "request storage fails if collareral per byte is zero", config:
let data = await RandomChunker.example(blocks = 2)
let cid = (await client.upload(data)).get
let duration = 100.uint64
let pricePerBytePerSecond = 1.u256
let proofProbability = 3.u256
let expiry = 30.uint64
let collateralPerByte = 0.u256
let nodes = 3
let tolerance = 1
var responseBefore = await client.requestStorageRaw(
cid, duration, pricePerBytePerSecond, proofProbability, collateralPerByte, expiry,
nodes.uint, tolerance.uint,
let response = await client.requestStorageRaw(
cid,
duration = 100.stuint(40),
pricePerBytePerSecond = 1.stuint(96),
proofProbability = 3.u256,
expiry = 30.stuint(40),
collateralPerByte = 0.u128,
nodes = 3.uint,
tolerance = 0.uint,
)
check responseBefore.status == 422
check (await responseBefore.body) == "Collateral per byte must be greater than zero"
check response.status == 422
check (await response.body) == "Collateral per byte must be greater than zero"
test "creating availability fails when until is negative", config:
let totalSize = 12.uint64

View File

@ -131,11 +131,11 @@ multinodesuite "Sales":
let id = (
await client.requestStorage(
cid,
duration = 20 * 60.uint64,
pricePerBytePerSecond = minPricePerBytePerSecond,
duration = (20 * 60).stuint(40),
pricePerBytePerSecond = minPricePerBytePerSecond.stuint(96),
proofProbability = 3.u256,
expiry = (10 * 60).uint64,
collateralPerByte = collateralPerByte,
expiry = (10 * 60).stuint(40),
collateralPerByte = collateralPerByte.stuint(128),
nodes = 3,
tolerance = 1,
)

View File

@ -109,8 +109,8 @@ marketplacesuite "Validation":
let cid = (await client0.upload(data)).get
let purchaseId = await client0.requestStorage(
cid,
expiry = expiry,
duration = duration,
expiry = expiry.stuint(40),
duration = duration.stuint(40),
nodes = ecNodes,
tolerance = ecTolerance,
proofProbability = proofProbability,
@ -179,8 +179,8 @@ marketplacesuite "Validation":
let cid = (await client0.upload(data)).get
let purchaseId = await client0.requestStorage(
cid,
expiry = expiry,
duration = duration,
expiry = expiry.stuint(40),
duration = duration.stuint(40),
nodes = ecNodes,
tolerance = ecTolerance,
proofProbability = proofProbability,