mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-09 18:36:29 +00:00
29433bad9a
* Use http subscriptions instead of websocket for tests To work around this issue when subscriptions are inactive for more than 5 minutes: https://github.com/NomicFoundation/hardhat/issues/2053 Use 100 millisecond polling; default polling interval of 4 seconds is too close to the 5 second timeout for `check eventually`. * use .confirm(1) instead of confirm(0) confirm(0) doesn't wait at all, confirm(1) waits for the transaction to be mined * speed up partial payout integration test * update nim-ethers to version 0.10.0 includes fixes for http polling and .confirm() * fix timing of marketplace tests allow for a bit more time to withdraw funds * use .confirm(1) in marketplace tests to ensure that the transaction has been processed before continuing with the test * fix timing issue in validation unit test * fix proof integration test there were two logic errors in this test: - a slot is freed anyway at the end of the contract - when starting the request takes a long time, the first slot can already be freed because there were too many missing proofs * fix intermittent error in contract tests currentTime() doesn't always correctly reflect the time of the next transaction * reduce number of slots in integration test otherwise the windows runner in the CI won't be able to start the request before it expires * fix timing in purchasing test allow for a bit more time for a request to be submitted * fix timing of request submission in test windows ci is so slow, it can take up to 40 seconds just to submit a storage request to hardhat * increase proof period to 90 seconds * adjust timing of integration tests reason: with the increased period length of 90 seconds, it can take longer to wait for a stable challenge at the beginning of a period. * increase CI timeout to 2 hours * Fix slow builds on windows apparently it takes windows 2-3 seconds to resolve "localhost" to 127.0.0.1 for every json-rpc connection that we make 🤦
84 lines
4.1 KiB
Nim
84 lines
4.1 KiB
Nim
import std/httpclient
|
|
import pkg/codex/contracts
|
|
import ./twonodes
|
|
import ../codex/examples
|
|
import ../contracts/time
|
|
|
|
proc findItem[T](items: seq[T], item: T): ?!T =
|
|
for tmp in items:
|
|
if tmp == item:
|
|
return success tmp
|
|
|
|
return failure("Not found")
|
|
|
|
twonodessuite "Sales", debug1 = false, debug2 = false:
|
|
|
|
test "node handles new storage availability":
|
|
let availability1 = client1.postAvailability(totalSize=1.u256, duration=2.u256, minPrice=3.u256, maxCollateral=4.u256).get
|
|
let availability2 = client1.postAvailability(totalSize=4.u256, duration=5.u256, minPrice=6.u256, maxCollateral=7.u256).get
|
|
check availability1 != availability2
|
|
|
|
test "node lists storage that is for sale":
|
|
let availability = client1.postAvailability(totalSize=1.u256, duration=2.u256, minPrice=3.u256, maxCollateral=4.u256).get
|
|
check availability in client1.getAvailabilities().get
|
|
|
|
test "updating non-existing availability":
|
|
let nonExistingResponse = client1.patchAvailabilityRaw(AvailabilityId.example, duration=100.u256.some, minPrice=200.u256.some, maxCollateral=200.u256.some)
|
|
check nonExistingResponse.status == "404 Not Found"
|
|
|
|
test "updating availability":
|
|
let availability = client1.postAvailability(totalSize=140000.u256, duration=200.u256, minPrice=300.u256, maxCollateral=300.u256).get
|
|
|
|
client1.patchAvailability(availability.id, duration=100.u256.some, minPrice=200.u256.some, maxCollateral=200.u256.some)
|
|
|
|
let updatedAvailability = (client1.getAvailabilities().get).findItem(availability).get
|
|
check updatedAvailability.duration == 100
|
|
check updatedAvailability.minPrice == 200
|
|
check updatedAvailability.maxCollateral == 200
|
|
check updatedAvailability.totalSize == 140000
|
|
check updatedAvailability.freeSize == 140000
|
|
|
|
test "updating availability - freeSize is not allowed to be changed":
|
|
let availability = client1.postAvailability(totalSize=140000.u256, duration=200.u256, minPrice=300.u256, maxCollateral=300.u256).get
|
|
let freeSizeResponse = client1.patchAvailabilityRaw(availability.id, freeSize=110000.u256.some)
|
|
check freeSizeResponse.status == "400 Bad Request"
|
|
check "not allowed" in freeSizeResponse.body
|
|
|
|
test "updating availability - updating totalSize":
|
|
let availability = client1.postAvailability(totalSize=140000.u256, duration=200.u256, minPrice=300.u256, maxCollateral=300.u256).get
|
|
client1.patchAvailability(availability.id, totalSize=100000.u256.some)
|
|
let updatedAvailability = (client1.getAvailabilities().get).findItem(availability).get
|
|
check updatedAvailability.totalSize == 100000
|
|
check updatedAvailability.freeSize == 100000
|
|
|
|
test "updating availability - updating totalSize does not allow bellow utilized":
|
|
let originalSize = 0xFFFFFF.u256
|
|
let data = await RandomChunker.example(blocks=8)
|
|
let availability = client1.postAvailability(totalSize=originalSize, duration=20*60.u256, minPrice=300.u256, maxCollateral=300.u256).get
|
|
|
|
# Lets create storage request that will utilize some of the availability's space
|
|
let cid = client2.upload(data).get
|
|
let id = client2.requestStorage(
|
|
cid,
|
|
duration=20*60.u256,
|
|
reward=400.u256,
|
|
proofProbability=3.u256,
|
|
expiry=10*60,
|
|
collateral=200.u256,
|
|
nodes = 3,
|
|
tolerance = 1).get
|
|
|
|
check eventually(client2.purchaseStateIs(id, "started"), timeout=10*60*1000)
|
|
let updatedAvailability = (client1.getAvailabilities().get).findItem(availability).get
|
|
check updatedAvailability.totalSize != updatedAvailability.freeSize
|
|
|
|
let utilizedSize = updatedAvailability.totalSize - updatedAvailability.freeSize
|
|
let totalSizeResponse = client1.patchAvailabilityRaw(availability.id, totalSize=(utilizedSize-1.u256).some)
|
|
check totalSizeResponse.status == "400 Bad Request"
|
|
check "totalSize must be larger then current totalSize" in totalSizeResponse.body
|
|
|
|
client1.patchAvailability(availability.id, totalSize=(originalSize + 20000).some)
|
|
let newUpdatedAvailability = (client1.getAvailabilities().get).findItem(availability).get
|
|
check newUpdatedAvailability.totalSize == originalSize + 20000
|
|
check newUpdatedAvailability.freeSize - updatedAvailability.freeSize == 20000
|