Add getHost() to retrieve host that fulfills request

This commit is contained in:
Mark Spanbroek 2022-07-04 11:16:55 +02:00 committed by markspanbroek
parent 1227ce8658
commit 97ef1bcd9f
2 changed files with 11 additions and 0 deletions

View File

@ -38,6 +38,10 @@ contract Storage is Collateral, Marketplace {
return _request(id);
}
function getHost(bytes32 id) public view returns (address) {
return _host(id);
}
function finishContract(bytes32 id) public {
require(_host(id) != address(0), "Contract not started");
require(!contractFinished[id], "Contract already finished");

View File

@ -1,6 +1,7 @@
const { expect } = require("chai")
const { ethers, deployments } = require("hardhat")
const { hexlify, randomBytes } = ethers.utils
const { AddressZero } = ethers.constants
const { exampleRequest } = require("./examples")
const { advanceTime, advanceTimeTo, currentTime } = require("./evm")
const { requestId } = require("./ids")
@ -55,6 +56,12 @@ describe("Storage", function () {
expect(retrieved.nonce).to.equal(request.nonce)
})
it("can retrieve host that fulfilled request", async function () {
expect(await storage.getHost(requestId(request))).to.equal(AddressZero)
await storage.fulfillRequest(requestId(request), proof)
expect(await storage.getHost(requestId(request))).to.equal(host.address)
})
describe("finishing the contract", function () {
async function waitUntilEnd() {
const end = (await storage.proofEnd(id)).toNumber()