Skip to content

Commit

Permalink
chore: test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SamAg19 committed Sep 11, 2024
1 parent 1e16edf commit 35eef53
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
3 changes: 1 addition & 2 deletions scenarios/scenarios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {
getState, adhocCommit, adhocReveal, getData, adhocPropose,
} = require('../test/helpers/utils');
const { assert } = require('chai');
const { mineBlock } = require('../test/helpers/testHelpers');
const {
COLLECTION_MODIFIER_ROLE,
Expand Down Expand Up @@ -910,7 +911,6 @@ describe('Scenarios', async () => {
const median = await calculateDisputesData(medianIndex,
voteManager,
stakeManager,
collectionManager,
epoch);
helper[medianIndex] = median.median;
}
Expand Down Expand Up @@ -974,7 +974,6 @@ describe('Scenarios', async () => {
} = await calculateDisputesData(validActiveCollectionIndexToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
await blockManager.connect(signers[4]).giveSorted(epoch, validActiveCollectionIndexToBeDisputed, sortedValues);

Expand Down
17 changes: 15 additions & 2 deletions test/AssignCollectionsRandomly.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ describe('AssignCollectionsRandomly', function () {
}
}

console.log('Jobs Created');

await collectionManager.createCollection(500, 3, 1, [1, 2, 3], 'c0');
await collectionManager.createCollection(500, 3, 1, [1, 2, 3], 'c1');
await collectionManager.createCollection(500, 3, 1, [1, 2, 3], 'c2');
Expand All @@ -95,6 +97,8 @@ describe('AssignCollectionsRandomly', function () {
await collectionManager.createCollection(500, 3, 1, [1, 2, 3], 'c5');
await collectionManager.createCollection(500, 3, 1, [1, 2, 3], 'c6');

console.log('Collections Created');

await mineToNextEpoch();

await razor.transfer(signers[1].address, tokenAmount('100000'));
Expand All @@ -110,17 +114,22 @@ describe('AssignCollectionsRandomly', function () {
await stakeManager.connect(signers[2]).stake(epoch, tokenAmount('100000'));
await stakeManager.connect(signers[3]).stake(epoch, tokenAmount('100000'));

console.log('Staked');

await mineToNextEpoch();
epoch = await getEpoch();
const secret = await getSecret(signers[1]);
await reset();
await commit(signers[1], 0, voteManager, collectionManager, secret, blockManager);
console.log('Committed');
await mineToNextState();

await reveal(signers[1], 0, voteManager, stakeManager);
console.log('Revealed');
await mineToNextState();

await propose(signers[1], stakeManager, blockManager, voteManager, collectionManager);
console.log('Proposed');

// Block Proposed

Expand All @@ -130,17 +139,22 @@ describe('AssignCollectionsRandomly', function () {
// as a staker, you have to pass sorted values
const data = await getData(signers[1]);
const validLeafIdToBeDisputed = (data.seqAllotedCollections)[0];
console.log(data.seqAllotedCollections)
console.log('Data Fetched');
const {
sortedValues,
} = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
console.log('Dispute Data Calculated');
await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues);
console.log('give sorted called');
const collectionIndexInBlock = await getCollectionIdPositionInBlock(epoch, await blockManager.sortedProposedBlockIds(epoch, 0),
signers[19], blockManager, collectionManager);

await assertRevert(blockManager.connect(signers[19]).finalizeDispute(epoch, 0, collectionIndexInBlock), 'Block proposed with same medians');
console.log('Finalize Dispute called');

await mineToNextState();

Expand Down Expand Up @@ -194,7 +208,6 @@ describe('AssignCollectionsRandomly', function () {
} = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues);
let collectionIndexInBlock = await getCollectionIdPositionInBlock(epoch, await blockManager.sortedProposedBlockIds(epoch, 0),
Expand Down
7 changes: 1 addition & 6 deletions test/BlockManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
mineToNextState,
assertRevert,
} = require('./helpers/testHelpers');
const { assert, expect } = require('chai');
const { setupContracts } = require('./helpers/testSetup');
const {
DEFAULT_ADMIN_ROLE_HASH,
Expand Down Expand Up @@ -278,7 +279,6 @@ describe('BlockManager', function () {
} = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues);
const numActiveCollections = await collectionManager.getNumActiveCollections();
Expand Down Expand Up @@ -409,7 +409,6 @@ describe('BlockManager', function () {
const res1 = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, res1.sortedValues);
const firstDispute = await blockManager.disputes(epoch, signers[19].address);
Expand All @@ -428,7 +427,6 @@ describe('BlockManager', function () {
const res2 = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);

await blockManager.connect(signers[15]).giveSorted(epoch, validLeafIdToBeDisputed, res2.sortedValues);
Expand Down Expand Up @@ -574,7 +572,6 @@ describe('BlockManager', function () {
} = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);

// Dispute in batches
Expand Down Expand Up @@ -795,7 +792,6 @@ describe('BlockManager', function () {
const res1 = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);
await blockManager.connect(signers[10]).giveSorted(epoch, validLeafIdToBeDisputed, res1.sortedValues);

Expand Down Expand Up @@ -1349,7 +1345,6 @@ describe('BlockManager', function () {
const res = await calculateDisputesData(validLeafIdToBeDisputed,
voteManager,
stakeManager,
collectionManager,
epoch);

await blockManager.giveSorted(epoch, validLeafIdToBeDisputed, res.sortedValues);
Expand Down
3 changes: 2 additions & 1 deletion test/RandomNoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
assertRevert,
assertBNNotEqual,
} = require('./helpers/testHelpers');
const { assert } = require('chai');
const { commit, reveal, propose } = require('./helpers/InternalEngine');
const { setupContracts } = require('./helpers/testSetup');
const {
Expand Down Expand Up @@ -166,7 +167,7 @@ describe('RandomNoManager', function () {
// Get Random no : Generic From Epoch
const randomNo3 = await randomNoManager.getGenericRandomNumber(epoch);
const seed3 = await randomNoManager.secrets(epoch);
const salt3 = 0;
const salt3 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const locallyCalculatedRandomNo3 = await prngHash(seed3, salt3);
assertBNEqual(randomNo3, toBigNumber(locallyCalculatedRandomNo3));
assertBNNotEqual(randomNo3, randomNo);
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,12 @@ const adhocPropose = async (signer, ids, medians, stakeManager, blockManager, vo
biggestStakerId);
};

const getCollectionIdPositionInBlock = async (epoch, blockId, signer, blockManager) => {
const getCollectionIdPositionInBlock = async (epoch, blockId, signer, blockManager, collectionManager) => {
const { ids } = await blockManager.getProposedBlock(epoch, blockId);
// console.log(ids);
const dispute = await blockManager.disputes(epoch, signer.address);
const { collectionId } = dispute;
const { leafId } = dispute;
const collectionId = await collectionManager.getCollectionIdFromLeafId(leafId);
let collectionIndexInBlock = 0;
for (let i = 0; i < ids.length; i++) {
if (ids[i] === collectionId) { collectionIndexInBlock = i; break; }
Expand Down

0 comments on commit 35eef53

Please sign in to comment.