From dc68550d2766af857cf7503edcf45c0dc4ff97fa Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 22 Aug 2024 15:20:32 +0200 Subject: [PATCH] Implements test for cirdl --- tests/tools/cirdl/testcirdl.nim | 386 +++----------------------------- 1 file changed, 26 insertions(+), 360 deletions(-) diff --git a/tests/tools/cirdl/testcirdl.nim b/tests/tools/cirdl/testcirdl.nim index 756bdffc..2b478f2e 100644 --- a/tests/tools/cirdl/testcirdl.nim +++ b/tests/tools/cirdl/testcirdl.nim @@ -1,370 +1,36 @@ +import std/os +import std/osproc import std/options import pkg/chronos import codex/contracts -import ../../ethertest +import ../../integration/marketplacesuite + +marketplacesuite "tools/cirdl": + const + cirdl = "tools/cirdl/cirdl" + workdir = "." -ethersuite "tools/cirdl": test "circuit download tool": - echo "Yes" + let + circuitPath = "testcircuitpath" + rpcEndpoint = "ws://localhost:8545" + marketplaceAddress = $marketplace.address -# var market: OnChainMarket -# var marketplace: Marketplace -# var request: StorageRequest -# var slotIndex: UInt256 -# var periodicity: Periodicity + let args = [circuitPath, rpcEndpoint, marketplaceAddress] -# setup: -# let address = Marketplace.address(dummyVerifier = true) -# marketplace = Marketplace.new(address, ethProvider.getSigner()) -# let config = await marketplace.config() + let process = osproc.startProcess( + cirdl, + workdir, + args + ) -# market = OnChainMarket.new(marketplace) -# periodicity = Periodicity(seconds: config.proofs.period) + let returnCode = process.waitForExit() + check returnCode == 0 -# request = StorageRequest.example -# request.client = accounts[0] + check: + fileExists(circuitPath/"proof_main_verification_key.json") + fileExists(circuitPath/"proof_main.r1cs") + fileExists(circuitPath/"proof_main.wasm") + fileExists(circuitPath/"proof_main.zkey") -# slotIndex = (request.ask.slots div 2).u256 - -# proc advanceToNextPeriod() {.async.} = -# let currentPeriod = periodicity.periodOf(await ethProvider.currentTime()) -# await ethProvider.advanceTimeTo(periodicity.periodEnd(currentPeriod) + 1) - -# proc advanceToCancelledRequest(request: StorageRequest) {.async.} = -# let expiry = (await market.requestExpiresAt(request.id)) + 1 -# await ethProvider.advanceTimeTo(expiry.u256) - -# proc waitUntilProofRequired(slotId: SlotId) {.async.} = -# await advanceToNextPeriod() -# while not ( -# (await marketplace.isProofRequired(slotId)) and -# (await marketplace.getPointer(slotId)) < 250 -# ): -# await advanceToNextPeriod() - -# test "fails to instantiate when contract does not have a signer": -# let storageWithoutSigner = marketplace.connect(ethProvider) -# expect AssertionDefect: -# discard OnChainMarket.new(storageWithoutSigner) - -# test "knows signer address": -# check (await market.getSigner()) == (await ethProvider.getSigner().getAddress()) - -# test "can retrieve proof periodicity": -# let periodicity = await market.periodicity() -# let config = await marketplace.config() -# let periodLength = config.proofs.period -# check periodicity.seconds == periodLength - -# test "can retrieve proof timeout": -# let proofTimeout = await market.proofTimeout() -# let config = await marketplace.config() -# check proofTimeout == config.proofs.timeout - -# test "supports marketplace requests": -# await market.requestStorage(request) - -# test "can retrieve previously submitted requests": -# check (await market.getRequest(request.id)) == none StorageRequest -# await market.requestStorage(request) -# let r = await market.getRequest(request.id) -# check (r) == some request - -# test "supports withdrawing of funds": -# await market.requestStorage(request) -# await advanceToCancelledRequest(request) -# await market.withdrawFunds(request.id) - -# test "supports request subscriptions": -# var receivedIds: seq[RequestId] -# var receivedAsks: seq[StorageAsk] -# proc onRequest(id: RequestId, ask: StorageAsk, expiry: UInt256) = -# receivedIds.add(id) -# receivedAsks.add(ask) -# let subscription = await market.subscribeRequests(onRequest) -# await market.requestStorage(request) -# check receivedIds == @[request.id] -# check receivedAsks == @[request.ask] -# await subscription.unsubscribe() - -# test "supports filling of slots": -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) - -# test "can retrieve host that filled slot": -# await market.requestStorage(request) -# check (await market.getHost(request.id, slotIndex)) == none Address -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# check (await market.getHost(request.id, slotIndex)) == some accounts[0] - -# test "supports freeing a slot": -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# await market.freeSlot(slotId(request.id, slotIndex)) -# check (await market.getHost(request.id, slotIndex)) == none Address - -# test "supports checking whether proof is required now": -# check (await market.isProofRequired(slotId(request.id, slotIndex))) == false - -# test "supports checking whether proof is required soon": -# check (await market.willProofBeRequired(slotId(request.id, slotIndex))) == false - -# test "submits proofs": -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# await advanceToNextPeriod() -# await market.submitProof(slotId(request.id, slotIndex), proof) - -# test "marks a proof as missing": -# let slotId = slotId(request, slotIndex) -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# await waitUntilProofRequired(slotId) -# let missingPeriod = periodicity.periodOf(await ethProvider.currentTime()) -# await advanceToNextPeriod() -# await market.markProofAsMissing(slotId, missingPeriod) -# check (await marketplace.missingProofs(slotId)) == 1 - -# test "can check whether a proof can be marked as missing": -# let slotId = slotId(request, slotIndex) -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# await waitUntilProofRequired(slotId) -# let missingPeriod = periodicity.periodOf(await ethProvider.currentTime()) -# await advanceToNextPeriod() -# check (await market.canProofBeMarkedAsMissing(slotId, missingPeriod)) == true - -# test "supports slot filled subscriptions": -# await market.requestStorage(request) -# var receivedIds: seq[RequestId] -# var receivedSlotIndices: seq[UInt256] -# proc onSlotFilled(id: RequestId, slotIndex: UInt256) = -# receivedIds.add(id) -# receivedSlotIndices.add(slotIndex) -# let subscription = await market.subscribeSlotFilled(onSlotFilled) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# check receivedIds == @[request.id] -# check receivedSlotIndices == @[slotIndex] -# await subscription.unsubscribe() - -# test "subscribes only to a certain slot": -# var otherSlot = slotIndex - 1 -# await market.requestStorage(request) -# var receivedSlotIndices: seq[UInt256] -# proc onSlotFilled(requestId: RequestId, slotIndex: UInt256) = -# receivedSlotIndices.add(slotIndex) -# let subscription = await market.subscribeSlotFilled(request.id, slotIndex, onSlotFilled) -# await market.fillSlot(request.id, otherSlot, proof, request.ask.collateral) -# check receivedSlotIndices.len == 0 -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# check receivedSlotIndices == @[slotIndex] -# await subscription.unsubscribe() - -# test "supports slot freed subscriptions": -# await market.requestStorage(request) -# await market.fillSlot(request.id, slotIndex, proof, request.ask.collateral) -# var receivedRequestIds: seq[RequestId] = @[] -# var receivedIdxs: seq[UInt256] = @[] -# proc onSlotFreed(requestId: RequestId, idx: UInt256) = -# receivedRequestIds.add(requestId) -# receivedIdxs.add(idx) -# let subscription = await market.subscribeSlotFreed(onSlotFreed) -# await market.freeSlot(slotId(request.id, slotIndex)) -# check receivedRequestIds == @[request.id] -# check receivedIdxs == @[slotIndex] -# await subscription.unsubscribe() - -# test "support fulfillment subscriptions": -# await market.requestStorage(request) -# var receivedIds: seq[RequestId] -# proc onFulfillment(id: RequestId) = -# receivedIds.add(id) -# let subscription = await market.subscribeFulfillment(request.id, onFulfillment) -# for slotIndex in 0..