Skip to content

Commit c9492b2

Browse files
committed
chore: arbitration/staking.ts update
1 parent d6b5531 commit c9492b2

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

contracts/test/arbitration/staking.ts

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { ethers, getNamedAccounts, network, deployments } from "hardhat";
22
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
3-
import { BigNumber } from "ethers";
3+
import { toBigInt, BytesLike } from "ethers";
44
import { PNK, KlerosCore, SortitionModule, RandomizerRNG, RandomizerMock } from "../../typechain-types";
55
import { expect } from "chai";
66

77
/* eslint-disable no-unused-vars */
88
/* eslint-disable no-unused-expressions */
99

1010
describe("Staking", async () => {
11-
const ETH = (amount: number) => ethers.utils.parseUnits(amount.toString());
11+
const ETH = (amount: number) => ethers.parseUnits(amount.toString());
1212
const PNK = ETH;
1313

1414
// 2nd court, 3 jurors, 1 dispute kit
1515
const extraData =
1616
"0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001";
1717

1818
let deployer;
19-
let pnk;
20-
let core;
21-
let sortition;
22-
let rng;
23-
let randomizer;
19+
let pnk: PNK;
20+
let core: KlerosCore;
21+
let sortition: SortitionModule;
22+
let rng: RandomizerRNG;
23+
let randomizer: RandomizerMock;
2424

2525
const deploy = async () => {
2626
({ deployer } = await getNamedAccounts());
@@ -40,17 +40,16 @@ describe("Staking", async () => {
4040

4141
const reachDrawingPhase = async () => {
4242
expect(await sortition.phase()).to.be.equal(0); // Staking
43-
const arbitrationCost = ETH(0.1).mul(3);
43+
const arbitrationCost = ETH(0.1) * toBigInt(3);
44+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
4445

45-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit
46-
47-
await pnk.approve(core.address, PNK(4000));
46+
await pnk.approve(core.target, PNK(4000));
4847
await core.setStake(1, PNK(2000));
4948
await core.setStake(2, PNK(2000));
5049

51-
expect(await sortition.getJurorCourtIDs(deployer)).to.be.deep.equal([BigNumber.from("1"), BigNumber.from("2")]);
50+
expect(await sortition.getJurorCourtIDs(deployer)).to.be.deep.equal([toBigInt("1"), toBigInt("2")]);
5251

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

5554
await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime
5655
await network.provider.send("evm_mine");
@@ -65,7 +64,7 @@ describe("Staking", async () => {
6564
};
6665

6766
const reachStakingPhaseAfterDrawing = async () => {
68-
await randomizer.relay(rng.address, 0, ethers.utils.randomBytes(32));
67+
await randomizer.relay(rng.target, 0, ethers.randomBytes(32));
6968
await sortition.passPhase(); // Generating -> Drawing
7069
await core.draw(0, 5000);
7170
await sortition.passPhase(); // Drawing -> Staking
@@ -86,7 +85,7 @@ describe("Staking", async () => {
8685
it("Should transfer PNK but delay the stake increase", async () => {
8786
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
8887
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
89-
await pnk.approve(core.address, PNK(1000));
88+
await pnk.approve(core.target, PNK(1000));
9089
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
9190
await expect(core.setStake(2, PNK(3000)))
9291
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
@@ -95,7 +94,7 @@ describe("Staking", async () => {
9594
});
9695

9796
it("Should transfer some PNK out of the juror's account", async () => {
98-
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore.sub(PNK(1000))); // PNK is transferred out of the juror's account
97+
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore - toBigInt(PNK(1000))); // PNK is transferred out of the juror's account
9998
});
10099

101100
it("Should store the delayed stake for later", async () => {
@@ -127,8 +126,8 @@ describe("Staking", async () => {
127126
]); // stake unchanged, delayed
128127
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
129128
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
130-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
131-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 2nd delayed stake got deleted
129+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
130+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
132131
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // no delayed stakes left
133132
});
134133

@@ -190,13 +189,13 @@ describe("Staking", async () => {
190189
]); // stake unchanged, delayed
191190
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
192191
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
193-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
194-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 2nd delayed stake got deleted
192+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
193+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
195194
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // no delayed stakes left
196195
});
197196

198197
it("Should withdraw some PNK", async () => {
199-
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore.add(PNK(1000))); // No PNK transfer yet
198+
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore + toBigInt(PNK(1000))); // No PNK transfer yet
200199
});
201200
});
202201
});
@@ -254,7 +253,7 @@ describe("Staking", async () => {
254253
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(2);
255254
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
256255
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
257-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
256+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
258257
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
259258
});
260259
});
@@ -277,8 +276,8 @@ describe("Staking", async () => {
277276
]); // stake unchanged, delayed
278277
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
279278
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
280-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
281-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 2nd delayed stake got deleted
279+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
280+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
282281
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // no delayed stakes left
283282
});
284283

