feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
import pkg/chronos
|
2022-09-20 06:51:03 +00:00
|
|
|
import pkg/ethers/testing
|
2023-04-14 09:04:17 +00:00
|
|
|
import pkg/ethers/erc20
|
2022-05-19 19:56:03 +00:00
|
|
|
import codex/contracts
|
2022-05-11 12:17:07 +00:00
|
|
|
import ../ethertest
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
import ./examples
|
2022-03-17 13:15:04 +00:00
|
|
|
import ./time
|
2023-05-03 07:24:25 +00:00
|
|
|
import ./deployment
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2023-01-19 05:58:04 +00:00
|
|
|
ethersuite "Marketplace contracts":
|
2024-02-07 06:50:35 +00:00
|
|
|
let proof = Groth16Proof.example
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
|
|
|
var client, host: Signer
|
2024-09-17 04:18:15 +00:00
|
|
|
var rewardRecipient, collateralRecipient: Address
|
2023-01-19 05:58:04 +00:00
|
|
|
var marketplace: Marketplace
|
2023-04-14 09:04:17 +00:00
|
|
|
var token: Erc20Token
|
2022-03-17 13:15:04 +00:00
|
|
|
var periodicity: Periodicity
|
|
|
|
var request: StorageRequest
|
2022-08-17 02:29:44 +00:00
|
|
|
var slotId: SlotId
|
2024-10-10 11:53:33 +00:00
|
|
|
var filledAt: UInt256
|
|
|
|
|
|
|
|
proc expectedPayout(endTimestamp: UInt256): UInt256 =
|
|
|
|
return (endTimestamp - filledAt) * request.ask.reward
|
2022-03-17 13:15:04 +00:00
|
|
|
|
|
|
|
proc switchAccount(account: Signer) =
|
2023-01-19 05:58:04 +00:00
|
|
|
marketplace = marketplace.connect(account)
|
2022-03-17 13:15:04 +00:00
|
|
|
token = token.connect(account)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
|
|
|
setup:
|
2023-12-18 09:34:04 +00:00
|
|
|
client = ethProvider.getSigner(accounts[0])
|
|
|
|
host = ethProvider.getSigner(accounts[1])
|
2024-09-17 04:18:15 +00:00
|
|
|
rewardRecipient = accounts[2]
|
|
|
|
collateralRecipient = accounts[3]
|
2022-03-17 13:15:04 +00:00
|
|
|
|
2024-02-07 06:50:35 +00:00
|
|
|
let address = Marketplace.address(dummyVerifier = true)
|
|
|
|
marketplace = Marketplace.new(address, ethProvider.getSigner())
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2023-04-14 09:04:17 +00:00
|
|
|
let tokenAddress = await marketplace.token()
|
2023-12-18 09:34:04 +00:00
|
|
|
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2024-10-30 10:40:17 +00:00
|
|
|
let config = await marketplace.configuration()
|
[marketplace] Load sales state from chain (#306)
* [marketplace] get active slots from chain
# Conflicts:
# codex/contracts/market.nim
* [marketplace] make on chain event callbacks async
# Conflicts:
# tests/codex/helpers/mockmarket.nim
* [marketplace] make availability optional for node restart
# Conflicts:
# tests/codex/testsales.nim
* [marketplace] add async state machine
Allows for `enterAsync` to be cancelled.
* [marketplace] move sale process to async state machine
* [marketplace] sales state machine tests
* bump dagger-contracts
* [marketplace] fix ci issue with chronicles output
* PR comments
- add slotIndex to `SalesAgent` constructor
- remove `SalesAgent.init`
- rename `SalesAgent.init` to `start` and `SalesAgent.deinit` to `stop`.
- rename `SalesAgent. populateRequest` to `SalesAgent.retreiveRequest`.
- move availability removal to the downloading state. once availability is persisted to disk, it should survive node restarts.
-
* [marketplace] handle slot filled by other host
Handle the case when in the downloading, proving, or filling states, that another host fills the slot.
* [marketplace] use requestId for mySlots
* [marketplace] infer slot index from slotid
prevents reassigning a random slot index when restoring state from chain
* [marketplace] update to work with latest contracts
* [marketplace] clean up
* [marketplace] align with contract changes
- getState / state > requestState
- getSlot > getRequestFromSlotId
- support MarketplaceConfig
- support slotState, remove unneeded Slot type
- collateral > config.collateral.initialAmount
- remove proofPeriod contract call
- Revert reason “Slot empty” > “Slot is free”
- getProofEnd > read SlotState
Tests for changes
* [marketplace] add missing file
* [marketplace] bump codex-contracts-eth
* [config] remove unused imports
* [sales] cleanup
* [sales] fix: do not crash when fetching state fails
* [sales] make slotIndex non-optional
* Rebase and update NBS commit
Rebase on top of main and update NBS commit to the CI fix.
* [marketplace] use async subscription event handlers
* [marketplace] support slotIndex no longer optional
Previously, SalesAgent.slotIndex had been moved to not optional. However, there were still many places where optionality was assumed. This commit removes those assumuptions.
* [marketplace] sales state machine: use slotState
Use `slotState` instead of `requestState` for sales state machine.
* [marketplace] clean up
* [statemachine] adds a statemachine for async workflows
Allows events to be scheduled synchronously.
See https://github.com/status-im/nim-codex/pull/344
Co-Authored-By: Ben Bierens <thatbenbierens@gmail.com>
Co-Authored-By: Eric Mastro <eric.mastro@gmail.com>
* [market] make market callbacks synchronous
* [statemachine] export Event
* [statemachine] ensure that no errors are raised
* [statemachine] add machine parameter to run method
* [statemachine] initialize queue on start
* [statemachine] check futures before cancelling them
* [sales] use new async state machine
- states use new run() method and event mechanism
- StartState starts subscriptions and loads request
* [statemachine] fix unsusbscribe before subscribe
* [sales] replace old state transition tests
* [sales] separate state machine from sales data
* [sales] remove reference from SalesData to Sales
* [sales] separate sales context from sales
* [sales] move decoupled types into their own modules
* [sales] move retrieveRequest to SalesData
* [sales] move subscription logic into SalesAgent
* [sales] unsubscribe when finished or errored
* [build] revert back to released version of nim-ethers
* [sales] remove SaleStart state
* [sales] add missing base method
* [sales] move asyncSpawn helper to utils
* [sales] fix imports
* [sales] remove unused variables
* [sales statemachine] add async state machine error handling (#349)
* [statemachine] add error handling to asyncstatemachine
- add error handling to catch errors during state.run
- Sales: add ErrorState to identify which state to transition to during an error. This had to be added to SalesAgent constructor due to circular dependency issues, otherwise it would have been added directly to SalesAgent.
- Sales: when an error during run is encountered, the SaleErrorState is constructed with the error, and by default (base impl) will return the error state, so the machine can transition to it. This can be overridden by individual states if needed.
* [sales] rename onSaleFailed to onSaleErrored
Because there is already a state named SaleFailed which is meant to react to an onchain RequestFailed event and also because this callback is called from SaleErrored, renaming to onSaleErrored prevents ambiguity and confusion as to what has happened at the callback callsite.
* [statemachine] forward error to state directly
without going through a machine method first
* [statemachine] remove unnecessary error handling
AsyncQueueFullError is already handled in schedule()
* [statemachine] test that cancellation ignores onError
* [sales] simplify error handling in states
Rely on the state machine error handling instead
of catching errors in the state run method
---------
Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
* [statemachine] prevent memory leaks
prevent memory leaks and nil access defects by:
- allowing multiple subscribe/unsubscribes of salesagent
- disallowing individual salesagent subscription calls to be made externally (requires the .subscribed check)
- allowing mutiple start/stops of asyncstatemachine
- disregard asyncstatemachine schedules if machine not yet started
* [salesagent] add salesagent-specific tests
1. test multiple subscribe/unsubscribes
2. test scheduling machine without being started
3. test subscriptions are working correctly with external events
4. test errors can be overridden at the state level for ErrorHandlingStates.
---------
Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
Co-authored-by: Mark Spanbroek <mark@spanbroek.net>
Co-authored-by: Ben Bierens <thatbenbierens@gmail.com>
2023-03-08 13:34:26 +00:00
|
|
|
periodicity = Periodicity(seconds: config.proofs.period)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-03-17 13:15:04 +00:00
|
|
|
request = StorageRequest.example
|
|
|
|
request.client = await client.getAddress()
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-03-17 13:15:04 +00:00
|
|
|
switchAccount(client)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await token.approve(marketplace.address, request.price).confirm(1)
|
|
|
|
discard await marketplace.requestStorage(request).confirm(1)
|
2022-03-17 13:15:04 +00:00
|
|
|
switchAccount(host)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await token.approve(marketplace.address, request.ask.collateral).confirm(1)
|
|
|
|
discard await marketplace.reserveSlot(request.id, 0.u256).confirm(1)
|
2024-10-10 11:53:33 +00:00
|
|
|
filledAt = await ethProvider.currentTime()
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1)
|
2022-08-17 02:29:44 +00:00
|
|
|
slotId = request.slotId(0.u256)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-08-17 02:29:44 +00:00
|
|
|
proc waitUntilProofRequired(slotId: SlotId) {.async.} =
|
2023-12-18 09:34:04 +00:00
|
|
|
let currentPeriod = periodicity.periodOf(await ethProvider.currentTime())
|
|
|
|
await ethProvider.advanceTimeTo(periodicity.periodEnd(currentPeriod))
|
2022-03-17 13:15:04 +00:00
|
|
|
while not (
|
2023-01-19 05:58:04 +00:00
|
|
|
(await marketplace.isProofRequired(slotId)) and
|
|
|
|
(await marketplace.getPointer(slotId)) < 250
|
2022-03-17 13:15:04 +00:00
|
|
|
):
|
2023-12-18 09:34:04 +00:00
|
|
|
await ethProvider.advanceTime(periodicity.seconds)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-11-08 07:10:17 +00:00
|
|
|
proc startContract() {.async.} =
|
|
|
|
for slotIndex in 1..<request.ask.slots:
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await token.approve(marketplace.address, request.ask.collateral).confirm(1)
|
|
|
|
discard await marketplace.reserveSlot(request.id, slotIndex.u256).confirm(1)
|
|
|
|
discard await marketplace.fillSlot(request.id, slotIndex.u256, proof).confirm(1)
|
2022-11-08 07:10:17 +00:00
|
|
|
|
2023-01-19 05:58:04 +00:00
|
|
|
test "accept marketplace proofs":
|
2022-03-17 13:15:04 +00:00
|
|
|
switchAccount(host)
|
2022-08-17 02:29:44 +00:00
|
|
|
await waitUntilProofRequired(slotId)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await marketplace.submitProof(slotId, proof).confirm(1)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-03-17 13:15:04 +00:00
|
|
|
test "can mark missing proofs":
|
|
|
|
switchAccount(host)
|
2022-08-17 02:29:44 +00:00
|
|
|
await waitUntilProofRequired(slotId)
|
2023-12-18 09:34:04 +00:00
|
|
|
let missingPeriod = periodicity.periodOf(await ethProvider.currentTime())
|
2023-11-09 05:35:55 +00:00
|
|
|
let endOfPeriod = periodicity.periodEnd(missingPeriod)
|
2023-12-18 09:34:04 +00:00
|
|
|
await ethProvider.advanceTimeTo(endOfPeriod + 1)
|
2022-03-17 13:15:04 +00:00
|
|
|
switchAccount(client)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await marketplace.markProofAsMissing(slotId, missingPeriod).confirm(1)
|
feat: integrate dagger contracts
Integrate dagger contracts from `nim-dagger-contracts` repo.
Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`.
Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`.
We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this?
Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
2022-01-25 00:22:58 +00:00
|
|
|
|
2022-11-08 07:10:17 +00:00
|
|
|
test "can be paid out at the end":
|
2022-03-17 13:15:04 +00:00
|
|
|
switchAccount(host)
|
2023-01-19 05:58:04 +00:00
|
|
|
let address = await host.getAddress()
|
2022-11-08 07:10:17 +00:00
|
|
|
await startContract()
|
2023-01-19 05:58:04 +00:00
|
|
|
let requestEnd = await marketplace.requestEnd(request.id)
|
2023-12-18 09:34:04 +00:00
|
|
|
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
|
2023-01-19 05:58:04 +00:00
|
|
|
let startBalance = await token.balanceOf(address)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await marketplace.freeSlot(slotId).confirm(1)
|
2023-01-19 05:58:04 +00:00
|
|
|
let endBalance = await token.balanceOf(address)
|
2024-10-10 11:53:33 +00:00
|
|
|
check endBalance == (startBalance + expectedPayout(requestEnd.u256) + request.ask.collateral)
|
2022-08-17 04:02:53 +00:00
|
|
|
|
2024-09-17 04:18:15 +00:00
|
|
|
test "can be paid out at the end, specifying reward and collateral recipient":
|
|
|
|
switchAccount(host)
|
|
|
|
let hostAddress = await host.getAddress()
|
|
|
|
await startContract()
|
|
|
|
let requestEnd = await marketplace.requestEnd(request.id)
|
|
|
|
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
|
|
|
|
let startBalanceHost = await token.balanceOf(hostAddress)
|
|
|
|
let startBalanceReward = await token.balanceOf(rewardRecipient)
|
|
|
|
let startBalanceCollateral = await token.balanceOf(collateralRecipient)
|
2024-11-12 07:52:36 +00:00
|
|
|
discard await marketplace.freeSlot(slotId, rewardRecipient, collateralRecipient).confirm(1)
|
2024-09-17 04:18:15 +00:00
|
|
|
let endBalanceHost = await token.balanceOf(hostAddress)
|
|
|
|
let endBalanceReward = await token.balanceOf(rewardRecipient)
|
|
|
|
let endBalanceCollateral = await token.balanceOf(collateralRecipient)
|
|
|
|
|
|
|
|
check endBalanceHost == startBalanceHost
|
2024-10-10 11:53:33 +00:00
|
|
|
check endBalanceReward == (startBalanceReward + expectedPayout(requestEnd.u256))
|
2024-09-17 04:18:15 +00:00
|
|
|
check endBalanceCollateral == (startBalanceCollateral + request.ask.collateral)
|
|
|
|
|
2022-08-17 04:02:53 +00:00
|
|
|
test "cannot mark proofs missing for cancelled request":
|
2024-05-06 15:35:46 +00:00
|
|
|
let expiry = await marketplace.requestExpiry(request.id)
|
|
|
|
await ethProvider.advanceTimeTo((expiry + 1).u256)
|
2022-08-17 04:02:53 +00:00
|
|
|
switchAccount(client)
|
2023-12-18 09:34:04 +00:00
|
|
|
let missingPeriod = periodicity.periodOf(await ethProvider.currentTime())
|
|
|
|
await ethProvider.advanceTime(periodicity.seconds)
|
2023-01-19 05:58:04 +00:00
|
|
|
check await marketplace
|
2022-09-21 02:50:11 +00:00
|
|
|
.markProofAsMissing(slotId, missingPeriod)
|
2024-11-12 07:52:36 +00:00
|
|
|
.confirm(1)
|
2022-09-21 02:50:11 +00:00
|
|
|
.reverts("Slot not accepting proofs")
|