diff --git a/tests/contracts/testClock.nim b/tests/contracts/testClock.nim index fafb6092..32c02e7b 100644 --- a/tests/contracts/testClock.nim +++ b/tests/contracts/testClock.nim @@ -8,21 +8,21 @@ ethersuite "On-Chain Clock": var clock: OnChainClock setup: - clock = OnChainClock.new(provider) + clock = OnChainClock.new(ethProvider) await clock.start() teardown: await clock.stop() test "returns the current time of the EVM": - let latestBlock = (!await provider.getBlock(BlockTag.latest)) + let latestBlock = (!await ethProvider.getBlock(BlockTag.latest)) let timestamp = latestBlock.timestamp.truncate(int64) check clock.now() == timestamp test "updates time with timestamp of new blocks": let future = (getTime() + 42.years).toUnix - discard await provider.send("evm_setNextBlockTimestamp", @[%future]) - discard await provider.send("evm_mine") + discard await ethProvider.send("evm_setNextBlockTimestamp", @[%future]) + discard await ethProvider.send("evm_mine") check clock.now() == future test "updates time using wall-clock in-between blocks": @@ -33,8 +33,8 @@ ethersuite "On-Chain Clock": test "can wait until a certain time is reached by the chain": let future = clock.now() + 42 # seconds let waiting = clock.waitUntil(future) - discard await provider.send("evm_setNextBlockTimestamp", @[%future]) - discard await provider.send("evm_mine") + discard await ethProvider.send("evm_setNextBlockTimestamp", @[%future]) + discard await ethProvider.send("evm_mine") check await waiting.withTimeout(chronos.milliseconds(100)) test "can wait until a certain time is reached by the wall-clock": @@ -44,7 +44,7 @@ ethersuite "On-Chain Clock": test "raises when not started": expect AssertionDefect: - discard OnChainClock.new(provider).now() + discard OnChainClock.new(ethProvider).now() test "raises when stopped": await clock.stop() diff --git a/tests/contracts/testContracts.nim b/tests/contracts/testContracts.nim index 176e5d25..22aaeba0 100644 --- a/tests/contracts/testContracts.nim +++ b/tests/contracts/testContracts.nim @@ -23,13 +23,13 @@ ethersuite "Marketplace contracts": token = token.connect(account) setup: - client = provider.getSigner(accounts[0]) - host = provider.getSigner(accounts[1]) + client = ethProvider.getSigner(accounts[0]) + host = ethProvider.getSigner(accounts[1]) - marketplace = Marketplace.new(Marketplace.address, provider.getSigner()) + marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner()) let tokenAddress = await marketplace.token() - token = Erc20Token.new(tokenAddress, provider.getSigner()) + token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) let config = await marketplace.config() periodicity = Periodicity(seconds: config.proofs.period) @@ -46,13 +46,13 @@ ethersuite "Marketplace contracts": slotId = request.slotId(0.u256) proc waitUntilProofRequired(slotId: SlotId) {.async.} = - let currentPeriod = periodicity.periodOf(await provider.currentTime()) - await provider.advanceTimeTo(periodicity.periodEnd(currentPeriod)) + 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 provider.advanceTime(periodicity.seconds) + await ethProvider.advanceTime(periodicity.seconds) proc startContract() {.async.} = for slotIndex in 1.. LogLevel.TRACE or enabledLogLevel == LogLevel.NONE): echo "" @@ -116,12 +116,12 @@ template multinodesuite*(name: string, "--bootstrap-node=" & bootstrap, "--persistence", "--simulate-proof-failures=" & $failEveryNProofs], - debugNodes.provider) + debugNodes.ethProvider) let restClient = newCodexClient(index) running.add RunningNode.new(Role.Provider, node, restClient, datadir, account) - if debugNodes.provider: - debug "started new provider node and codex client", + if debugNodes.ethProvider: + debug "started new ethProvider node and codex client", restApiPort = 8080 + index, discPort = 8090 + index, account proc startValidatorNode() = diff --git a/tests/integration/testIntegration.nim b/tests/integration/testIntegration.nim index 999182e0..5218c673 100644 --- a/tests/integration/testIntegration.nim +++ b/tests/integration/testIntegration.nim @@ -28,10 +28,10 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: return purchase.state == state setup: - # Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not + # Our Hardhat configuration does use automine, which means that time tracked by `ethProvider.currentTime()` is not # advanced until blocks are mined and that happens only when transaction is submitted. - # As we use in tests provider.currentTime() which uses block timestamp this can lead to synchronization issues. - await provider.advanceTime(1.u256) + # As we use in tests ethProvider.currentTime() which uses block timestamp this can lead to synchronization issues. + await ethProvider.advanceTime(1.u256) test "nodes can print their peer information": check client1.info() != client2.info() @@ -111,7 +111,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: check availability in client1.getAvailabilities().get test "node handles storage request": - let expiry = (await provider.currentTime()) + 10 + let expiry = (await ethProvider.currentTime()) + 10 let cid = client1.upload("some file contents").get let id1 = client1.requestStorage(cid, duration=100.u256, reward=2.u256, proofProbability=3.u256, expiry=expiry, collateral=200.u256).get let id2 = client1.requestStorage(cid, duration=400.u256, reward=5.u256, proofProbability=6.u256, expiry=expiry, collateral=201.u256).get @@ -123,7 +123,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: 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 expiry = (await provider.currentTime()) + 30 + let expiry = (await ethProvider.currentTime()) + 30 let id = client1.requestStorage( cid, duration=100.u256, @@ -145,7 +145,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: # TODO: We currently do not support encoding single chunks # test "node retrieves purchase status with 1 chunk": - # let expiry = (await provider.currentTime()) + 30 + # let expiry = (await ethProvider.currentTime()) + 30 # let cid = client1.upload("some file contents").get # let id = client1.requestStorage(cid, duration=1.u256, reward=2.u256, proofProbability=3.u256, expiry=expiry, collateral=200.u256, nodes=2, tolerance=1).get # let request = client1.getPurchase(id).get.request.get @@ -158,7 +158,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: # check request.ask.maxSlotLoss == 1'u64 test "node remembers purchase status after restart": - let expiry = (await provider.currentTime()) + 30 + let expiry = (await ethProvider.currentTime()) + 30 let cid = client1.upload("some file contents").get let id = client1.requestStorage(cid, duration=100.u256, @@ -188,7 +188,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: discard client2.postAvailability(size=size, duration=200.u256, minPrice=300.u256, maxCollateral=300.u256) # client 1 requests storage - let expiry = (await provider.currentTime()) + 30 + let expiry = (await ethProvider.currentTime()) + 30 let cid = client1.upload("some file contents").get let id = client1.requestStorage(cid, duration=100.u256, reward=400.u256, proofProbability=3.u256, expiry=expiry, collateral=200.u256).get @@ -201,9 +201,9 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: check newSize > 0 and newSize < size test "node slots gets paid out": - let marketplace = Marketplace.new(Marketplace.address, provider.getSigner()) + let marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner()) let tokenAddress = await marketplace.token() - let token = Erc20Token.new(tokenAddress, provider.getSigner()) + let token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) let reward = 400.u256 let duration = 100.u256 @@ -212,7 +212,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: discard client2.postAvailability(size=0xFFFFF.u256, duration=200.u256, minPrice=300.u256, maxCollateral=300.u256).get # client 1 requests storage - let expiry = (await provider.currentTime()) + 30 + let expiry = (await ethProvider.currentTime()) + 30 let cid = client1.upload("some file contents").get let id = client1.requestStorage(cid, duration=duration, reward=reward, proofProbability=3.u256, expiry=expiry, collateral=200.u256).get @@ -223,12 +223,12 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: # Proving mechanism uses blockchain clock to do proving/collect/cleanup round # hence we must use `advanceTime` over `sleepAsync` as Hardhat does mine new blocks # only with new transaction - await provider.advanceTime(duration) + await ethProvider.advanceTime(duration) check eventually (await token.balanceOf(account2)) - startBalance == duration*reward test "node requires expiry and its value to be in future": - let currentTime = await provider.currentTime() + let currentTime = await ethProvider.currentTime() let cid = client1.upload("some file contents").get let responseMissing = client1.requestStorageRaw(cid, duration=1.u256, reward=2.u256, proofProbability=3.u256, collateral=200.u256) @@ -244,9 +244,9 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: check responseBefore.body == "Expiry has to be before the request's end (now + duration)" test "expired request partially pays out for stored time": - let marketplace = Marketplace.new(Marketplace.address, provider.getSigner()) + let marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner()) let tokenAddress = await marketplace.token() - let token = Erc20Token.new(tokenAddress, provider.getSigner()) + let token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) let reward = 400.u256 let duration = 100.u256 @@ -256,7 +256,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: # client 1 requests storage but requires two nodes to host the content let startBalanceClient1 = await token.balanceOf(account1) - let expiry = (await provider.currentTime()) + 10 + let expiry = (await ethProvider.currentTime()) + 10 let cid = client1.upload(exampleString(100000)).get let id = client1.requestStorage(cid, duration=duration, reward=reward, proofProbability=3.u256, expiry=expiry, collateral=200.u256, nodes=2).get @@ -264,7 +264,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false: # Until https://github.com/codex-storage/nim-codex/issues/594 is implemented nothing better then # sleeping some seconds is available. await sleepAsync(2.seconds) - await provider.advanceTimeTo(expiry+1) + await ethProvider.advanceTimeTo(expiry+1) check eventually(client1.purchaseStateIs(id, "cancelled"), 20000) check eventually ((await token.balanceOf(account2)) - startBalanceClient2) > 0 and ((await token.balanceOf(account2)) - startBalanceClient2) < 10*reward diff --git a/tests/integration/testproofs.nim b/tests/integration/testproofs.nim index c5f2ff05..86905f8f 100644 --- a/tests/integration/testproofs.nim +++ b/tests/integration/testproofs.nim @@ -22,13 +22,13 @@ twonodessuite "Proving integration test", debug1=false, debug2=false: client.getPurchase(id).option.?state == some state setup: - marketplace = Marketplace.new(Marketplace.address, provider) + marketplace = Marketplace.new(Marketplace.address, ethProvider) period = (await marketplace.config()).proofs.period.truncate(uint64) - # Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not + # Our Hardhat configuration does use automine, which means that time tracked by `ethProvider.currentTime()` is not # advanced until blocks are mined and that happens only when transaction is submitted. - # As we use in tests provider.currentTime() which uses block timestamp this can lead to synchronization issues. - await provider.advanceTime(1.u256) + # As we use in tests ethProvider.currentTime() which uses block timestamp this can lead to synchronization issues. + await ethProvider.advanceTime(1.u256) proc waitUntilPurchaseIsStarted(proofProbability: uint64 = 3, duration: uint64 = 100 * period, @@ -40,7 +40,7 @@ twonodessuite "Proving integration test", debug1=false, debug2=false: maxCollateral=200.u256 ) let cid = client1.upload("some file contents").get - let expiry = (await provider.currentTime()) + expiry.u256 + let expiry = (await ethProvider.currentTime()) + expiry.u256 let id = client1.requestStorage( cid, expiry=expiry, @@ -53,9 +53,9 @@ twonodessuite "Proving integration test", debug1=false, debug2=false: proc advanceToNextPeriod {.async.} = let periodicity = Periodicity(seconds: period.u256) - let currentPeriod = periodicity.periodOf(await provider.currentTime()) + let currentPeriod = periodicity.periodOf(await ethProvider.currentTime()) let endOfPeriod = periodicity.periodEnd(currentPeriod) - await provider.advanceTimeTo(endOfPeriod + 1) + await ethProvider.advanceTimeTo(endOfPeriod + 1) proc startValidator: NodeProcess = let validator = startNode( @@ -81,7 +81,7 @@ twonodessuite "Proving integration test", debug1=false, debug2=false: proc onProofSubmitted(event: ProofSubmitted) = proofWasSubmitted = true let subscription = await marketplace.subscribe(ProofSubmitted, onProofSubmitted) - await provider.advanceTime(period.u256) + await ethProvider.advanceTime(period.u256) check eventually proofWasSubmitted await subscription.unsubscribe() @@ -110,7 +110,7 @@ twonodessuite "Proving integration test", debug1=false, debug2=false: multinodesuite "Simulate invalid proofs", StartNodes.init(clients=1'u, providers=0'u, validators=1'u), - DebugNodes.init(client=false, provider=false, validator=false): + DebugNodes.init(client=false, ethProvider=false, validator=false): proc purchaseStateIs(client: CodexClient, id: PurchaseId, state: string): bool = client.getPurchase(id).option.?state == some state @@ -120,15 +120,15 @@ multinodesuite "Simulate invalid proofs", var slotId: SlotId setup: - marketplace = Marketplace.new(Marketplace.address, provider) + marketplace = Marketplace.new(Marketplace.address, ethProvider) let config = await marketplace.config() period = config.proofs.period.truncate(uint64) slotId = SlotId(array[32, byte].default) # ensure we aren't reusing from prev test - # Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not + # Our Hardhat configuration does use automine, which means that time tracked by `ethProvider.currentTime()` is not # advanced until blocks are mined and that happens only when transaction is submitted. - # As we use in tests provider.currentTime() which uses block timestamp this can lead to synchronization issues. - await provider.advanceTime(1.u256) + # As we use in tests ethProvider.currentTime() which uses block timestamp this can lead to synchronization issues. + await ethProvider.advanceTime(1.u256) proc periods(p: Ordinal | uint): uint64 = when p is uint: @@ -137,16 +137,16 @@ multinodesuite "Simulate invalid proofs", proc advanceToNextPeriod {.async.} = let periodicity = Periodicity(seconds: period.u256) - let currentPeriod = periodicity.periodOf(await provider.currentTime()) + let currentPeriod = periodicity.periodOf(await ethProvider.currentTime()) let endOfPeriod = periodicity.periodEnd(currentPeriod) - await provider.advanceTimeTo(endOfPeriod + 1) + await ethProvider.advanceTimeTo(endOfPeriod + 1) proc waitUntilPurchaseIsStarted(proofProbability: uint64 = 1, duration: uint64 = 12.periods, expiry: uint64 = 4.periods) {.async.} = if clients().len < 1 or providers().len < 1: - raiseAssert("must start at least one client and one provider") + raiseAssert("must start at least one client and one ethProvider") let client = clients()[0].restClient let storageProvider = providers()[0].restClient @@ -158,7 +158,7 @@ multinodesuite "Simulate invalid proofs", maxCollateral=200.u256 ) let cid = client.upload("some file contents " & $ getTime().toUnix).get - let expiry = (await provider.currentTime()) + expiry.u256 + let expiry = (await ethProvider.currentTime()) + expiry.u256 # avoid timing issues by filling the slot at the start of the next period await advanceToNextPeriod() let id = client.requestStorage(