[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] = func id*(request: StorageRequest): array[32, byte] =
let encoding = AbiEncoder.encode((request, )) let encoding = AbiEncoder.encode((request, ))
keccak256.digest(encoding).data 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 balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.} 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 getRequest*(storage: Storage, id: Id): StorageRequest {.contract, view.}
proc getHost*(storage: Storage, id: Id): Address {.contract, view.} proc getHost*(storage: Storage, id: Id): Address {.contract, view.}

View File

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