import std/options import std/importutils import pkg/chronos import pkg/ethers/erc20 import codex/contracts import ../ethertest import ./examples import ./time import ./deployment import ./helpers/mockprovider privateAccess(OnChainMarket) # enable access to private fields # to see supportive information in the test output # use `-d:"chronicles_enabled_topics:testMarket:DEBUG` option # when compiling the test file logScope: topics = "testMarket" ethersuite "On-Chain Market": let proof = Groth16Proof.example var market: OnChainMarket var marketplace: Marketplace var token: Erc20Token var request: StorageRequest var slotIndex: UInt256 var periodicity: Periodicity var host: Signer var otherHost: Signer var hostRewardRecipient: Address proc expectedPayout(r: StorageRequest, startTimestamp: UInt256, endTimestamp: UInt256): UInt256 = return (endTimestamp - startTimestamp) * r.ask.reward proc switchAccount(account: Signer) = marketplace = marketplace.connect(account) token = token.connect(account) market = OnChainMarket.new(marketplace, market.rewardRecipient) setup: let address = Marketplace.address(dummyVerifier = true) marketplace = Marketplace.new(address, ethProvider.getSigner()) let config = await marketplace.configuration() hostRewardRecipient = accounts[2] market = OnChainMarket.new(marketplace) let tokenAddress = await marketplace.token() token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) periodicity = Periodicity(seconds: config.proofs.period) request = StorageRequest.example request.client = accounts[0] host = ethProvider.getSigner(accounts[1]) otherHost = ethProvider.getSigner(accounts[3]) 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 mineNBlocks(provider: JsonRpcProvider, n: int) {.async.} = for _ in 0.. 291 # 1728436104 => 291 # 1728436105 => 292 # 1728436106 => 292 # 1728436110 => 292 proc generateExpectations( blocks: seq[(UInt256, UInt256)]): seq[Expectations] = var expectations: seq[Expectations] = @[] for i in 0..