import pkg/chronos import pkg/ethers/testing import pkg/ethers/erc20 import codex/contracts import ../ethertest import ./examples import ./time import ./deployment ethersuite "Marketplace contracts": let proof = Groth16Proof.example var client, host: Signer var rewardRecipient, collateralRecipient: Address var marketplace: Marketplace var token: Erc20Token var periodicity: Periodicity var request: StorageRequest var slotId: SlotId var filledAt: UInt256 proc expectedPayout(endTimestamp: UInt256): UInt256 = return (endTimestamp - filledAt) * request.ask.reward proc switchAccount(account: Signer) = marketplace = marketplace.connect(account) token = token.connect(account) setup: client = ethProvider.getSigner(accounts[0]) host = ethProvider.getSigner(accounts[1]) rewardRecipient = accounts[2] collateralRecipient = accounts[3] let address = Marketplace.address(dummyVerifier = true) marketplace = Marketplace.new(address, ethProvider.getSigner()) let tokenAddress = await marketplace.token() token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) let config = await marketplace.configuration() periodicity = Periodicity(seconds: config.proofs.period) request = StorageRequest.example request.client = await client.getAddress() switchAccount(client) discard await token.approve(marketplace.address, request.price).confirm(1) discard await marketplace.requestStorage(request).confirm(1) switchAccount(host) discard await token.approve(marketplace.address, request.ask.collateral).confirm(1) discard await marketplace.reserveSlot(request.id, 0.u256).confirm(1) let receipt = await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1) filledAt = await ethProvider.blockTime(BlockTag.init(!receipt.blockNumber)) slotId = request.slotId(0.u256) proc waitUntilProofRequired(slotId: SlotId) {.async.} = let currentPeriod = periodicity.periodOf(await ethProvider.currentTime()) await ethProvider.advanceTimeTo(periodicity.periodEnd(currentPeriod)) while not ( (await marketplace.isProofRequired(slotId)) and (await marketplace.getPointer(slotId)) < 250 ): await ethProvider.advanceTime(periodicity.seconds) proc startContract() {.async.} = for slotIndex in 1..