From acfcd1b26695b13b7df350bba6855cd4833d4841 Mon Sep 17 00:00:00 2001 From: unknownunknown1 Date: Mon, 30 Oct 2023 00:13:16 +1000 Subject: [PATCH] fix(RNG): test fixes --- contracts/deploy/00-home-chain-arbitration.ts | 5 -- contracts/test/arbitration/draw.ts | 19 ++++-- contracts/test/arbitration/unstake.ts | 2 +- contracts/test/integration/index.ts | 61 +++++++++++++------ 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/contracts/deploy/00-home-chain-arbitration.ts b/contracts/deploy/00-home-chain-arbitration.ts index f95bdde01..c68a4a102 100644 --- a/contracts/deploy/00-home-chain-arbitration.ts +++ b/contracts/deploy/00-home-chain-arbitration.ts @@ -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; diff --git a/contracts/test/arbitration/draw.ts b/contracts/test/arbitration/draw.ts index d1600858c..db41e4338 100644 --- a/contracts/test/arbitration/draw.ts +++ b/contracts/test/arbitration/draw.ts @@ -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]); @@ -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"); diff --git a/contracts/test/arbitration/unstake.ts b/contracts/test/arbitration/unstake.ts index 818488710..4f22a133a 100644 --- a/contracts/test/arbitration/unstake.ts +++ b/contracts/test/arbitration/unstake.ts @@ -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"); diff --git a/contracts/test/integration/index.ts b/contracts/test/integration/index.ts index 542b2fdd4..6f23cc777 100644 --- a/contracts/test/integration/index.ts +++ b/contracts/test/integration/index.ts @@ -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); @@ -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;