[contracts] Replace fulfillRequest() by fillSlot()

This commit is contained in:
Mark Spanbroek 2022-07-20 15:30:13 +02:00 committed by markspanbroek
parent 0494b3617b
commit 67e4a28ed0
3 changed files with 16 additions and 9 deletions

View File

@ -119,3 +119,10 @@ func decode*(decoder: var AbiDecoder, T: type StorageRequest): ?!T =
func id*(request: StorageRequest): array[32, byte] =
let encoding = AbiEncoder.encode((request, ))
keccak256.digest(encoding).data
func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] =
let encoding = AbiEncoder.encode((request.id, slot))
keccak256.digest(encoding).data
func price*(request: StorageRequest): UInt256 =
request.ask.slots.u256 * request.ask.duration * request.ask.reward

View File

@ -28,7 +28,8 @@ proc withdraw*(storage: Storage) {.contract.}
proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
proc fulfillRequest*(storage: Storage, id: Id, proof: seq[byte]) {.contract.}
proc fillSlot*(storage: Storage, requestId: Id, slotIndex: UInt256, proof: seq[byte]) {.contract.}
proc payoutSlot*(storage: Storage, requestId: Id, slotIndex: UInt256) {.contract.}
proc getRequest*(storage: Storage, id: Id): StorageRequest {.contract, view.}
proc getHost*(storage: Storage, id: Id): Address {.contract, view.}

View File

@ -1,6 +1,5 @@
import std/json
import pkg/chronos
import pkg/nimcrypto
import codex/contracts
import codex/contracts/testtoken
import codex/storageproofs
@ -31,8 +30,8 @@ ethersuite "Storage contracts":
storage = Storage.new(!deployment.address(Storage), provider.getSigner())
token = TestToken.new(!deployment.address(TestToken), provider.getSigner())
await token.mint(await client.getAddress(), 1000.u256)
await token.mint(await host.getAddress(), 1000.u256)
await token.mint(await client.getAddress(), 1_000_000_000.u256)
await token.mint(await host.getAddress(), 1000_000_000.u256)
collateralAmount = await storage.collateralAmount()
periodicity = Periodicity(seconds: await storage.proofPeriod())
@ -41,13 +40,13 @@ ethersuite "Storage contracts":
request.client = await client.getAddress()
switchAccount(client)
await token.approve(storage.address, request.ask.reward)
await token.approve(storage.address, request.price)
await storage.requestStorage(request)
switchAccount(host)
await token.approve(storage.address, collateralAmount)
await storage.deposit(collateralAmount)
await storage.fulfillRequest(request.id, proof)
id = request.id
await storage.fillSlot(request.id, 0.u256, proof)
id = request.slotId(0.u256)
proc waitUntilProofRequired(id: array[32, byte]) {.async.} =
let currentPeriod = periodicity.periodOf(await provider.currentTime())
@ -71,7 +70,7 @@ ethersuite "Storage contracts":
switchAccount(client)
await storage.markProofAsMissing(id, missingPeriod)
test "can be finished":
test "can be payed out at the end":
switchAccount(host)
await provider.advanceTimeTo(await storage.proofEnd(id))
await storage.finishContract(id)
await storage.payoutSlot(request.id, 0.u256)