Re-arrange marketplace constructor parameters

first configuration, then contracts that we depend on
This commit is contained in:
Mark Spanbroek 2024-01-10 15:12:06 +01:00 committed by markspanbroek
parent 0d9b67bb31
commit db124ddbd9
8 changed files with 60 additions and 22 deletions

View File

@ -3,13 +3,14 @@ pragma solidity ^0.8.0;
import "./TestToken.sol";
import "./Marketplace.sol";
import "./TestVerifier.sol";
contract FuzzMarketplace is Marketplace {
constructor()
Marketplace(
new TestToken(),
MarketplaceConfig(CollateralConfig(10, 5, 3, 10), ProofConfig(10, 5, 64)),
address(0)
new TestToken(),
new TestVerifier()
)
// solhint-disable-next-line no-empty-blocks
{

View File

@ -8,6 +8,7 @@ import "./Configuration.sol";
import "./Requests.sol";
import "./Proofs.sol";
import "./StateRetrieval.sol";
import "./Verifier.sol";
contract Marketplace is Proofs, StateRetrieval {
using EnumerableSet for EnumerableSet.Bytes32Set;
@ -55,10 +56,10 @@ contract Marketplace is Proofs, StateRetrieval {
}
constructor(
IERC20 token_,
MarketplaceConfig memory configuration,
address verifierAddress
) Proofs(configuration.proofs, verifierAddress) {
IERC20 token_,
IVerifier verifier
) Proofs(configuration.proofs, verifier) {
token = token_;
require(

View File

@ -4,19 +4,16 @@ pragma solidity ^0.8.8;
import "./Configuration.sol";
import "./Requests.sol";
import "./Periods.sol";
interface IVerifier {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[3] calldata _pubSignals) external view returns (bool);
}
import "./Verifier.sol";
abstract contract Proofs is Periods {
ProofConfig private _config;
IVerifier private _verifier;
constructor(ProofConfig memory config, address verifierAddress) Periods(config.period) {
constructor(ProofConfig memory config, IVerifier verifier) Periods(config.period) {
require(block.number > 256, "Insufficient block height");
_config = config;
_verifier = IVerifier(verifierAddress);
_verifier = verifier;
}
mapping(SlotId => uint256) private _slotStarts;

View File

@ -6,11 +6,11 @@ import "./Marketplace.sol";
// exposes internal functions of Marketplace for testing
contract TestMarketplace is Marketplace {
constructor(
IERC20 token,
MarketplaceConfig memory config,
address verifierAddress
IERC20 token,
IVerifier verifier
)
Marketplace(token, config, verifierAddress) // solhint-disable-next-line no-empty-blocks
Marketplace(config, token, verifier) // solhint-disable-next-line no-empty-blocks
{}
function forciblyFreeSlot(SlotId slotId) public {

View File

@ -7,8 +7,10 @@ import "./Proofs.sol";
contract TestProofs is Proofs {
mapping(SlotId => SlotState) private _states;
// solhint-disable-next-line no-empty-blocks
constructor(ProofConfig memory config, address verifierAddress) Proofs(config, verifierAddress) {}
constructor(
ProofConfig memory config,
IVerifier verifier
) Proofs(config, verifier) {} // solhint-disable-line no-empty-blocks
function slotState(SlotId slotId) public view override returns (SlotState) {
return _states[slotId];

View File

@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "./Verifier.sol";
contract TestVerifier is IVerifier {
function verifyProof(
uint[2] calldata,
uint[2][2] calldata,
uint[2] calldata,
uint[3] calldata
) external pure returns (bool) {
return false;
}
}

11
contracts/Verifier.sol Normal file
View File

@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
interface IVerifier {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[3] calldata _pubSignals
) external view returns (bool);
}

View File

@ -32,7 +32,7 @@ const {
const ACCOUNT_STARTING_BALANCE = 1_000_000_000
describe("Marketplace constructor", function () {
let Marketplace, token, config
let Marketplace, token, verifier, config
beforeEach(async function () {
await snapshot()
@ -41,6 +41,9 @@ describe("Marketplace constructor", function () {
const TestToken = await ethers.getContractFactory("TestToken")
token = await TestToken.deploy()
const TestVerifier = await ethers.getContractFactory("TestVerifier")
verifier = await TestVerifier.deploy()
Marketplace = await ethers.getContractFactory("TestMarketplace")
config = exampleConfiguration()
})
@ -54,7 +57,7 @@ describe("Marketplace constructor", function () {
config.collateral[property] = 101
await expect(
Marketplace.deploy(token.address, config)
Marketplace.deploy(config, token.address, verifier.address)
).to.be.revertedWith("Must be less than 100")
})
}
@ -66,9 +69,9 @@ describe("Marketplace constructor", function () {
config.collateral.slashPercentage = 1
config.collateral.maxNumberOfSlashes = 101
await expect(Marketplace.deploy(token.address, config)).to.be.revertedWith(
"Maximum slashing exceeds 100%"
)
await expect(
Marketplace.deploy(config, token.address, verifier.address)
).to.be.revertedWith("Maximum slashing exceeds 100%")
})
})
@ -78,6 +81,7 @@ describe("Marketplace", function () {
let marketplace
let token
let verifier
let client, host, host1, host2, host3
let request
let slot
@ -96,8 +100,15 @@ describe("Marketplace", function () {
await token.mint(account.address, ACCOUNT_STARTING_BALANCE)
}
const TestVerifier = await ethers.getContractFactory("TestVerifier")
verifier = await TestVerifier.deploy()
const Marketplace = await ethers.getContractFactory("TestMarketplace")
marketplace = await Marketplace.deploy(token.address, config)
marketplace = await Marketplace.deploy(
config,
token.address,
verifier.address
)
request = await exampleRequest()
request.client = client.address