2022-03-28 14:44:59 +00:00
|
|
|
import std/random
|
2022-04-13 16:41:48 +00:00
|
|
|
import std/sequtils
|
2022-11-08 07:10:17 +00:00
|
|
|
import std/times
|
2022-08-18 05:55:53 +00:00
|
|
|
import pkg/codex/proving
|
2022-03-28 14:44:59 +00:00
|
|
|
import pkg/stint
|
|
|
|
|
|
|
|
proc example*[T: SomeInteger](_: type T): T =
|
|
|
|
rand(T)
|
|
|
|
|
|
|
|
proc example*[T,N](_: type array[N, T]): array[N, T] =
|
|
|
|
for item in result.mitems:
|
|
|
|
item = T.example
|
|
|
|
|
2022-04-13 16:41:48 +00:00
|
|
|
proc example*[T](_: type seq[T]): seq[T] =
|
|
|
|
let length = uint8.example.int
|
|
|
|
newSeqWith(length, T.example)
|
|
|
|
|
2022-03-28 14:44:59 +00:00
|
|
|
proc example*(_: type UInt256): UInt256 =
|
|
|
|
UInt256.fromBytes(array[32, byte].example)
|
2022-08-18 05:55:53 +00:00
|
|
|
|
|
|
|
proc example*[T: RequestId | SlotId | Nonce](_: type T): T =
|
|
|
|
T(array[32, byte].example)
|
2022-11-08 07:10:17 +00:00
|
|
|
|
|
|
|
proc example*(_: type StorageRequest): StorageRequest =
|
|
|
|
StorageRequest(
|
|
|
|
client: Address.example,
|
|
|
|
ask: StorageAsk(
|
|
|
|
slots: 4,
|
|
|
|
slotSize: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
|
|
|
|
duration: (10 * 60 * 60).u256, # 10 hours
|
|
|
|
proofProbability: 4.u256, # require a proof roughly once every 4 periods
|
|
|
|
reward: 84.u256,
|
|
|
|
maxSlotLoss: 2 # 2 slots can be freed without data considered to be lost
|
|
|
|
),
|
|
|
|
content: StorageContent(
|
|
|
|
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",
|
|
|
|
erasure: StorageErasure(
|
|
|
|
totalChunks: 12,
|
|
|
|
),
|
2023-03-10 07:02:54 +00:00
|
|
|
por: StoragePoR(
|
2022-11-08 07:10:17 +00:00
|
|
|
u: @(array[480, byte].example),
|
|
|
|
publicKey: @(array[96, byte].example),
|
|
|
|
name: @(array[512, byte].example)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
expiry: (getTime() + initDuration(hours=1)).toUnix.u256,
|
|
|
|
nonce: Nonce.example
|
|
|
|
)
|
|
|
|
|
2023-03-27 13:47:25 +00:00
|
|
|
proc example*(_: type Slot): Slot =
|
|
|
|
let request = StorageRequest.example
|
|
|
|
let slotIndex = rand(request.ask.slots.int).u256
|
|
|
|
Slot(request: request, slotIndex: slotIndex)
|
|
|
|
|
2022-11-08 07:10:17 +00:00
|
|
|
proc exampleProof*(): seq[byte] =
|
|
|
|
var proof: seq[byte]
|
|
|
|
while proof.len == 0:
|
|
|
|
proof = seq[byte].example
|
|
|
|
return proof
|