Skip to content

Commit

Permalink
refactor(DiamondTestSetup): rename IAccessControl to accessControlFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu authored and molecula451 committed Oct 7, 2023
1 parent 8dbc683 commit edf5f53
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 78 deletions.
36 changes: 27 additions & 9 deletions packages/contracts/test/diamond/DiamondTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract contract DiamondTestSetup is DiamondTestHelper {
DiamondInit diamondInit;

// diamond facets (which point to the core diamond and should be used across the tests)
AccessControlFacet IAccessControl;
AccessControlFacet accessControlFacet;
BondingCurveFacet bondingCurveFacet;
ChefFacet chefFacet;
CollectableDustFacet collectableDustFacet;
Expand Down Expand Up @@ -761,7 +761,7 @@ abstract contract DiamondTestSetup is DiamondTestHelper {
diamond = new Diamond(_args, cuts);

// initialize diamond facets which point to the core diamond contract
IAccessControl = AccessControlFacet(address(diamond));
accessControlFacet = AccessControlFacet(address(diamond));
bondingCurveFacet = BondingCurveFacet(address(diamond));
chefFacet = ChefFacet(address(diamond));
collectableDustFacet = CollectableDustFacet(address(diamond));
Expand Down Expand Up @@ -790,20 +790,38 @@ abstract contract DiamondTestSetup is DiamondTestHelper {
facetAddressList = diamondLoupeFacet.facetAddresses();
vm.startPrank(admin);
// grant diamond dollar minting and burning rights
IAccessControl.grantRole(CURVE_DOLLAR_MANAGER_ROLE, address(diamond));
accessControlFacet.grantRole(
CURVE_DOLLAR_MANAGER_ROLE,
address(diamond)
);
// grant diamond dollar minting and burning rights
IAccessControl.grantRole(DOLLAR_TOKEN_MINTER_ROLE, address(diamond));
IAccessControl.grantRole(DOLLAR_TOKEN_BURNER_ROLE, address(diamond));
accessControlFacet.grantRole(
DOLLAR_TOKEN_MINTER_ROLE,
address(diamond)
);
accessControlFacet.grantRole(
DOLLAR_TOKEN_BURNER_ROLE,
address(diamond)
);
// grand diamond Credit token minting and burning rights
IAccessControl.grantRole(CREDIT_TOKEN_MINTER_ROLE, address(diamond));
IAccessControl.grantRole(CREDIT_TOKEN_BURNER_ROLE, address(diamond));
accessControlFacet.grantRole(
CREDIT_TOKEN_MINTER_ROLE,
address(diamond)
);
accessControlFacet.grantRole(
CREDIT_TOKEN_BURNER_ROLE,
address(diamond)
);
// grant diamond token admin rights
IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MANAGER_ROLE,
address(diamond)
);
// grant diamond token minter rights
IAccessControl.grantRole(STAKING_SHARE_MINTER_ROLE, address(diamond));
accessControlFacet.grantRole(
STAKING_SHARE_MINTER_ROLE,
address(diamond)
);
// init UUPS core contracts
__setupUUPS(address(diamond));
vm.stopPrank();
Expand Down
18 changes: 12 additions & 6 deletions packages/contracts/test/diamond/ERC20UbiquityDollarTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ contract ERC20UbiquityDollarTest is DiamondTestSetup {
// create burner role
address burner = makeAddr("burner");
vm.prank(admin);
IAccessControl.grantRole(keccak256("DOLLAR_TOKEN_BURNER_ROLE"), burner);
accessControlFacet.grantRole(
keccak256("DOLLAR_TOKEN_BURNER_ROLE"),
burner
);
// admin pauses contract
vm.prank(admin);
dollarToken.pause();
Expand All @@ -188,7 +191,10 @@ contract ERC20UbiquityDollarTest is DiamondTestSetup {
// create burner role
address burner = makeAddr("burner");
vm.prank(admin);
IAccessControl.grantRole(keccak256("DOLLAR_TOKEN_BURNER_ROLE"), burner);
accessControlFacet.grantRole(
keccak256("DOLLAR_TOKEN_BURNER_ROLE"),
burner
);
// burn 50 tokens for user
vm.prank(burner);
vm.expectEmit(true, true, true, true);
Expand Down Expand Up @@ -245,10 +251,10 @@ contract ERC20UbiquityDollarTest is DiamondTestSetup {

function testUnpause_ShouldUnpauseContract() public {
vm.startPrank(admin);
IAccessControl.pause();
assertTrue(IAccessControl.paused());
IAccessControl.unpause();
assertFalse(IAccessControl.paused());
accessControlFacet.pause();
assertTrue(accessControlFacet.paused());
accessControlFacet.unpause();
assertFalse(accessControlFacet.paused());
vm.stopPrank();
}

Expand Down
32 changes: 25 additions & 7 deletions packages/contracts/test/diamond/facets/AccessControlFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ contract AccessControlFacetTest is DiamondTestSetup {
vm.prank(admin);
vm.expectEmit(true, true, true, true);
emit RoleGranted(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient, admin);
IAccessControl.grantRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);
}

// test grantRole function should revert if sender is not admin
Expand All @@ -48,19 +51,28 @@ contract AccessControlFacetTest is DiamondTestSetup {
uint256(DEFAULT_ADMIN_ROLE).toHexString(32)
)
);
IAccessControl.grantRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);
}

// test revokeRole function should work only for admin
function testRevokeRole_ShouldWork() public {
vm.prank(admin);
emit RoleGranted(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient, admin);
IAccessControl.grantRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);

vm.prank(admin);
vm.expectEmit(true, true, true, true);
emit RoleRevoked(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient, admin);
IAccessControl.revokeRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.revokeRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);
}

