Skip to content

Commit

Permalink
WIP debugging integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markspanbroek committed Nov 13, 2024
1 parent b9d1ec7 commit bf5404b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 90 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ jobs:
uses: fabiocaccamo/create-matrix-action@v4
with:
matrix: |
os {linux}, cpu {amd64}, builder {ubuntu-20.04}, tests {all}, nim_version {${{ env.nim_version }}}, shell {bash --noprofile --norc -e -o pipefail}
os {macos}, cpu {amd64}, builder {macos-13}, tests {all}, nim_version {${{ env.nim_version }}}, shell {bash --noprofile --norc -e -o pipefail}
os {windows}, cpu {amd64}, builder {windows-latest}, tests {unittest}, nim_version {${{ env.nim_version }}}, shell {msys2}
os {windows}, cpu {amd64}, builder {windows-latest}, tests {contract}, nim_version {${{ env.nim_version }}}, shell {msys2}
os {windows}, cpu {amd64}, builder {windows-latest}, tests {integration}, nim_version {${{ env.nim_version }}}, shell {msys2}
os {windows}, cpu {amd64}, builder {windows-latest}, tests {tools}, nim_version {${{ env.nim_version }}}, shell {msys2}
build:
needs: matrix
Expand Down
78 changes: 39 additions & 39 deletions tests/integration/testpurchasing.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ import ./twonodes
import ../contracts/time
import ../examples

twonodessuite "Purchasing", debug1 = false, debug2 = false:
twonodessuite "Purchasing", debug1 = true, debug2 = false:

test "node handles storage request":
let data = await RandomChunker.example(blocks=2)
let cid = client1.upload(data).get
let id1 = client1.requestStorage(cid, duration=100.u256, reward=2.u256, proofProbability=3.u256, expiry=10, collateral=200.u256).get
let id2 = client1.requestStorage(cid, duration=400.u256, reward=5.u256, proofProbability=6.u256, expiry=10, collateral=201.u256).get
check id1 != id2
# test "node handles storage request":
# let data = await RandomChunker.example(blocks=2)
# let cid = client1.upload(data).get
# let id1 = client1.requestStorage(cid, duration=100.u256, reward=2.u256, proofProbability=3.u256, expiry=10, collateral=200.u256).get
# let id2 = client1.requestStorage(cid, duration=400.u256, reward=5.u256, proofProbability=6.u256, expiry=10, collateral=201.u256).get
# check id1 != id2

test "node retrieves purchase status":
# get one contiguous chunk
let rng = rng.Rng.instance()
let chunker = RandomChunker.new(rng, size = DefaultBlockSize * 2, chunkSize = DefaultBlockSize * 2)
let data = await chunker.getBytes()
let cid = client1.upload(byteutils.toHex(data)).get
let id = client1.requestStorage(
cid,
duration=100.u256,
reward=2.u256,
proofProbability=3.u256,
expiry=30,
collateral=200.u256,
nodes=3,
tolerance=1).get
# test "node retrieves purchase status":
# # get one contiguous chunk
# let rng = rng.Rng.instance()
# let chunker = RandomChunker.new(rng, size = DefaultBlockSize * 2, chunkSize = DefaultBlockSize * 2)
# let data = await chunker.getBytes()
# let cid = client1.upload(byteutils.toHex(data)).get
# let id = client1.requestStorage(
# cid,
# duration=100.u256,
# reward=2.u256,
# proofProbability=3.u256,
# expiry=30,
# collateral=200.u256,
# nodes=3,
# tolerance=1).get

let request = client1.getPurchase(id).get.request.get
check request.ask.duration == 100.u256
check request.ask.reward == 2.u256
check request.ask.proofProbability == 3.u256
check request.expiry == 30
check request.ask.collateral == 200.u256
check request.ask.slots == 3'u64
check request.ask.maxSlotLoss == 1'u64
# let request = client1.getPurchase(id).get.request.get
# check request.ask.duration == 100.u256
# check request.ask.reward == 2.u256
# check request.ask.proofProbability == 3.u256
# check request.expiry == 30
# check request.ask.collateral == 200.u256
# check request.ask.slots == 3'u64
# check request.ask.maxSlotLoss == 1'u64

# TODO: We currently do not support encoding single chunks
# test "node retrieves purchase status with 1 chunk":
Expand Down Expand Up @@ -78,14 +78,14 @@ twonodessuite "Purchasing", debug1 = false, debug2 = false:
check request.ask.slots == 3'u64
check request.ask.maxSlotLoss == 1'u64

test "node requires expiry and its value to be in future":
let data = await RandomChunker.example(blocks=2)
let cid = client1.upload(data).get
# test "node requires expiry and its value to be in future":
# let data = await RandomChunker.example(blocks=2)
# let cid = client1.upload(data).get

let responseMissing = client1.requestStorageRaw(cid, duration=1.u256, reward=2.u256, proofProbability=3.u256, collateral=200.u256)
check responseMissing.status == "400 Bad Request"
check responseMissing.body == "Expiry required"
# let responseMissing = client1.requestStorageRaw(cid, duration=1.u256, reward=2.u256, proofProbability=3.u256, collateral=200.u256)
# check responseMissing.status == "400 Bad Request"
# check responseMissing.body == "Expiry required"

let responseBefore = client1.requestStorageRaw(cid, duration=10.u256, reward=2.u256, proofProbability=3.u256, collateral=200.u256, expiry=10)
check responseBefore.status == "400 Bad Request"
check "Expiry needs value bigger then zero and smaller then the request's duration" in responseBefore.body
# let responseBefore = client1.requestStorageRaw(cid, duration=10.u256, reward=2.u256, proofProbability=3.u256, collateral=200.u256, expiry=10)
# check responseBefore.status == "400 Bad Request"
# check "Expiry needs value bigger then zero and smaller then the request's duration" in responseBefore.body
78 changes: 39 additions & 39 deletions tests/integration/testsales.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,45 @@ proc findItem[T](items: seq[T], item: T): ?!T =

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
twonodessuite "Sales", debug1 = true, 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
Expand Down
14 changes: 7 additions & 7 deletions tests/testIntegration.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ./integration/testcli
import ./integration/testrestapi
import ./integration/testupdownload
# import ./integration/testcli
# import ./integration/testrestapi
# import ./integration/testupdownload
import ./integration/testsales
import ./integration/testpurchasing
import ./integration/testblockexpiration
import ./integration/testmarketplace
import ./integration/testproofs
import ./integration/testecbug
# import ./integration/testblockexpiration
# import ./integration/testmarketplace
# import ./integration/testproofs
# import ./integration/testecbug

{.warning[UnusedImport]:off.}

0 comments on commit bf5404b

Please sign in to comment.