Skip to content

Commit 9f8c334

Browse files
ShasShas
authored andcommitted
feat: test subnet governance
1 parent cb4fa66 commit 9f8c334

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/SubnetManager.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ contract SubnetManager is ISubnetManager, ERC721Upgradeable, Ownable2StepUpgrade
606606
emit SubnetFeeBurnRateUpdated(newBurnRate);
607607
}
608608

609+
/// @inheritdoc ISubnetManager
610+
function getSubnetFeeBurnRate() public view returns (uint8) {
611+
return subnetFeeBurnRate;
612+
}
613+
609614
/// @inheritdoc ISubnetManager
610615
function setPerformancePoolShare(uint8 newShare) public onlyRole(SUBNET_ADMIN_ROLE) {
611616
if (newShare > 50) {
@@ -615,6 +620,11 @@ contract SubnetManager is ISubnetManager, ERC721Upgradeable, Ownable2StepUpgrade
615620
emit PerformancePoolShareUpdated(newShare);
616621
}
617622

623+
/// @inheritdoc ISubnetManager
624+
function getPerformancePoolShare() public view returns (uint8) {
625+
return performancePoolShare;
626+
}
627+
618628
/// @inheritdoc ISubnetManager
619629
function subnetOwner(uint256 subnetId) public view returns (address) {
620630
return ownerOf(subnetId);

src/interfaces/ISubnetManager.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,18 @@ interface ISubnetManager {
466466
/// @param newBurnRate New subnet fee burn rate (percentage)
467467
function setSubnetFeeBurnRate(uint8 newBurnRate) external;
468468

469+
/// @notice Gets the subnet fee burn rate
470+
/// @return Subnet fee burn rate (percentage)
471+
function getSubnetFeeBurnRate() external view returns (uint8);
472+
469473
/// @notice Sets the performance pool share for a subnet
470474
/// @param newShare New performance pool share
471475
function setPerformancePoolShare(uint8 newShare) external;
472476

477+
/// @notice Gets the performance pool share for a subnet
478+
/// @return Performance pool share
479+
function getPerformancePoolShare() external view returns (uint8);
480+
473481
/// @notice Deletes a subnet
474482
/// @param subnetId ID of the subnet to delete
475483
function deleteSubnet(uint256 subnetId) external;

test/PodManagerV2/PodManagerV2.Base.t.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ contract SubnetManagerMock is ISubnetManager {
432432
function getSeederFeeShare(
433433
uint256 subnetId
434434
) external view override returns (uint8) {}
435+
436+
function getSubnetFeeBurnRate() external view override returns (uint8) {}
437+
438+
function getPerformancePoolShare() external view override returns (uint8) {}
435439
}
436440

437441
abstract contract PodManagerV2TestBase is Test {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.29;
3+
4+
import {SubnetManagerTestBase} from "./SubnetManager.Base.t.sol";
5+
6+
contract SubnetManagerSubnetGovernanceTest is SubnetManagerTestBase {
7+
8+
function test_governanceAdminCanChangeTaxRate() public {
9+
uint8 newTaxRate = 15;
10+
vm.startPrank(admin);
11+
subnetManager.setTaxRate(newTaxRate);
12+
vm.stopPrank();
13+
uint8 currentTaxRate = subnetManager.getTaxRate();
14+
assertEq(currentTaxRate, newTaxRate, "Tax rate should be updated by admin");
15+
}
16+
17+
function testRevert_nonAdminCannotChangeTaxRate() public {
18+
vm.startPrank(user1);
19+
vm.expectRevert(abi.encodeWithSignature("AccessControlUnauthorizedAccount(address,bytes32)", user1, keccak256("SUBNET_ADMIN_ROLE")));
20+
subnetManager.setTaxRate(20);
21+
vm.stopPrank();
22+
}
23+
24+
function test_governanceAdminCanChangeSubnetFeeBurnRate() public {
25+
uint8 newBurnRate = 5;
26+
vm.startPrank(admin);
27+
subnetManager.setSubnetFeeBurnRate(newBurnRate);
28+
vm.stopPrank();
29+
uint8 currentBurnRate = subnetManager.getSubnetFeeBurnRate();
30+
assertEq(currentBurnRate, newBurnRate, "Subnet fee burn rate should be updated by admin");
31+
}
32+
33+
function testRevert_nonAdminCannotChangeSubnetFeeBurnRate() public {
34+
vm.startPrank(user1);
35+
vm.expectRevert(abi.encodeWithSignature("AccessControlUnauthorizedAccount(address,bytes32)", user1, keccak256("SUBNET_ADMIN_ROLE")));
36+
subnetManager.setSubnetFeeBurnRate(10);
37+
vm.stopPrank();
38+
}
39+
40+
function test_governaceCanChangePerformancePoolShare() public {
41+
uint8 newShare = 25;
42+
vm.startPrank(admin);
43+
subnetManager.setPerformancePoolShare(newShare);
44+
vm.stopPrank();
45+
uint8 currentShare = subnetManager.getPerformancePoolShare();
46+
assertEq(currentShare, newShare, "Performance pool share should be updated by admin");
47+
}
48+
49+
function testRevert_nonAdminCannotChangePerformancePoolShare() public {
50+
vm.startPrank(user1);
51+
vm.expectRevert(abi.encodeWithSignature("AccessControlUnauthorizedAccount(address,bytes32)", user1, keccak256("SUBNET_ADMIN_ROLE")));
52+
subnetManager.setPerformancePoolShare(30);
53+
vm.stopPrank();
54+
}
55+
}

0 commit comments

Comments
 (0)