@@ -303,7 +302,7 @@ describe("Staking", async () => {
303302
it("Should transfer PNK but delay the stake increase", async () => {
304303
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
305304
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
306-
await pnk.approve(core.address, PNK(1000));
305+
await pnk.approve(core.target, PNK(1000));
307306
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0);
308307
await expect(core.setStake(2, PNK(3000)))
309308
.to.emit(sortition, "StakeDelayedAlreadyTransferred")
@@ -312,7 +311,7 @@ describe("Staking", async () => {
312311
});
313312

314313
it("Should transfer some PNK out of the juror's account", async () => {
315-
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore.sub(PNK(1000))); // PNK is transferred out of the juror's account
314+
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore - toBigInt(PNK(1000))); // PNK is transferred out of the juror's account
316315
});
317316

318317
it("Should store the delayed stake for later", async () => {
@@ -336,14 +335,14 @@ describe("Staking", async () => {
336335
});
337336

338337
it("Should transfer back some PNK to the juror", async () => {
339-
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore.add(PNK(1000))); // PNK is sent back to the juror
338+
expect(await pnk.balanceOf(deployer)).to.be.equal(balanceBefore + toBigInt(PNK(1000))); // PNK is sent back to the juror
340339
});
341340

342341
it("Should store the delayed stake for later", async () => {
343342
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(2);
344343
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
345344
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
346-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
345+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
347346
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
348347
});
349348
});
@@ -369,8 +368,8 @@ describe("Staking", async () => {
369368
]); // stake unchanged, delayed
370369
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
371370
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
372-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 1st delayed stake got deleted
373-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.constants.AddressZero, 0, 0, false]); // the 2nd delayed stake got deleted
371+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
372+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
374373
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // no delayed stakes left
375374
});
376375

@@ -387,17 +386,16 @@ describe("Staking", async () => {
387386
});
388387

389388
it("Should unstake from all courts", async () => {
390-
const arbitrationCost = ETH(0.1).mul(3);
391-
392-
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], 3, [1]); // Parent - general court, Classic dispute kit
389+
const arbitrationCost = ETH(0.1) * toBigInt(3);
390+
await core.createCourt(1, false, PNK(1000), 1000, ETH(0.1), 3, [0, 0, 0, 0], ethers.toBeHex(3), [1]); // Parent - general court, Classic dispute kit
393391

394-
await pnk.approve(core.address, PNK(4000));
392+
await pnk.approve(core.target, PNK(4000));
395393
await core.setStake(1, PNK(2000));
396394
await core.setStake(2, PNK(2000));
397395

398396
expect(await sortition.getJurorCourtIDs(deployer)).to.be.deep.equal([1, 2]);
399397

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

402400
await network.provider.send("evm_increaseTime", [2000]); // Wait for minStakingTime
403401
await network.provider.send("evm_mine");
@@ -407,7 +405,7 @@ describe("Staking", async () => {
407405
for (let index = 0; index < lookahead; index++) {
408406
await network.provider.send("evm_mine");
409407
}
410-
await randomizer.relay(rng.address, 0, ethers.utils.randomBytes(32));
408+
await randomizer.relay(rng.target, 0, ethers.randomBytes(32));
411409
await sortition.passPhase(); // Generating -> Drawing
412410

413411
await core.draw(0, 5000);

0 commit comments

Comments
 (0)