[storage] add getRequest() and getOffer()

This commit is contained in:
Mark Spanbroek 2022-04-06 14:52:02 +02:00 committed by markspanbroek
parent 169a446769
commit b145e66a68
2 changed files with 25 additions and 0 deletions

View File

@ -29,6 +29,14 @@ contract Storage is Collateral, Marketplace, Proofs {
slashPercentage = _slashPercentage; slashPercentage = _slashPercentage;
} }
function getRequest(bytes32 id) public view returns (Request memory) {
return _request(id);
}
function getOffer(bytes32 id) public view returns (Offer memory) {
return _offer(id);
}
function startContract(bytes32 id) public { function startContract(bytes32 id) public {
Offer storage offer = _offer(id); Offer storage offer = _offer(id);
require(msg.sender == offer.host, "Only host can call this function"); require(msg.sender == offer.host, "Only host can call this function");

View File

@ -51,6 +51,23 @@ describe("Storage", function () {
id = offerId(offer) id = offerId(offer)
}) })
it("can retrieve storage requests", async function () {
const id = requestId(request)
const retrieved = await storage.getRequest(id)
expect(retrieved.client).to.equal(request.client)
expect(retrieved.expiry).to.equal(request.expiry)
expect(retrieved.nonce).to.equal(request.nonce)
})
it("can retrieve storage offers", async function () {
const id = offerId(offer)
const retrieved = await storage.getOffer(id)
expect(retrieved.requestId).to.equal(offer.requestId)
expect(retrieved.host).to.equal(offer.host)
expect(retrieved.price).to.equal(offer.price)
expect(retrieved.expiry).to.equal(offer.expiry)
})
describe("starting the contract", function () { describe("starting the contract", function () {
it("starts requiring storage proofs", async function () { it("starts requiring storage proofs", async function () {
switchAccount(host) switchAccount(host)