Re-arrange marketplace constructor parameters
first configuration, then contracts that we depend on
This commit is contained in:
parent
0d9b67bb31
commit
db124ddbd9
|
@ -3,13 +3,14 @@ pragma solidity ^0.8.0;
|
||||||
|
|
||||||
import "./TestToken.sol";
|
import "./TestToken.sol";
|
||||||
import "./Marketplace.sol";
|
import "./Marketplace.sol";
|
||||||
|
import "./TestVerifier.sol";
|
||||||
|
|
||||||
contract FuzzMarketplace is Marketplace {
|
contract FuzzMarketplace is Marketplace {
|
||||||
constructor()
|
constructor()
|
||||||
Marketplace(
|
Marketplace(
|
||||||
new TestToken(),
|
|
||||||
MarketplaceConfig(CollateralConfig(10, 5, 3, 10), ProofConfig(10, 5, 64)),
|
MarketplaceConfig(CollateralConfig(10, 5, 3, 10), ProofConfig(10, 5, 64)),
|
||||||
address(0)
|
new TestToken(),
|
||||||
|
new TestVerifier()
|
||||||
)
|
)
|
||||||
// solhint-disable-next-line no-empty-blocks
|
// solhint-disable-next-line no-empty-blocks
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@ import "./Configuration.sol";
|
||||||
import "./Requests.sol";
|
import "./Requests.sol";
|
||||||
import "./Proofs.sol";
|
import "./Proofs.sol";
|
||||||
import "./StateRetrieval.sol";
|
import "./StateRetrieval.sol";
|
||||||
|
import "./Verifier.sol";
|
||||||
|
|
||||||
contract Marketplace is Proofs, StateRetrieval {
|
contract Marketplace is Proofs, StateRetrieval {
|
||||||
using EnumerableSet for EnumerableSet.Bytes32Set;
|
using EnumerableSet for EnumerableSet.Bytes32Set;
|
||||||
|
@ -55,10 +56,10 @@ contract Marketplace is Proofs, StateRetrieval {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
IERC20 token_,
|
|
||||||
MarketplaceConfig memory configuration,
|
MarketplaceConfig memory configuration,
|
||||||
address verifierAddress
|
IERC20 token_,
|
||||||
) Proofs(configuration.proofs, verifierAddress) {
|
IVerifier verifier
|
||||||
|
) Proofs(configuration.proofs, verifier) {
|
||||||
token = token_;
|
token = token_;
|
||||||
|
|
||||||
require(
|
require(
|
||||||
|
|
|
@ -4,19 +4,16 @@ pragma solidity ^0.8.8;
|
||||||
import "./Configuration.sol";
|
import "./Configuration.sol";
|
||||||
import "./Requests.sol";
|
import "./Requests.sol";
|
||||||
import "./Periods.sol";
|
import "./Periods.sol";
|
||||||
|
import "./Verifier.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract contract Proofs is Periods {
|
abstract contract Proofs is Periods {
|
||||||
ProofConfig private _config;
|
ProofConfig private _config;
|
||||||
IVerifier private _verifier;
|
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");
|
require(block.number > 256, "Insufficient block height");
|
||||||
_config = config;
|
_config = config;
|
||||||
_verifier = IVerifier(verifierAddress);
|
_verifier = verifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping(SlotId => uint256) private _slotStarts;
|
mapping(SlotId => uint256) private _slotStarts;
|
||||||
|
|
|
@ -6,11 +6,11 @@ import "./Marketplace.sol";
|
||||||
// exposes internal functions of Marketplace for testing
|
// exposes internal functions of Marketplace for testing
|
||||||
contract TestMarketplace is Marketplace {
|
contract TestMarketplace is Marketplace {
|
||||||
constructor(
|
constructor(
|
||||||
IERC20 token,
|
|
||||||
MarketplaceConfig memory config,
|
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 {
|
function forciblyFreeSlot(SlotId slotId) public {
|
||||||
|
|
|
@ -7,8 +7,10 @@ import "./Proofs.sol";
|
||||||
contract TestProofs is Proofs {
|
contract TestProofs is Proofs {
|
||||||
mapping(SlotId => SlotState) private _states;
|
mapping(SlotId => SlotState) private _states;
|
||||||
|
|
||||||
// solhint-disable-next-line no-empty-blocks
|
constructor(
|
||||||
constructor(ProofConfig memory config, address verifierAddress) Proofs(config, verifierAddress) {}
|
ProofConfig memory config,
|
||||||
|
IVerifier verifier
|
||||||
|
) Proofs(config, verifier) {} // solhint-disable-line no-empty-blocks
|
||||||
|
|
||||||
function slotState(SlotId slotId) public view override returns (SlotState) {
|
function slotState(SlotId slotId) public view override returns (SlotState) {
|
||||||
return _states[slotId];
|
return _states[slotId];
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ const {
|
||||||
const ACCOUNT_STARTING_BALANCE = 1_000_000_000
|
const ACCOUNT_STARTING_BALANCE = 1_000_000_000
|
||||||
|
|
||||||
describe("Marketplace constructor", function () {
|
describe("Marketplace constructor", function () {
|
||||||
let Marketplace, token, config
|
let Marketplace, token, verifier, config
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await snapshot()
|
await snapshot()
|
||||||
|
@ -41,6 +41,9 @@ describe("Marketplace constructor", function () {
|
||||||
const TestToken = await ethers.getContractFactory("TestToken")
|
const TestToken = await ethers.getContractFactory("TestToken")
|
||||||
token = await TestToken.deploy()
|
token = await TestToken.deploy()
|
||||||
|
|
||||||
|
const TestVerifier = await ethers.getContractFactory("TestVerifier")
|
||||||
|
verifier = await TestVerifier.deploy()
|
||||||
|
|
||||||
Marketplace = await ethers.getContractFactory("TestMarketplace")
|
Marketplace = await ethers.getContractFactory("TestMarketplace")
|
||||||
config = exampleConfiguration()
|
config = exampleConfiguration()
|
||||||
})
|
})
|
||||||
|
@ -54,7 +57,7 @@ describe("Marketplace constructor", function () {
|
||||||
config.collateral[property] = 101
|
config.collateral[property] = 101
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
Marketplace.deploy(token.address, config)
|
Marketplace.deploy(config, token.address, verifier.address)
|
||||||
).to.be.revertedWith("Must be less than 100")
|
).to.be.revertedWith("Must be less than 100")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -66,9 +69,9 @@ describe("Marketplace constructor", function () {
|
||||||
config.collateral.slashPercentage = 1
|
config.collateral.slashPercentage = 1
|
||||||
config.collateral.maxNumberOfSlashes = 101
|
config.collateral.maxNumberOfSlashes = 101
|
||||||
|
|
||||||
await expect(Marketplace.deploy(token.address, config)).to.be.revertedWith(
|
await expect(
|
||||||
"Maximum slashing exceeds 100%"
|
Marketplace.deploy(config, token.address, verifier.address)
|
||||||
)
|
).to.be.revertedWith("Maximum slashing exceeds 100%")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -78,6 +81,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
let marketplace
|
let marketplace
|
||||||
let token
|
let token
|
||||||
|
let verifier
|
||||||
let client, host, host1, host2, host3
|
let client, host, host1, host2, host3
|
||||||
let request
|
let request
|
||||||
let slot
|
let slot
|
||||||
|
@ -96,8 +100,15 @@ describe("Marketplace", function () {
|
||||||
await token.mint(account.address, ACCOUNT_STARTING_BALANCE)
|
await token.mint(account.address, ACCOUNT_STARTING_BALANCE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TestVerifier = await ethers.getContractFactory("TestVerifier")
|
||||||
|
verifier = await TestVerifier.deploy()
|
||||||
|
|
||||||
const Marketplace = await ethers.getContractFactory("TestMarketplace")
|
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 = await exampleRequest()
|
||||||
request.client = client.address
|
request.client = client.address
|
||||||
|
|
Loading…
Reference in New Issue