Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions test/Redistribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
const height_0_n_2 = 2;

//fake
const overlay_f = '0xf4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f415';

Check warning on line 68 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'overlay_f' is assigned a value but never used
const depth_f = '0x0000000000000000000000000000000000000000000000000000000000000007';
const reveal_nonce_f = '0xf4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f415';

Expand Down Expand Up @@ -118,12 +118,12 @@
const { depth: depth_5, hash: hash_5 } = node5_proof1;
const height_5 = 0;

let node_6: string;

Check warning on line 121 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'node_6' is assigned a value but never used
const overlay_6 = '0x141680b0d9c7ab250672fd4603ac13e39e47de6e2c93d71bbdc66459a6c5e39f';

Check warning on line 122 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'overlay_6' is assigned a value but never used
const stakeAmount_6 = '100000000000000000';

Check warning on line 123 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'stakeAmount_6' is assigned a value but never used

const nonce_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';

Check warning on line 125 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'nonce_6' is assigned a value but never used
const hash_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';

Check warning on line 126 in test/Redistribution.test.ts

View workflow job for this annotation

GitHub Actions / Check Code Quality & Run Tests

'hash_6' is assigned a value but never used
const depth_6 = '0x06';
const reveal_nonce_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';

Expand Down Expand Up @@ -1427,8 +1427,13 @@

await mineNBlocks(phaseLength);

expect(await r_node_1.isWinner(overlay_1_n_25)).to.be.false;
expect(await r_node_5.isWinner(overlay_5)).to.be.true;
// Equal-stake lottery: exactly one of the two truth-tellers is the winner.
const node1Wins = await r_node_1.isWinner(overlay_1_n_25);
const node5Wins = await r_node_5.isWinner(overlay_5);
expect(node1Wins).to.not.eq(node5Wins);

const winnerOwner = node5Wins ? node_5 : node_1;
const winnerOverlay = node5Wins ? overlay_5 : overlay_1_n_25;

const tx2 = await r_node_5.claim(proof1, proof2, proofLast);
const receipt2 = await tx2.wait();
Expand All @@ -1453,16 +1458,15 @@
(receipt2.blockNumber - copyBatch.tx.blockNumber) * price1 * 2 ** copyBatch.postageDepth +
(receipt2.blockNumber - stampCreatedBlock) * price1 * 2 ** batch.depth; // batch in the beforeHook

expect(await token.balanceOf(node_5)).to.be.eq(expectedPotPayout);
expect(await token.balanceOf(winnerOwner)).to.be.eq(expectedPotPayout);

expect(CountCommitsEvent.args[0]).to.be.eq(2);
expect(CountRevealsEvent.args[0]).to.be.eq(2);

expect(WinnerSelectedEvent.args[0].owner).to.be.eq(node_5);
expect(WinnerSelectedEvent.args[0].overlay).to.be.eq(overlay_5);
expect(WinnerSelectedEvent.args[0].stake).to.be.eq(effectiveStakeAmount_5);
expect(WinnerSelectedEvent.args[0].owner).to.be.eq(winnerOwner);
expect(WinnerSelectedEvent.args[0].overlay).to.be.eq(winnerOverlay);
expect(WinnerSelectedEvent.args[0].stakeDensity).to.be.eq(
calculateStakeDensity(effectiveStakeAmount_5, Number(depth_5))
calculateStakeDensity(WinnerSelectedEvent.args[0].stake.toString(), Number(depth_5))
);
expect(WinnerSelectedEvent.args[0].hash).to.be.eq(hash_5);
expect(WinnerSelectedEvent.args[0].depth).to.be.eq(parseInt(depth_5));
Expand Down Expand Up @@ -1495,13 +1499,16 @@

await mineNBlocks(phaseLength);

const node5Wins = await r_node_5.isWinner(overlay_5);
const winnerOwner = node5Wins ? node_5 : node_1;

const tx2 = await r_node_5.claim(proof1, proof2, proofLast);
const receipt2 = await tx2.wait();

const expectedPotPayout =
(receipt2.blockNumber - copyBatch.tx.blockNumber) * price1 * 2 ** copyBatch.postageDepth +
(receipt2.blockNumber - stampCreatedBlock) * price1 * 2 ** batch.depth; // batch in the beforeHook
expect(await token.balanceOf(node_5)).to.be.eq(expectedPotPayout);
expect(await token.balanceOf(winnerOwner)).to.be.eq(expectedPotPayout);

const sr = await ethers.getContract('StakeRegistry');

Expand Down
Loading