// test revokeRole function should revert if sender is not admin
Expand All @@ -75,15 +87,21 @@ contract AccessControlFacetTest is DiamondTestSetup {
uint256(DEFAULT_ADMIN_ROLE).toHexString(32)
)
);
IAccessControl.revokeRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.revokeRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);
}

// test renounceRole function should work for grantee
function testRenounceRole_ShouldWork() public {
vm.prank(admin);
vm.expectEmit(true, true, true, true);
emit RoleGranted(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient, admin);
IAccessControl.grantRole(GOVERNANCE_TOKEN_BURNER_ROLE, mock_recipient);
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
mock_recipient
);

vm.prank(mock_recipient);
vm.expectEmit(true, true, true, true);
Expand All @@ -92,6 +110,6 @@ contract AccessControlFacetTest is DiamondTestSetup {
mock_recipient,
mock_recipient
);
IAccessControl.renounceRole(GOVERNANCE_TOKEN_BURNER_ROLE);
accessControlFacet.renounceRole(GOVERNANCE_TOKEN_BURNER_ROLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract BondingCurveFacetTest is DiamondTestSetup {

vm.startPrank(admin);

IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/test/diamond/facets/ChefFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract ZeroStateChef is DiamondTestSetup {
vm.startPrank(admin);
managerFacet.setStakingShareAddress(address(stakingShare));
stakingShare.setApprovalForAll(address(diamond), true);
IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(stakingShare)
);
Expand All @@ -119,14 +119,14 @@ contract ZeroStateChef is DiamondTestSetup {

vm.startPrank(admin);

IAccessControl.grantRole(GOVERNANCE_TOKEN_MANAGER_ROLE, admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(diamond));
IAccessControl.grantRole(
accessControlFacet.grantRole(GOVERNANCE_TOKEN_MANAGER_ROLE, admin);
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(diamond));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);

IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
address(diamond)
);
Expand Down Expand Up @@ -170,7 +170,7 @@ contract ZeroStateChef is DiamondTestSetup {
metapool.add_liquidity(amounts_, (dyuAD2LP * 99) / 100, fourthAccount);

vm.startPrank(admin);
IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract CollectableDustFacetTest is DiamondTestSetup {

vm.startPrank(admin);

IAccessControl.grantRole(STAKING_MANAGER_ROLE, stakingManager);
accessControlFacet.grantRole(STAKING_MANAGER_ROLE, stakingManager);

// deploy mock token
mockToken = new MockERC20("Mock", "MCK", 18);
Expand Down
40 changes: 26 additions & 14 deletions packages/contracts/test/diamond/facets/CreditNftManagerFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {

// set this contract as minter
vm.startPrank(admin);
IAccessControl.grantRole(DOLLAR_TOKEN_MINTER_ROLE, address(this));
IAccessControl.grantRole(CREDIT_TOKEN_MINTER_ROLE, address(this));
IAccessControl.grantRole(
accessControlFacet.grantRole(DOLLAR_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(diamond));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(diamond));
vm.stopPrank();
}

Expand Down Expand Up @@ -167,7 +167,7 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {
uint256 expiryBlockNumber = 500;
vm.startPrank(admin);
creditNft.mintCreditNft(mockMessageSender, 2e18, expiryBlockNumber);
IAccessControl.grantRole(
accessControlFacet.grantRole(
keccak256("GOVERNANCE_TOKEN_MINTER_ROLE"),
creditNftManagerAddress
);
Expand Down Expand Up @@ -203,7 +203,7 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {
vm.startPrank(admin);

creditNft.mintCreditNft(mockMessageSender, 2e18, expiryBlockNumber);
IAccessControl.grantRole(
accessControlFacet.grantRole(
keccak256("GOVERNANCE_TOKEN_MINTER_ROLE"),
creditNftManagerAddress
);
Expand Down Expand Up @@ -258,8 +258,11 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {

function test_redeemCreditNftRevertsIfNotEnoughBalance() public {
vm.startPrank(admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(this)
);
vm.stopPrank();

mockTwapFuncs(2e18);
Expand All @@ -274,8 +277,11 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {

function test_redeemCreditNftRevertsIfNotEnoughDollars() public {
vm.startPrank(admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(this)
);
vm.stopPrank();

mockTwapFuncs(2e18);
Expand Down Expand Up @@ -304,8 +310,11 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {

function test_redeemCreditNftRevertsIfZeroAmountOfDollars() public {
vm.startPrank(admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(this)
);
vm.stopPrank();

mockTwapFuncs(2e18);
Expand Down Expand Up @@ -333,8 +342,11 @@ contract CreditNftManagerFacetTest is DiamondTestSetup {

function test_redeemCreditNftWorks() public {
vm.startPrank(admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(this)
);
vm.stopPrank();

mockTwapFuncs(2e18);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ contract CreditNftRedemptionCalculatorFacetTest is DiamondTestSetup {

vm.startPrank(admin);
managerFacet.setCreditNftAddress(address(creditNft));
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(this)
);
vm.stopPrank();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract CreditRedemptionCalculatorFacetTest is DiamondTestSetup {
assertEq(admSupply, 10000e18);

vm.startPrank(admin);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
accessControlFacet.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
creditNft.mintCreditNft(user1, 100, 10);
managerFacet.setCreditNftAddress(address(creditNft));
vm.stopPrank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract CurveDollarIncentiveTest is DiamondTestSetup {
twapOracleAddress = address(diamond);

vm.startPrank(admin);
IAccessControl.grantRole(CURVE_DOLLAR_MANAGER_ROLE, managerAddr);
accessControlFacet.grantRole(CURVE_DOLLAR_MANAGER_ROLE, managerAddr);
vm.stopPrank();
}

Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/test/diamond/facets/ManagerFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ contract ManagerFacetTest is DiamondTestSetup {

function testSetIncentiveToDollar_ShouldSucceed() public prankAs(admin) {
assertEq(
IAccessControl.hasRole(GOVERNANCE_TOKEN_MANAGER_ROLE, admin),
accessControlFacet.hasRole(GOVERNANCE_TOKEN_MANAGER_ROLE, admin),
true
);
assertEq(
IAccessControl.hasRole(
accessControlFacet.hasRole(
GOVERNANCE_TOKEN_MANAGER_ROLE,
address(diamond)
),
Expand All @@ -119,7 +119,7 @@ contract ManagerFacetTest is DiamondTestSetup {
prankAs(admin)
{
assertEq(
IAccessControl.hasRole(GOVERNANCE_TOKEN_MINTER_ROLE, admin),
accessControlFacet.hasRole(GOVERNANCE_TOKEN_MINTER_ROLE, admin),
true
);
}
Expand Down Expand Up @@ -157,11 +157,11 @@ contract ManagerFacetTest is DiamondTestSetup {
}

address stakingV1Address = generateAddress("stakingV1", true, 10 ether);
IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
stakingV1Address
);
IAccessControl.grantRole(
accessControlFacet.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
stakingV1Address
);
Expand Down
Loading

1 comment on commit edf5f53

@ubiquibot
Copy link

@ubiquibot ubiquibot bot commented on edf5f53 Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.