Skip to content

Commit

Permalink
fix(RNG): test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownunknown1 committed Oct 29, 2023
1 parent 9ce3f4b commit acfcd1b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
5 changes: 0 additions & 5 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", pnk, 12225583, 12);
await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", dai, 60327783, 11);
await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", weth, 1, 1);
await deploy("DisputeResolver", {
from: deployer,
args: [klerosCore.address],
log: true,
});

const link = linkByChain.get(Number(await getChainId())) ?? AddressZero; // LINK not needed on hardhat local node
const keyHash = keyHashByChain.get(Number(await getChainId())) ?? AddressZero;
Expand Down
19 changes: 15 additions & 4 deletions contracts/test/arbitration/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ describe("Draw Benchmark", async () => {
}

// Create a dispute
const tx = await arbitrable.createDispute(2, "0x00", 0, {
const tx = await arbitrable.functions["createDispute(string)"]("RNG test", {
value: arbitrationCost,
});
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
Expand All @@ -451,9 +451,20 @@ describe("Draw Benchmark", async () => {
// Relayer tx
const tx2 = await homeGateway
.connect(await ethers.getSigner(relayer))
.relayCreateDispute(31337, lastBlock.hash, disputeId, 2, "0x00", arbitrable.address, {
value: arbitrationCost,
});
.functions["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
{
foreignBlockHash: lastBlock.hash,
foreignChainID: 31337,
foreignArbitrable: arbitrable.address,
foreignDisputeID: disputeId,
externalDisputeID: ethers.utils.keccak256(ethers.utils.toUtf8Bytes("RNG test")),
templateId: 0,
templateUri: "",
choices: 2,
extraData: `0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003`, // General Court, 3 jurors
},
{ value: arbitrationCost }
);

await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime
await network.provider.send("evm_mine");
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/arbitration/unstake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("Unstake juror", async () => {

expect(await core.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]);

await core.createDispute(2, extraData, { value: arbitrationCost });
await core.functions["createDispute(uint256,bytes)"](2, extraData, { value: arbitrationCost });

await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime
await network.provider.send("evm_mine");
Expand Down
61 changes: 41 additions & 20 deletions contracts/test/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ describe("Integration tests", async () => {

const roundInfo = await core.getRoundInfo(0, 0);
expect(roundInfo.drawnJurors).deep.equal([deployer, deployer, deployer]);
expect(roundInfo.tokensAtStakePerJuror).to.equal(ONE_HUNDRED_PNK.mul(2));
expect(roundInfo.pnkAtStakePerJuror).to.equal(ONE_HUNDRED_PNK.mul(2));
expect(roundInfo.totalFeesForJurors).to.equal(arbitrationCost);
expect(roundInfo.feeToken).to.equal(ethers.constants.AddressZero);

expect((await core.disputes(0)).period).to.equal(Period.evidence);

Expand Down Expand Up @@ -210,55 +211,75 @@ describe("Integration tests", async () => {

await core.setStake(1, ONE_THOUSAND_PNK);
await core.getJurorBalance(deployer, 1).then((result) => {
expect(result.staked).to.equal(ONE_THOUSAND_PNK);
expect(result.locked).to.equal(0);
expect(result.totalStaked).to.equal(ONE_THOUSAND_PNK);
expect(result.totalLocked).to.equal(0);
logJurorBalance(result);
});

await core.setStake(1, ONE_HUNDRED_PNK.mul(5));
await core.getJurorBalance(deployer, 1).then((result) => {
expect(result.staked).to.equal(ONE_HUNDRED_PNK.mul(5));
expect(result.locked).to.equal(0);
expect(result.totalStaked).to.equal(ONE_HUNDRED_PNK.mul(5));
expect(result.totalLocked).to.equal(0);
logJurorBalance(result);
});

await core.setStake(1, 0);
await core.getJurorBalance(deployer, 1).then((result) => {
expect(result.staked).to.equal(0);
expect(result.locked).to.equal(0);
expect(result.totalStaked).to.equal(0);
expect(result.totalLocked).to.equal(0);
logJurorBalance(result);
});

await core.setStake(1, ONE_THOUSAND_PNK.mul(4));
await core.getJurorBalance(deployer, 1).then((result) => {
expect(result.staked).to.equal(ONE_THOUSAND_PNK.mul(4));
expect(result.locked).to.equal(0);
expect(result.totalStaked).to.equal(ONE_THOUSAND_PNK.mul(4));
expect(result.totalLocked).to.equal(0);
logJurorBalance(result);
});
const tx = await arbitrable.createDispute(2, "0x00", 0, {
const tx = await arbitrable.functions["createDispute(string)"]("RNG test", {
value: arbitrationCost,
});
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
const [disputeId] = ethers.utils.defaultAbiCoder.decode(["uint"], `0x${trace.returnValue}`); // get returned value from createDispute()
console.log("Dispute Created");
expect(tx).to.emit(foreignGateway, "DisputeCreation");
expect(tx).to.emit(foreignGateway, "OutgoingDispute");
console.log(`disputeId: ${disputeId}`);
console.log("Dispute Created with disputeId: %d", disputeId);
await expect(tx)
.to.emit(foreignGateway, "CrossChainDisputeOutgoing")
.withArgs(anyValue, arbitrable.address, 1, 2, "0x00");
await expect(tx)
.to.emit(arbitrable, "DisputeRequest")
.withArgs(
foreignGateway.address,
1,
BigNumber.from("100587076116875319099890440047601180158236049259177371049006183970829186180694"),
0,
""
);

const lastBlock = await ethers.provider.getBlock(tx.blockNumber - 1);
const disputeHash = ethers.utils.solidityKeccak256(
["uint", "bytes", "bytes", "uint", "uint", "bytes", "address"],
[31337, lastBlock.hash, ethers.utils.toUtf8Bytes("createDispute"), disputeId, 2, "0x00", arbitrable.address]
["bytes", "bytes32", "uint256", "address", "uint256", "uint256", "bytes"],
[ethers.utils.toUtf8Bytes("createDispute"), lastBlock.hash, 31337, arbitrable.address, disputeId, 2, "0x00"]
);

const events = (await tx.wait()).events;
console.log("dispute hash: ", disputeHash);

// Relayer tx
const tx2 = await homeGateway
.connect(relayer)
.relayCreateDispute(31337, lastBlock.hash, disputeId, 2, "0x00", arbitrable.address, {
value: arbitrationCost,
});
.functions["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
{
foreignBlockHash: lastBlock.hash,
foreignChainID: 31337,
foreignArbitrable: arbitrable.address,
foreignDisputeID: disputeId,
externalDisputeID: ethers.utils.keccak256(ethers.utils.toUtf8Bytes("RNG test")),
templateId: 0,
templateUri: "",
choices: 2,
extraData: "0x00",
},
{ value: arbitrationCost }
);
expect(tx2).to.emit(homeGateway, "Dispute");
const events2 = (await tx2.wait()).events;

Expand Down

0 comments on commit acfcd1b

Please sign in to comment.