import std/json import pkg/chronos import pkg/ethers/testing import pkg/ethers/erc20 import codex/contracts import ../ethertest import ./examples import ./time ethersuite "Marketplace contracts": let proof = exampleProof() var client, host: Signer var marketplace: Marketplace var token: Erc20Token var periodicity: Periodicity var request: StorageRequest var slotId: SlotId proc switchAccount(account: Signer) = marketplace = marketplace.connect(account) token = token.connect(account) setup: client = provider.getSigner(accounts[0]) host = provider.getSigner(accounts[1]) let deployment = Deployment.init() marketplace = Marketplace.new(!deployment.address(Marketplace), provider.getSigner()) let tokenAddress = await marketplace.token() token = Erc20Token.new(tokenAddress, provider.getSigner()) let config = await marketplace.config() periodicity = Periodicity(seconds: config.proofs.period) request = StorageRequest.example request.client = await client.getAddress() switchAccount(client) await token.approve(marketplace.address, request.price) await marketplace.requestStorage(request) switchAccount(host) await token.approve(marketplace.address, request.ask.collateral) await marketplace.fillSlot(request.id, 0.u256, proof) slotId = request.slotId(0.u256) proc waitUntilProofRequired(slotId: SlotId) {.async.} = let currentPeriod = periodicity.periodOf(await provider.currentTime()) await provider.advanceTimeTo(periodicity.periodEnd(currentPeriod)) while not ( (await marketplace.isProofRequired(slotId)) and (await marketplace.getPointer(slotId)) < 250 ): await provider.advanceTime(periodicity.seconds) proc startContract() {.async.} = for slotIndex in 1..