Skip to content

Commit df6132e

Browse files
committed
chore: integration test update
1 parent d1c5961 commit df6132e

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

contracts/test/arbitration/draw.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ describe("Draw Benchmark", async () => {
137137
const tx = await arbitrable["createDispute(string)"]("future of france", {
138138
value: arbitrationCost,
139139
});
140-
if (tx.blockNumber === null) return;
140+
if (tx.blockNumber === null) throw new Error("tx.blockNumber is null");
141141
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
142142
const [disputeId] = abiCoder.decode(["uint"], `0x${trace.returnValue}`);
143143
const lastBlock = await ethers.provider.getBlock(tx.blockNumber - 1);
144-
if (lastBlock?.hash === null || lastBlock?.hash === undefined) return;
144+
if (lastBlock?.hash === null || lastBlock?.hash === undefined) throw new Error("lastBlock is null || undefined");
145145
// Relayer tx
146146
await homeGateway
147147
.connect(await ethers.getSigner(relayer))
@@ -215,7 +215,7 @@ describe("Draw Benchmark", async () => {
215215
.withArgs(anyValue, 0, 0, 1)
216216
.to.emit(core, "Draw")
217217
.withArgs(anyValue, 0, 0, 2);
218-
if (tx?.blockNumber === undefined) return;
218+
if (tx?.blockNumber === undefined) throw new Error("txBlockNumber is null");
219219
countedDraws = await countDraws(tx.blockNumber);
220220
for (const [address, draws] of Object.entries(countedDraws)) {
221221
expect(await sortitionModule.getJurorBalance(address, PARENT_COURT)).to.deep.equal([
@@ -306,7 +306,7 @@ describe("Draw Benchmark", async () => {
306306
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);
307307

308308
const tx = await (await drawTx).wait();
309-
if (tx === null) return;
309+
if (tx === null) throw new Error("tx is null");
310310
expect(tx)
311311
.to.emit(core, "Draw")
312312
.withArgs(anyValue, 0, 0, 0)
@@ -368,7 +368,7 @@ describe("Draw Benchmark", async () => {
368368
expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);
369369

370370
const tx = await (await drawTx).wait();
371-
if (tx === null) return;
371+
if (tx === null) throw new Error("tx is null");
372372
expect(tx)
373373
.to.emit(core, "Draw")
374374
.withArgs(anyValue, 0, 0, 0)

contracts/test/evidence/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Party = {
1313
function getEmittedEvent(eventName: any, receipt: ContractTransactionReceipt): EventLog {
1414
const logs = receipt.logs as Array<EventLog>;
1515
const event = logs.find((log) => log.eventName === eventName);
16-
if (event === undefined) process.exit();
16+
if (event === undefined) throw new Error(`Event ${eventName} not found`);
1717
return event;
1818
}
1919

@@ -139,7 +139,7 @@ describe("Home Evidence contract", async () => {
139139
value: minRequiredDeposit,
140140
}); // id: 0
141141
const receipt = await tx.wait();
142-
if (receipt === null) return;
142+
if (receipt === null) throw new Error("Receipt is null");
143143
const evidenceID = ethers.solidityPackedKeccak256(["uint", "string"], [1234, newEvidence]);
144144

145145
const [_arbitrator, _externalDisputeID, _party, _evidence] = getEmittedEvent("ModeratedEvidence", receipt).args;
@@ -248,7 +248,7 @@ describe("Home Evidence contract", async () => {
248248
value: depositRequired, // Less is actually needed. Overpaid fees are reimbursed
249249
});
250250
let receipt = await tx.wait();
251-
if (receipt === null) return;
251+
if (receipt === null) throw new Error("Receipt is null");
252252
let [_arbitrator, _arbitrableDisputeID, _externalDisputeID, _templateId, _templateUri] = getEmittedEvent(
253253
"DisputeRequest",
254254
receipt

contracts/test/integration/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
22
import { expect } from "chai";
33
import { deployments, ethers, getNamedAccounts, network } from "hardhat";
4-
import { toBigInt, BytesLike } from "ethers";
4+
import { toBigInt } from "ethers";
55
import {
66
PNK,
77
KlerosCore,
@@ -105,6 +105,7 @@ describe("Integration tests", async () => {
105105
const tx = await arbitrable["createDispute(string)"]("future of france", {
106106
value: arbitrationCost,
107107
});
108+
108109
const trace = await network.provider.send("debug_traceTransaction", [tx.hash]);
109110
const [disputeId] = abiCoder.decode(["uint"], `0x${trace.returnValue}`); // get returned value from createDispute()
110111
console.log("Dispute Created with disputeId: %d", disputeId);
@@ -120,20 +121,23 @@ describe("Integration tests", async () => {
120121
0,
121122
""
122123
);
123-
124-
const lastBlock = await ethers.provider.getBlock(tx.blockNumber ?? 0 - 1);
124+
if (tx.blockNumber === null) throw new Error("tx.blockNumber is null");
125+
const lastBlock = await ethers.provider.getBlock(tx.blockNumber - 1);
126+
if (lastBlock === null) throw new Error("lastBlock is null");
125127
const disputeHash = ethers.solidityPackedKeccak256(
126128
["bytes", "bytes32", "uint256", "address", "uint256", "uint256", "bytes"],
127-
[ethers.toUtf8Bytes("createDispute"), lastBlock?.hash, 31337, arbitrable.target, disputeId, 2, "0x00"]
129+
[ethers.toUtf8Bytes("createDispute"), lastBlock.hash, 31337, arbitrable.target, disputeId, 2, "0x00"]
128130
);
129131
console.log("dispute hash: ", disputeHash);
130-
132+
if (lastBlock.hash === null) {
133+
process.exit();
134+
}
131135
// Relayer tx
132136
const tx2 = await homeGateway
133137
.connect(relayer)
134138
["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
135139
{
136-
foreignBlockHash: lastBlock?.hash as BytesLike,
140+
foreignBlockHash: ethers.toBeHex(lastBlock.hash),
137141
foreignChainID: 31337,
138142
foreignArbitrable: arbitrable.target,
139143
foreignDisputeID: disputeId,
@@ -202,5 +206,5 @@ describe("Integration tests", async () => {
202206
});
203207

204208
const logJurorBalance = async (result) => {
205-
console.log("staked=%s, locked=%s", ethers.formatUnits(result.totalLocked), ethers.formatUnits(result.totalStaked));
209+
console.log("staked=%s, locked=%s", ethers.formatUnits(result.totalStaked), ethers.formatUnits(result.totalLocked));
206210
};

0 commit comments

Comments
 (0)