Skip to content

Commit e8e0d87

Browse files
committed
fix: fixed the IncrementalNG to start from a non-zero value, fixed the skipped tests
1 parent 1f37609 commit e8e0d87

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2525

2626
const rng = await deploy("IncrementalNG", {
2727
from: deployer,
28+
args: [67193503189],
2829
log: true,
2930
});
3031

contracts/scripts/changeRng.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function main() {
2121

2222
const rng = await deploy("IncrementalNG", {
2323
from: deployer,
24+
args: [6485021504514574],
2425
log: true,
2526
skipIfAlreadyDeployed: false, // BUG: this parameter does nothing
2627
});

contracts/src/rng/IncrementalNG.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import "./RNG.sol";
1212
contract IncrementalNG is RNG {
1313
uint256 public number;
1414

15+
constructor(uint256 _start) {
16+
number = _start;
17+
}
18+
1519
/**
1620
* @dev Contribute to the reward of a random number. All the ETH will be lost forever.
1721
* @param _block Block the random number is linked to.

contracts/test/pre-alpha1/index.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("Demo pre-alpha1", function () {
4545
let deployer, relayer, bridger, challenger, innocentBystander;
4646
let ng, disputeKit, pnk, core, fastBridgeReceiver, foreignGateway, arbitrable, fastBridgeSender, homeGateway, inbox;
4747

48-
before("Setup", async () => {
48+
beforeEach("Setup", async () => {
4949
deployer = (await getNamedAccounts()).deployer;
5050
relayer = (await getNamedAccounts()).relayer;
5151

@@ -217,10 +217,7 @@ describe("Demo pre-alpha1", function () {
217217
const tx8 = await fastBridgeReceiver.withdrawClaimDeposit(ticketID);
218218
});
219219

220-
it.skip("Demo - Honest Claim - Challenged - Bridger Paid, Challenger deposit forfeited", async () => {
221-
222-
// TODO: FIX ME !
223-
220+
it("Demo - Honest Claim - Challenged - Bridger Paid, Challenger deposit forfeited", async () => {
224221
const arbitrationCost = ONE_TENTH_ETH.mul(3);
225222
const [bridger, challenger] = await ethers.getSigners();
226223

@@ -322,14 +319,14 @@ describe("Demo pre-alpha1", function () {
322319
console.log("draw successful");
323320
const events3 = (await tx3.wait()).events;
324321

325-
const roundInfo = await core.getRoundInfo(1, 0);
322+
const roundInfo = await core.getRoundInfo(0, 0);
326323
expect(roundInfo.drawnJurors).deep.equal([deployer, deployer, deployer]);
327324
expect(roundInfo.tokensAtStakePerJuror).to.equal(ONE_HUNDRED_PNK.mul(2));
328325
expect(roundInfo.totalFeesForJurors).to.equal(arbitrationCost);
329326

330-
expect((await core.disputes(1)).period).to.equal(Period.evidence);
331-
await core.passPeriod(1);
332-
expect((await core.disputes(1)).period).to.equal(Period.vote);
327+
expect((await core.disputes(0)).period).to.equal(Period.evidence);
328+
await core.passPeriod(0);
329+
expect((await core.disputes(0)).period).to.equal(Period.vote);
333330

334331
console.log("KC phase: %d, DK phase: ", await core.phase(), await disputeKit.phase());
335332

@@ -345,22 +342,22 @@ describe("Demo pre-alpha1", function () {
345342

346343
console.log("KC phase: %d, DK phase: ", await core.phase(), await disputeKit.phase());
347344

348-
await disputeKit.connect(await ethers.getSigner(deployer)).castVote(1, [0, 1, 2], 0, 0);
349-
await core.passPeriod(1);
350-
await core.passPeriod(1);
351-
expect((await core.disputes(1)).period).to.equal(Period.execution);
352-
await core.execute(1, 0, 1000);
345+
await disputeKit.connect(await ethers.getSigner(deployer)).castVote(0, [0, 1, 2], 0, 0);
346+
await core.passPeriod(0);
347+
await core.passPeriod(0);
348+
expect((await core.disputes(0)).period).to.equal(Period.execution);
349+
await core.execute(0, 0, 1000);
353350
const ticket1 = await fastBridgeSender.currentTicketID();
354-
expect(ticket1).to.equal(2);
351+
expect(ticket1).to.equal(1);
355352

356-
const tx4 = await core.executeRuling(1);
353+
const tx4 = await core.executeRuling(0);
357354

358355
expect(tx4).to.emit(fastBridgeSender, "OutgoingMessage");
359356

360357
console.log("Executed ruling");
361358

362359
const ticket2 = await fastBridgeSender.currentTicketID();
363-
expect(ticket2).to.equal(3);
360+
expect(ticket2).to.equal(2);
364361
const eventFilter = fastBridgeSender.filters.OutgoingMessage();
365362
const event5 = await fastBridgeSender.queryFilter(eventFilter, "latest");
366363
const event6 = await ethers.provider.getLogs(eventFilter);
@@ -379,7 +376,7 @@ describe("Demo pre-alpha1", function () {
379376
expect(messageHash).to.equal(expectedHash);
380377

381378
const currentID = await fastBridgeSender.currentTicketID();
382-
expect(currentID).to.equal(3);
379+
expect(currentID).to.equal(2);
383380

384381
// bridger tx starts
385382
const tx5 = await fastBridgeReceiver.connect(bridger).claim(ticketID, messageHash, { value: ONE_TENTH_ETH });
@@ -416,10 +413,7 @@ describe("Demo pre-alpha1", function () {
416413
);
417414
});
418415

419-
it.skip("Demo - Dishonest Claim - Challenged - Bridger deposit forfeited, Challenger paid", async () => {
420-
421-
// TODO: FIX ME !
422-
416+
it("Demo - Dishonest Claim - Challenged - Bridger deposit forfeited, Challenger paid", async () => {
423417
const arbitrationCost = ONE_TENTH_ETH.mul(3);
424418
const [bridger, challenger] = await ethers.getSigners();
425419

@@ -519,7 +513,7 @@ describe("Demo pre-alpha1", function () {
519513
expect((await core.disputes(coreId)).period).to.equal(Period.execution);
520514
await core.execute(coreId, 0, 1000);
521515
const ticket1 = await fastBridgeSender.currentTicketID();
522-
expect(ticket1).to.equal(3);
516+
expect(ticket1).to.equal(1);
523517

524518
const tx4 = await core.executeRuling(coreId);
525519

@@ -528,7 +522,7 @@ describe("Demo pre-alpha1", function () {
528522
console.log("Executed ruling");
529523

530524
const ticket2 = await fastBridgeSender.currentTicketID();
531-
expect(ticket2).to.equal(4);
525+
expect(ticket2).to.equal(2);
532526
const eventFilter = fastBridgeSender.filters.OutgoingMessage();
533527
const event5 = await fastBridgeSender.queryFilter(eventFilter, "latest");
534528
const event6 = await ethers.provider.getLogs(eventFilter);
@@ -547,7 +541,7 @@ describe("Demo pre-alpha1", function () {
547541
expect(messageHash).to.equal(expectedHash);
548542

549543
const currentID = await fastBridgeSender.currentTicketID();
550-
expect(currentID).to.equal(4);
544+
expect(currentID).to.equal(2);
551545

552546
// bridger tx starts - bridger creates fakeData & fakeHash for dishonest ruling
553547
const fakeData = "0x0000000000000000000000009a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000643496987923bd6a8aa2bdce6c5b15551665079e7acfb1b4d2149ac7e2f72260417d541b7f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c800000000000000000000000000000000000000000000000000000000";

contracts/test/rng/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ describe("ConstantNG", function () {
1818
describe("IncrementalNG", function () {
1919
it("Should return a number incrementing each time", async function () {
2020
const IncrementalNG = await ethers.getContractFactory("IncrementalNG");
21-
const incrementalNG = await IncrementalNG.deploy();
21+
const initialNg = 424242;
22+
const incrementalNG = await IncrementalNG.deploy(initialNg);
2223
await incrementalNG.deployed();
2324

24-
expect(await incrementalNG.callStatic.getRN(689376)).to.equal(0);
25+
expect(await incrementalNG.callStatic.getRN(689376)).to.equal(initialNg);
2526
await incrementalNG.getRN(29543);
26-
expect(await incrementalNG.callStatic.getRN(5894382)).to.equal(1);
27+
expect(await incrementalNG.callStatic.getRN(5894382)).to.equal(initialNg + 1);
2728
await incrementalNG.getRN(0);
28-
expect(await incrementalNG.callStatic.getRN(3465)).to.equal(2);
29+
expect(await incrementalNG.callStatic.getRN(3465)).to.equal(initialNg + 2);
2930
await incrementalNG.getRN(BigNumber.from(2).pow(255));
30-
expect(await incrementalNG.callStatic.getRN(0)).to.equal(3);
31+
expect(await incrementalNG.callStatic.getRN(0)).to.equal(initialNg + 3);
3132
});
3233
});

0 commit comments

Comments
 (0)