[contracts] Update to latest dagger-contracts

This commit is contained in:
Mark Spanbroek 2022-06-13 15:04:12 +02:00 committed by markspanbroek
parent e1998e0b61
commit e352a181e4
3 changed files with 6 additions and 24 deletions

View File

@ -14,12 +14,7 @@ type
StorageRequested* = object of Event StorageRequested* = object of Event
requestId*: Id requestId*: Id
ask*: StorageAsk ask*: StorageAsk
StorageOffered* = object of Event RequestFulfilled* = object of Event
offerId*: Id
offer*: StorageOffer
requestId* {.indexed.}: Id
OfferSelected* = object of Event
offerId*: Id
requestId* {.indexed.}: Id requestId* {.indexed.}: Id
ProofSubmitted* = object of Event ProofSubmitted* = object of Event
id*: Id id*: Id
@ -34,10 +29,8 @@ proc withdraw*(storage: Storage) {.contract.}
proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.} proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.} proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
proc offerStorage*(storage: Storage, offer: StorageOffer) {.contract.} proc fulfillRequest*(storage: Storage, id: Id, proof: seq[byte]) {.contract.}
proc selectOffer*(storage: Storage, id: Id) {.contract.}
proc startContract*(storage: Storage, id: Id) {.contract.}
proc finishContract*(storage: Storage, id: Id) {.contract.} proc finishContract*(storage: Storage, id: Id) {.contract.}
proc proofPeriod*(storage: Storage): UInt256 {.contract, view.} proc proofPeriod*(storage: Storage): UInt256 {.contract, view.}

View File

@ -9,6 +9,7 @@ import ./examples
import ./time import ./time
ethersuite "Storage contracts": ethersuite "Storage contracts":
let proof = seq[byte].example
var client, host: Signer var client, host: Signer
var storage: Storage var storage: Storage
@ -50,10 +51,8 @@ ethersuite "Storage contracts":
switchAccount(host) switchAccount(host)
await token.approve(storage.address, collateralAmount) await token.approve(storage.address, collateralAmount)
await storage.deposit(collateralAmount) await storage.deposit(collateralAmount)
await storage.offerStorage(offer) await storage.fulfillRequest(request.id, proof)
switchAccount(client) id = request.id
await storage.selectOffer(offer.id)
id = offer.id
proc waitUntilProofRequired(id: array[32, byte]) {.async.} = proc waitUntilProofRequired(id: array[32, byte]) {.async.} =
let currentPeriod = periodicity.periodOf(await provider.currentTime()) let currentPeriod = periodicity.periodOf(await provider.currentTime())
@ -64,22 +63,13 @@ ethersuite "Storage contracts":
): ):
await provider.advanceTime(periodicity.seconds) await provider.advanceTime(periodicity.seconds)
test "can be started by the host":
switchAccount(host)
await storage.startContract(id)
let proofEnd = await storage.proofEnd(id)
check proofEnd > 0
test "accept storage proofs": test "accept storage proofs":
let proof = seq[byte].example
switchAccount(host) switchAccount(host)
await storage.startContract(id)
await waitUntilProofRequired(id) await waitUntilProofRequired(id)
await storage.submitProof(id, proof) await storage.submitProof(id, proof)
test "can mark missing proofs": test "can mark missing proofs":
switchAccount(host) switchAccount(host)
await storage.startContract(id)
await waitUntilProofRequired(id) await waitUntilProofRequired(id)
let missingPeriod = periodicity.periodOf(await provider.currentTime()) let missingPeriod = periodicity.periodOf(await provider.currentTime())
await provider.advanceTime(periodicity.seconds) await provider.advanceTime(periodicity.seconds)
@ -88,6 +78,5 @@ ethersuite "Storage contracts":
test "can be finished": test "can be finished":
switchAccount(host) switchAccount(host)
await storage.startContract(id)
await provider.advanceTimeTo(await storage.proofEnd(id)) await provider.advanceTimeTo(await storage.proofEnd(id))
await storage.finishContract(id) await storage.finishContract(id)

@ -1 +1 @@
Subproject commit 2bf01da728317fd1f3ae8424785f31b53eb4013f Subproject commit 97ef1bcd9f09ac3f267a58e7b7ed5df057b88890