-
Notifications
You must be signed in to change notification settings - Fork 50
Universal Gated Dispute Kit and Shutter Gated Dispute Kit #2045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { deployments, ethers, getNamedAccounts, network } from "hardhat"; | ||
| import { toBigInt, BigNumberish, Addressable } from "ethers"; | ||
| import { PNK, KlerosCore, SortitionModule, IncrementalNG, DisputeKitGated } from "../../typechain-types"; | ||
| import { expect } from "chai"; | ||
| import { Courts } from "../../deploy/utils"; | ||
| import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; | ||
|
|
||
| /* eslint-disable no-unused-vars */ | ||
| /* eslint-disable no-unused-expressions */ // https://github.com/standard/standard/issues/690#issuecomment-278533482 | ||
|
|
||
| describe("DisputeKitGated", async () => { | ||
| const ONE_THOUSAND_PNK = 10n ** 21n; | ||
| const thousandPNK = (amount: BigNumberish) => toBigInt(amount) * ONE_THOUSAND_PNK; | ||
|
|
||
| let deployer: string; | ||
| let juror1: HardhatEthersSigner; | ||
| let juror2: HardhatEthersSigner; | ||
| let disputeKitGated: DisputeKitGated; | ||
| let pnk: PNK; | ||
| let core: KlerosCore; | ||
| let sortitionModule: SortitionModule; | ||
| let rng: IncrementalNG; | ||
| const RANDOM = 424242n; | ||
|
|
||
| beforeEach("Setup", async () => { | ||
| ({ deployer } = await getNamedAccounts()); | ||
| [, juror1, juror2] = await ethers.getSigners(); | ||
|
|
||
| await deployments.fixture(["Arbitration", "VeaMock"], { | ||
| fallbackToGlobal: true, | ||
| keepExistingDeployments: false, | ||
| }); | ||
| disputeKitGated = (await ethers.getContract("DisputeKitGated")) as DisputeKitGated; | ||
| pnk = (await ethers.getContract("PNK")) as PNK; | ||
| core = (await ethers.getContract("KlerosCore")) as KlerosCore; | ||
| sortitionModule = (await ethers.getContract("SortitionModule")) as SortitionModule; | ||
|
|
||
| // Make the tests more deterministic with this dummy RNG | ||
| await deployments.deploy("IncrementalNG", { | ||
| from: deployer, | ||
| args: [RANDOM], | ||
| log: true, | ||
| }); | ||
| rng = (await ethers.getContract("IncrementalNG")) as IncrementalNG; | ||
|
|
||
| await sortitionModule.changeRandomNumberGenerator(rng.target, 20).then((tx) => tx.wait()); | ||
| }); | ||
|
|
||
| const encodeExtraData = ( | ||
| courtId: number, | ||
| minJurors: number, | ||
| disputeKitId: number, | ||
| tokenGate: string | Addressable, | ||
| isERC1155: boolean, | ||
| tokenId: BigNumberish | ||
| ) => { | ||
| // Packing of tokenGate and isERC1155 | ||
| // uint88 (padding 11 bytes) + bool (1 byte) + address (20 bytes) = 32 bytes | ||
| const packed = ethers.solidityPacked(["uint88", "bool", "address"], [0, isERC1155, tokenGate]); | ||
| return ethers.AbiCoder.defaultAbiCoder().encode( | ||
| ["uint256", "uint256", "uint256", "bytes32", "uint256"], | ||
| [courtId, minJurors, disputeKitId, packed, tokenId] | ||
| ); | ||
| }; | ||
|
|
||
| const stakeAndDraw = async ( | ||
| courtId: number, | ||
| minJurors: number, | ||
| disputeKitId: number, | ||
| tokenGate: string | Addressable, | ||
| isERC1155: boolean, | ||
| tokenId: BigNumberish | ||
| ) => { | ||
| // Stake jurors | ||
| for (const juror of [juror1, juror2]) { | ||
| await pnk.transfer(juror.address, thousandPNK(10)).then((tx) => tx.wait()); | ||
| expect(await pnk.balanceOf(juror.address)).to.equal(thousandPNK(10)); | ||
|
|
||
| await pnk | ||
| .connect(juror) | ||
| .approve(core.target, thousandPNK(10), { gasLimit: 300000 }) | ||
| .then((tx) => tx.wait()); | ||
|
|
||
| await core | ||
| .connect(juror) | ||
| .setStake(Courts.GENERAL, thousandPNK(10), { gasLimit: 300000 }) | ||
| .then((tx) => tx.wait()); | ||
|
|
||
| expect(await sortitionModule.getJurorBalance(juror.address, 1)).to.deep.equal([ | ||
| thousandPNK(10), // totalStaked | ||
| 0, // totalLocked | ||
| thousandPNK(10), // stakedInCourt | ||
| 1, // nbOfCourts | ||
| ]); | ||
| } | ||
|
|
||
| const extraData = encodeExtraData(courtId, minJurors, disputeKitId, tokenGate, isERC1155, tokenId); | ||
| console.log("extraData", extraData); | ||
|
|
||
| const tokenInfo = await disputeKitGated.extraDataToTokenInfo(extraData); | ||
| expect(tokenInfo[0]).to.equal(tokenGate); | ||
| expect(tokenInfo[1]).to.equal(isERC1155); | ||
| expect(tokenInfo[2]).to.equal(tokenId); | ||
|
|
||
| const arbitrationCost = await core["arbitrationCost(bytes)"](extraData); | ||
|
|
||
| // Warning: this dispute cannot be executed, in reality it should be created by an arbitrable contract, not an EOA. | ||
| const tx = await core["createDispute(uint256,bytes)"](2, extraData, { value: arbitrationCost }).then((tx) => | ||
| tx.wait() | ||
| ); | ||
| const disputeId = 0; | ||
| // console.log(tx?.logs); | ||
|
|
||
| await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime | ||
| await network.provider.send("evm_mine"); | ||
| await sortitionModule.passPhase().then((tx) => tx.wait()); // Staking -> Generating | ||
|
|
||
| const lookahead = await sortitionModule.rngLookahead(); | ||
| for (let index = 0; index < lookahead; index++) { | ||
| await network.provider.send("evm_mine"); | ||
| } | ||
|
|
||
| await sortitionModule.passPhase().then((tx) => tx.wait()); // Generating -> Drawing | ||
| return core.draw(disputeId, 20, { gasLimit: 1000000 }); | ||
| }; | ||
|
|
||
| describe("When gating with PNK token", async () => { | ||
| it("Should draw all the jurors successfully", async () => { | ||
| await stakeAndDraw(Courts.GENERAL, 3, 3, pnk.target, false, 0); | ||
| // TODO: expect.... | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / SonarCloud
Unused assignments should be removed Low test