From 35eef5355e871f4eed759353c26dd1be57a24c6a Mon Sep 17 00:00:00 2001 From: SamAg19 Date: Wed, 11 Sep 2024 16:15:36 +0530 Subject: [PATCH] chore: test fixes --- scenarios/scenarios.js | 3 +-- test/AssignCollectionsRandomly.js | 17 +++++++++++++++-- test/BlockManager.js | 7 +------ test/RandomNoManager.js | 3 ++- test/helpers/utils.js | 5 +++-- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scenarios/scenarios.js b/scenarios/scenarios.js index bd5a20f3..17413ed1 100644 --- a/scenarios/scenarios.js +++ b/scenarios/scenarios.js @@ -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, @@ -910,7 +911,6 @@ describe('Scenarios', async () => { const median = await calculateDisputesData(medianIndex, voteManager, stakeManager, - collectionManager, epoch); helper[medianIndex] = median.median; } @@ -974,7 +974,6 @@ describe('Scenarios', async () => { } = await calculateDisputesData(validActiveCollectionIndexToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[4]).giveSorted(epoch, validActiveCollectionIndexToBeDisputed, sortedValues); diff --git a/test/AssignCollectionsRandomly.js b/test/AssignCollectionsRandomly.js index 55b64a47..07a2c641 100644 --- a/test/AssignCollectionsRandomly.js +++ b/test/AssignCollectionsRandomly.js @@ -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'); @@ -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')); @@ -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 @@ -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(); @@ -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), diff --git a/test/BlockManager.js b/test/BlockManager.js index 84d9c663..33522bc5 100644 --- a/test/BlockManager.js +++ b/test/BlockManager.js @@ -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, @@ -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(); @@ -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); @@ -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); @@ -574,7 +572,6 @@ describe('BlockManager', function () { } = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); // Dispute in batches @@ -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); @@ -1349,7 +1345,6 @@ describe('BlockManager', function () { const res = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.giveSorted(epoch, validLeafIdToBeDisputed, res.sortedValues); diff --git a/test/RandomNoManager.js b/test/RandomNoManager.js index f2203f00..cbe6cfd9 100644 --- a/test/RandomNoManager.js +++ b/test/RandomNoManager.js @@ -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 { @@ -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); diff --git a/test/helpers/utils.js b/test/helpers/utils.js index ce4f9d47..6adcecab 100644 --- a/test/helpers/utils.js +++ b/test/helpers/utils.js @@ -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; }