fix: hardhat ignition support

This commit is contained in:
Adam Uhlíř 2025-08-13 16:33:07 +02:00
parent 3ce91a51ab
commit ae13351dfa
No known key found for this signature in database
GPG Key ID: 1D17A9E81F76155B

View File

@ -1,4 +1,4 @@
const { ethers } = require("hardhat") const { ethers, ignition } = require("hardhat")
const { const {
exampleRequest, exampleRequest,
exampleProof, exampleProof,
@ -18,6 +18,7 @@ const { expect } = require("chai")
const { patchOverloads } = require("./marketplace") const { patchOverloads } = require("./marketplace")
const { periodic } = require("./time") const { periodic } = require("./time")
const { RequestState } = require("./requests") const { RequestState } = require("./requests")
const MarketplaceModule = require("../ignition/modules/marketplace")
// Ensures that the actual gas costs can never deviate from the gas estimate by // Ensures that the actual gas costs can never deviate from the gas estimate by
// more than a certain percentage. // more than a certain percentage.
@ -29,33 +30,10 @@ describe("Marketplace gas estimates", function () {
let token let token
let signer let signer
async function setupToken() {
const Token = await ethers.getContractFactory("TestToken")
const token = await Token.deploy()
for (let signer of await ethers.getSigners()) {
await token.mint(signer.address, 1_000_000_000_000_000)
}
return token
}
async function setupMarketplace() {
const Marketplace = await ethers.getContractFactory("Marketplace")
const Verifier = await ethers.getContractFactory("TestVerifier")
const verifier = await Verifier.deploy()
await ensureMinimumBlockHeight(256)
const marketplace = await Marketplace.deploy(
exampleConfiguration(),
token.address,
verifier.address
)
patchOverloads(marketplace)
return marketplace
}
async function requestStorage() { async function requestStorage() {
const request = exampleRequest() const request = exampleRequest()
request.client = signer.address request.client = signer.address
await token.approve(marketplace.address, maxPrice(request)) await token.approve(await marketplace.getAddress(), maxPrice(request))
await marketplace.requestStorage(request) await marketplace.requestStorage(request)
return request return request
} }
@ -64,16 +42,38 @@ describe("Marketplace gas estimates", function () {
const id = requestId(request) const id = requestId(request)
for (let i = 0; i < request.ask.slots; i++) { for (let i = 0; i < request.ask.slots; i++) {
await marketplace.reserveSlot(id, i) await marketplace.reserveSlot(id, i)
await token.approve(marketplace.address, collateralPerSlot(request)) await token.approve(
await marketplace.getAddress(),
collateralPerSlot(request),
)
await marketplace.fillSlot(id, i, exampleProof()) await marketplace.fillSlot(id, i, exampleProof())
} }
} }
beforeEach(async function () { beforeEach(async function () {
await snapshot() await snapshot()
await ensureMinimumBlockHeight(256)
signer = (await ethers.getSigners())[0] signer = (await ethers.getSigners())[0]
token = await setupToken()
marketplace = await setupMarketplace() const { testMarketplace, token: _token } = await ignition.deploy(
MarketplaceModule,
{
parameters: {
Marketplace: {
configuration: exampleConfiguration(),
},
},
},
)
marketplace = testMarketplace
patchOverloads(marketplace)
token = _token
for (let account of await ethers.getSigners()) {
await token.mint(account.address, 1_000_000_000_000_000n)
}
}) })
afterEach(async function () { afterEach(async function () {
@ -91,7 +91,7 @@ describe("Marketplace gas estimates", function () {
try { try {
const transaction = await marketplace.reserveSlot(id, i) const transaction = await marketplace.reserveSlot(id, i)
const receipt = await transaction.wait() const receipt = await transaction.wait()
gasUsage.push(receipt.gasUsed.toNumber()) gasUsage.push(Number(receipt.gasUsed))
} catch (exception) { } catch (exception) {
// ignore: reservations can be full // ignore: reservations can be full
} }
@ -110,10 +110,13 @@ describe("Marketplace gas estimates", function () {
const gasUsage = [] const gasUsage = []
for (let i = 0; i < request.ask.slots; i++) { for (let i = 0; i < request.ask.slots; i++) {
await marketplace.reserveSlot(id, i) await marketplace.reserveSlot(id, i)
await token.approve(marketplace.address, collateralPerSlot(request)) await token.approve(
await marketplace.getAddress(),
collateralPerSlot(request),
)
const transaction = await marketplace.fillSlot(id, i, exampleProof()) const transaction = await marketplace.fillSlot(id, i, exampleProof())
const receipt = await transaction.wait() const receipt = await transaction.wait()
gasUsage.push(receipt.gasUsed.toNumber()) gasUsage.push(Number(receipt.gasUsed))
} }
const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0 const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0
expect(deviation).to.be.gt(0) expect(deviation).to.be.gt(0)
@ -131,7 +134,7 @@ describe("Marketplace gas estimates", function () {
const slot = { request: id, index: i } const slot = { request: id, index: i }
const transaction = await marketplace.freeSlot(slotId(slot)) const transaction = await marketplace.freeSlot(slotId(slot))
const receipt = await transaction.wait() const receipt = await transaction.wait()
gasUsage.push(receipt.gasUsed.toNumber()) gasUsage.push(Number(receipt.gasUsed))
} }
const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0 const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0
expect(deviation).to.be.gt(0) expect(deviation).to.be.gt(0)
@ -144,7 +147,7 @@ describe("Marketplace gas estimates", function () {
beforeEach(async function () { beforeEach(async function () {
const configuration = await marketplace.configuration() const configuration = await marketplace.configuration()
period = configuration.proofs.period period = Number(configuration.proofs.period)
;({ periodOf, periodEnd } = periodic(period)) ;({ periodOf, periodEnd } = periodic(period))
}) })
@ -161,10 +164,10 @@ describe("Marketplace gas estimates", function () {
const slot = { request: id, index: i } const slot = { request: id, index: i }
const transaction = await marketplace.markProofAsMissing( const transaction = await marketplace.markProofAsMissing(
slotId(slot), slotId(slot),
missingPeriod missingPeriod,
) )
const receipt = await transaction.wait() const receipt = await transaction.wait()
gasUsage.push(receipt.gasUsed.toNumber()) gasUsage.push(Number(receipt.gasUsed))
} catch (exception) { } catch (exception) {
// ignore: proof might not be missing // ignore: proof might not be missing
} }