From d99b54b60bd356b548aa8d53744294ad982fb612 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Thu, 27 Feb 2025 15:18:14 +0100 Subject: [PATCH 01/13] added the Access control for incentives pool storage test --- test/integration/Paranet.test.ts | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index f605ed99..caece3d9 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -900,6 +900,61 @@ describe('@unit Paranet', () => { expect(await incentivesPoolStorage.paranetId()).to.equal(paranetId); }); + it('Access control for incentives pool storage', async () => { + const kcCreator = getDefaultKCCreator(accounts); + const publishingNode = getDefaultPublishingNode(accounts); + const receivingNodes = getDefaultReceivingNodes(accounts); + + const { + paranetKCStorageContract, + paranetKCTokenId, + paranetKATokenId, + paranetOwner, + } = await setupParanet(kcCreator, publishingNode, receivingNodes, { + Paranet, + Profile, + Token, + KnowledgeCollection, + KnowledgeCollectionStorage, + }); + + const tx = await ParanetIncentivesPoolFactory.connect( + paranetOwner, + ).deployIncentivesPool( + paranetKCStorageContract, + paranetKCTokenId, + paranetKATokenId, + ethers.parseUnits('1', 12), // 1 NEURO per 1 TRAC + 1000, // 10% operator + 2000, // 20% voters + 'Pool', + await Token.getAddress(), + ); + + const receipt = await tx.wait(); + const event = receipt!.logs.find( + (log) => + log.topics[0] === + ParanetIncentivesPoolFactory.interface.getEvent( + 'ParanetIncentivesPoolDeployed', + ).topicHash, + ) as EventLog; + + const poolStorage = await hre.ethers.getContractAt( + 'ParanetIncentivesPoolStorage', + event?.args[3], + ); + + await expect( + poolStorage + .connect(accounts[1]) + .addMinerClaimedRewardProfile( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + }); + it('Should handle multiple incentives pools for same paranet', async () => { // 1. Setup paranet first const kcCreator = getDefaultKCCreator(accounts); From 06c28badf6f36d0b2cbecb3f28cee37b6c43aef5 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Thu, 27 Feb 2025 15:18:14 +0100 Subject: [PATCH 02/13] added the Access control for incentives pool storage test --- test/integration/Paranet.test.ts | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index f605ed99..dfcda33b 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -900,6 +900,61 @@ describe('@unit Paranet', () => { expect(await incentivesPoolStorage.paranetId()).to.equal(paranetId); }); + it('Access control for incentives pool storage', async () => { + const kcCreator = getDefaultKCCreator(accounts); + const publishingNode = getDefaultPublishingNode(accounts); + const receivingNodes = getDefaultReceivingNodes(accounts); + + const { + paranetKCStorageContract, + paranetKCTokenId, + paranetKATokenId, + paranetOwner, + } = await setupParanet(kcCreator, publishingNode, receivingNodes, { + Paranet, + Profile, + Token, + KnowledgeCollection, + KnowledgeCollectionStorage, + }); + + const tx = await ParanetIncentivesPoolFactory.connect( + paranetOwner, + ).deployIncentivesPool( + paranetKCStorageContract, + paranetKCTokenId, + paranetKATokenId, + ethers.parseUnits('1', 12), // 1 NEURO per 1 TRAC + 1000, // 10% operator + 2000, // 20% voters + 'Pool', + await Token.getAddress(), + ); + + const receipt = await tx.wait(); + const event = receipt!.logs.find( + (log) => + log.topics[0] === + ParanetIncentivesPoolFactory.interface.getEvent( + 'ParanetIncentivesPoolDeployed', + ).topicHash, + ) as EventLog; + + const poolStorage = await hre.ethers.getContractAt( + 'ParanetIncentivesPoolStorage', + event?.args[3], + ); + + await expect( + poolStorage + .connect(accounts[1]) + .addMinerClaimedReward( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + }); + it('Should handle multiple incentives pools for same paranet', async () => { // 1. Setup paranet first const kcCreator = getDefaultKCCreator(accounts); From 438521ab9a630a0626209aee51b2ec95ef1c3e6c Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 10:08:48 +0100 Subject: [PATCH 03/13] added other Reward functions tests --- test/integration/Paranet.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index dfcda33b..b8cd7111 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -953,6 +953,33 @@ describe('@unit Paranet', () => { ethers.parseUnits('100', 12), ) ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .addMinerClaimedRewardProfile( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .addClaimedOperatorReward( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .addOperatorClaimedRewardsProfile( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); }); it('Should handle multiple incentives pools for same paranet', async () => { From 3844af11bb083f0e1af34fb23717952495471f14 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 10:41:37 +0100 Subject: [PATCH 04/13] added Voter batch too large case --- test/integration/Paranet.test.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index b8cd7111..a52bf6d0 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1290,14 +1290,27 @@ describe('@unit Paranet', () => { expect(voterReward).to.be.eq(0); // storage contract was not funded // Verify voter weight affects reward calculation - const voter = await incentivesPoolStorage.getVoter(accounts[5].address); - const voterShare = (voterReward * BigInt(voter.weight)) / BigInt(10000); + const voter = await incentivesPoolStorage.getVoter(accounts[5].address); const voterShare = (voterReward * BigInt(voter.weight)) / BigInt(10000); const claimableVoterReward = await incentivesPool .connect(accounts[5]) .getClaimableProposalVoterRewardAmount(); expect(claimableVoterReward).to.equal(voterShare); - // Transfer registrar role to new address + // Verfiy batch is too large + const votersBachTooLarge = Array.from({ length: 101 }, (_, index) => ({ + addr: accounts[index % accounts.length].address, // Wrap around if index exceeds accounts.length + weight: 1000 // Fixed weight for all entries (or adjust as needed) + })); + + console.log("VotersBatch size is :", votersBachTooLarge.length); + + await expect( + incentivesPoolStorage + .connect(registrarSigner) + .addVoters(votersBachTooLarge), + ).to.be.revertedWith('Batch too large'); + + // Transfer registrar role to new address await expect( incentivesPoolStorage .connect(registrarSigner) @@ -1317,6 +1330,7 @@ describe('@unit Paranet', () => { .connect(accounts[6]) .transferVotersRegistrarRole(ethers.ZeroAddress), ).to.be.revertedWith('New registrar cannot be zero address'); + }); it('Should handle incentives pool redeployment', async () => { From d8882cd899aaa3eb81f82d98f34e16f47bea8ac8 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 10:52:28 +0100 Subject: [PATCH 05/13] added Voter already exists case --- test/integration/Paranet.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index a52bf6d0..2a50100c 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1230,6 +1230,11 @@ describe('@unit Paranet', () => { 10000, ); + // Try to add voter for the second time + await expect( + incentivesPoolStorage.connect(registrarSigner).addVoters(voters) + ).to.be.revertedWith('Voter already exists'); + // Now voter exists but hasn't claimed anything yet expect( await incentivesPool.voterclaimedToken(accounts[5].address), @@ -1302,8 +1307,6 @@ describe('@unit Paranet', () => { weight: 1000 // Fixed weight for all entries (or adjust as needed) })); - console.log("VotersBatch size is :", votersBachTooLarge.length); - await expect( incentivesPoolStorage .connect(registrarSigner) From e0a92ecd61d72d0ad655ae377ad3f2c7005b6012 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:24:46 +0100 Subject: [PATCH 06/13] added Voter index out of bounds case --- test/integration/Paranet.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index 2a50100c..afd84aa7 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1266,6 +1266,13 @@ describe('@unit Paranet', () => { 6000, ); + // Try to get a non existing voter + await expect( + incentivesPoolStorage + .connect(registrarSigner) + .getVoterAtIndex(105), + ).to.be.revertedWith('Index is out of bounds'); + // Try to add voter that would exceed max weight const overweightVoter = [{ addr: accounts[8].address, weight: 5000 }]; await expect( From 31f13978eb0418daf34f1eca0b5e6081afcb14b6 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:29:04 +0100 Subject: [PATCH 07/13] added VoterclaimedToken case --- test/integration/Paranet.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index b8cd7111..b95f57c2 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -980,6 +980,18 @@ describe('@unit Paranet', () => { ethers.parseUnits('100', 12), ) ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .addVoterclaimedToken( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + + }); it('Should handle multiple incentives pools for same paranet', async () => { From 45ff1f4ad9584b996f2a8389b20d0abbd06d42ae Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:36:00 +0100 Subject: [PATCH 08/13] added addTotal...claimedToken cases --- test/integration/Paranet.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index b95f57c2..6c84ae87 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -990,7 +990,29 @@ describe('@unit Paranet', () => { ) ).to.be.revertedWith('Caller is not incentives pool contract'); + await expect( + poolStorage + .connect(accounts[1]) + .addTotalMinersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + await expect( + poolStorage + .connect(accounts[1]) + .addTotalOperatorsclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .addTotalVotersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); }); From 902a22db009a5654e9f60488758f2050853f49f1 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:37:16 +0100 Subject: [PATCH 09/13] added transferReward case --- test/integration/Paranet.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index 6c84ae87..0988ddd1 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1014,6 +1014,15 @@ describe('@unit Paranet', () => { ) ).to.be.revertedWith('Caller is not incentives pool contract'); + await expect( + poolStorage + .connect(accounts[1]) + .transferReward( + accounts[0].address, + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + }); it('Should handle multiple incentives pools for same paranet', async () => { From 03e9451e77deed4b8199f0e26221445b26c6bf6a Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:40:53 +0100 Subject: [PATCH 10/13] added setTotal...claimedToken cases --- test/integration/Paranet.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index 0988ddd1..92a9517b 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1023,6 +1023,30 @@ describe('@unit Paranet', () => { ) ).to.be.revertedWith('Caller is not incentives pool contract'); + await expect( + poolStorage + .connect(accounts[1]) + .setTotalMinersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .setTotalVotersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .setTotalOperatorsclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + }); it('Should handle multiple incentives pools for same paranet', async () => { From 1e5b78872bdb016176966ae72d7c42cae531986c Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:44:21 +0100 Subject: [PATCH 11/13] added decrementTotal...claimedToken cases --- test/integration/Paranet.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index 92a9517b..bbd240e4 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -1047,6 +1047,31 @@ describe('@unit Paranet', () => { ) ).to.be.revertedWith('Caller is not incentives pool contract'); + await expect( + poolStorage + .connect(accounts[1]) + .decrementTotalMinersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .decrementTotalVotersclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + await expect( + poolStorage + .connect(accounts[1]) + .decrementTotalOperatorsclaimedToken( + ethers.parseUnits('100', 12), + ) + ).to.be.revertedWith('Caller is not incentives pool contract'); + + }); it('Should handle multiple incentives pools for same paranet', async () => { From 90ea13a58f852e5896f255a4f472145f33e1e1c9 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 11:59:24 +0100 Subject: [PATCH 12/13] added clarification for address being non incetives pool --- test/integration/Paranet.test.ts | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index bbd240e4..49c94fab 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -945,9 +945,11 @@ describe('@unit Paranet', () => { event?.args[3], ); + const notIncentivesPool = accounts[1]; + await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addMinerClaimedReward( accounts[0].address, ethers.parseUnits('100', 12), @@ -956,7 +958,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addMinerClaimedRewardProfile( accounts[0].address, ethers.parseUnits('100', 12), @@ -965,7 +967,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addClaimedOperatorReward( accounts[0].address, ethers.parseUnits('100', 12), @@ -974,7 +976,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addOperatorClaimedRewardsProfile( accounts[0].address, ethers.parseUnits('100', 12), @@ -983,7 +985,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addVoterclaimedToken( accounts[0].address, ethers.parseUnits('100', 12), @@ -992,7 +994,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addTotalMinersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1000,7 +1002,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addTotalOperatorsclaimedToken( ethers.parseUnits('100', 12), ) @@ -1008,7 +1010,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .addTotalVotersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1016,7 +1018,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .transferReward( accounts[0].address, ethers.parseUnits('100', 12), @@ -1025,7 +1027,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .setTotalMinersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1033,7 +1035,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .setTotalVotersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1041,7 +1043,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .setTotalOperatorsclaimedToken( ethers.parseUnits('100', 12), ) @@ -1049,7 +1051,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .decrementTotalMinersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1057,7 +1059,7 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .decrementTotalVotersclaimedToken( ethers.parseUnits('100', 12), ) @@ -1065,13 +1067,12 @@ describe('@unit Paranet', () => { await expect( poolStorage - .connect(accounts[1]) + .connect(notIncentivesPool) .decrementTotalOperatorsclaimedToken( ethers.parseUnits('100', 12), ) ).to.be.revertedWith('Caller is not incentives pool contract'); - }); it('Should handle multiple incentives pools for same paranet', async () => { From 26544760c5d6b4ba3c7aed25b006da3c745ddef5 Mon Sep 17 00:00:00 2001 From: Marko Kostic Date: Fri, 28 Feb 2025 15:21:04 +0100 Subject: [PATCH 13/13] typo fix --- test/integration/Paranet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/Paranet.test.ts b/test/integration/Paranet.test.ts index 39a1faa9..7cf506ea 100644 --- a/test/integration/Paranet.test.ts +++ b/test/integration/Paranet.test.ts @@ -986,7 +986,7 @@ describe('@unit Paranet', () => { await expect( poolStorage .connect(notIncentivesPool) - .addVoterclaimedToken( + .addVoterClaimedToken( accounts[0].address, ethers.parseUnits('100', 12), )