Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove CreditNft mock #762

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions packages/contracts/src/dollar/mocks/MockCreditNft.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "../DiamondTestSetup.sol";
import "../../../src/dollar/libraries/Constants.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {MockERC20} from "../../../src/dollar/mocks/MockERC20.sol";
import {MockCreditNft} from "../../../src/dollar/mocks/MockCreditNft.sol";
import "forge-std/Test.sol";

contract BondingCurveFacetTest is DiamondSetup {
Expand All @@ -29,7 +28,10 @@ contract BondingCurveFacetTest is DiamondSetup {
super.setUp();

vm.startPrank(admin);
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(diamond));
IAccessControl.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);

vm.stopPrank();
}
Expand Down
16 changes: 12 additions & 4 deletions packages/contracts/test/diamond/facets/ChefFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {IERC20Ubiquity} from "../../../src/dollar/interfaces/IERC20Ubiquity.sol"
import {ICurveFactory} from "../../../src/dollar/interfaces/ICurveFactory.sol";

import {DollarMintCalculatorFacet} from "../../../src/dollar/facets/DollarMintCalculatorFacet.sol";
import {MockCreditNft} from "../../../src/dollar/mocks/MockCreditNft.sol";
import {UbiquityCreditToken} from "../../../src/dollar/core/UbiquityCreditToken.sol";
import "../../../src/dollar/libraries/Constants.sol";
import {MockERC20} from "../../../src/dollar/mocks/MockERC20.sol";
Expand Down Expand Up @@ -127,9 +126,15 @@ contract ZeroStateChef is DiamondSetup {

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

IAccessControl.grantRole(GOVERNANCE_TOKEN_BURNER_ROLE, address(diamond));
IAccessControl.grantRole(
GOVERNANCE_TOKEN_BURNER_ROLE,
address(diamond)
);
UbiquityCreditToken creditToken = new UbiquityCreditToken(
address(IManager)
);
Expand Down Expand Up @@ -175,7 +180,10 @@ contract ZeroStateChef is DiamondSetup {
vm.startPrank(admin);
stakingShare = new StakingShare(address(diamond), uri);
IManager.setStakingShareAddress(address(stakingShare));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(diamond));
IAccessControl.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);
IStakingFacet.setBlockCountInAWeek(420);

vm.stopPrank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {DollarMintExcessFacet} from "../../../src/dollar/facets/DollarMintExcess
import {TWAPOracleDollar3poolFacet} from "../../../src/dollar/facets/TWAPOracleDollar3poolFacet.sol";
import "../../../src/dollar/libraries/Constants.sol";
import {IERC20Ubiquity} from "../../../src/dollar/interfaces/IERC20Ubiquity.sol";
import {MockCreditNft} from "../../../src/dollar/mocks/MockCreditNft.sol";
import {CreditNft} from "../../../src/dollar/core/CreditNft.sol";
import {UbiquityCreditToken} from "../../../src/dollar/core/UbiquityCreditToken.sol";

contract CreditNftManagerFacetTest is DiamondSetup {
MockCreditNft _creditNft;
CreditNft _creditNft;
address dollarManagerAddress;
address dollarTokenAddress;
address creditCalculatorAddress;
Expand All @@ -32,7 +32,7 @@ contract CreditNftManagerFacetTest is DiamondSetup {
uint256 admSupply = IDollar.balanceOf(admin);
assertEq(admSupply, 10000e18);

_creditNft = new MockCreditNft(100);
_creditNft = new CreditNft(address(diamond));
vm.prank(admin);
IManager.setCreditNftAddress(address(_creditNft));

Expand All @@ -54,6 +54,11 @@ contract CreditNftManagerFacetTest is DiamondSetup {
vm.startPrank(admin);
IAccessControl.grantRole(DOLLAR_TOKEN_MINTER_ROLE, address(this));
IAccessControl.grantRole(CREDIT_TOKEN_MINTER_ROLE, address(this));
IAccessControl.grantRole(
GOVERNANCE_TOKEN_MINTER_ROLE,
address(diamond)
);
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(diamond));
vm.stopPrank();
}

Expand Down Expand Up @@ -152,11 +157,7 @@ contract CreditNftManagerFacetTest is DiamondSetup {
{
address mockMessageSender = address(0x123);
vm.prank(admin);
MockCreditNft(creditNftAddress).mintCreditNft(
mockMessageSender,
100,
500
);
CreditNft(creditNftAddress).mintCreditNft(mockMessageSender, 100, 500);
vm.roll(1000);
vm.prank(mockMessageSender);
vm.expectRevert("User not enough Credit NFT");
Expand All @@ -167,7 +168,7 @@ contract CreditNftManagerFacetTest is DiamondSetup {
address mockMessageSender = address(0x123);
uint256 expiryBlockNumber = 500;
vm.startPrank(admin);
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
mockMessageSender,
2e18,
expiryBlockNumber
Expand All @@ -178,11 +179,13 @@ contract CreditNftManagerFacetTest is DiamondSetup {
);
vm.stopPrank();
vm.roll(1000);
vm.prank(mockMessageSender);
vm.startPrank(mockMessageSender);
CreditNft(creditNftAddress).setApprovalForAll(address(diamond), true);
ICreditNftManagerFacet.burnExpiredCreditNftForGovernance(
expiryBlockNumber,
1e18
);
vm.stopPrank();
uint256 governanceBalance = IERC20Ubiquity(governanceTokenAddress)
.balanceOf(mockMessageSender);
assertEq(governanceBalance, 5e17);
Expand All @@ -204,7 +207,7 @@ contract CreditNftManagerFacetTest is DiamondSetup {
address mockMessageSender = address(0x123);
uint256 expiryBlockNumber = 500;
vm.startPrank(admin);
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
mockMessageSender,
2e18,
expiryBlockNumber
Expand All @@ -214,9 +217,11 @@ contract CreditNftManagerFacetTest is DiamondSetup {
creditNftManagerAddress
);
vm.stopPrank();
vm.prank(mockMessageSender);
vm.startPrank(mockMessageSender);
vm.warp(expiryBlockNumber - 1);
CreditNft(creditNftAddress).setApprovalForAll(address(diamond), true);
ICreditNftManagerFacet.burnCreditNftForCredit(expiryBlockNumber, 1e18);
vm.stopPrank();
uint256 redeemBalance = UbiquityCreditToken(creditTokenAddress)
.balanceOf(mockMessageSender);
assertEq(redeemBalance, 1e18);
Expand Down Expand Up @@ -262,10 +267,15 @@ contract CreditNftManagerFacetTest is DiamondSetup {
}

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

mockTwapFuncs(2e18);
address account1 = address(0x123);
uint256 expiryBlockNumber = 123123;
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
account1,
100,
expiryBlockNumber
Expand All @@ -277,10 +287,15 @@ contract CreditNftManagerFacetTest is DiamondSetup {
}

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

mockTwapFuncs(2e18);
address account1 = address(0x123);
uint256 expiryBlockNumber = 123123;
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
account1,
100,
expiryBlockNumber
Expand All @@ -306,11 +321,16 @@ contract CreditNftManagerFacetTest is DiamondSetup {
}

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

mockTwapFuncs(2e18);
mockDollarMintCalcFuncs(0);
address account1 = address(0x123);
uint256 expiryBlockNumber = 123123;
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
account1,
100,
expiryBlockNumber
Expand All @@ -334,11 +354,16 @@ contract CreditNftManagerFacetTest is DiamondSetup {
}

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

mockTwapFuncs(2e18);
mockDollarMintCalcFuncs(20000e18);
address account1 = address(0x123);
uint256 expiryBlockNumber = 123123;
MockCreditNft(creditNftAddress).mintCreditNft(
CreditNft(creditNftAddress).mintCreditNft(
account1,
100,
expiryBlockNumber
Expand All @@ -356,12 +381,15 @@ contract CreditNftManagerFacetTest is DiamondSetup {
),
abi.encode()
);
vm.prank(account1);
vm.startPrank(account1);
CreditNft(creditNftAddress).setApprovalForAll(address(diamond), true);
vm.roll(expiryBlockNumber - 1);
uint256 unredeemedCreditNft = ICreditNftManagerFacet.redeemCreditNft(
expiryBlockNumber,
99
);
vm.stopPrank();

assertEq(unredeemedCreditNft, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
pragma solidity ^0.8.19;

import "../DiamondTestSetup.sol";
import {MockCreditNft} from "../../../src/dollar/mocks/MockCreditNft.sol";
import {CreditNft} from "../../../src/dollar/core/CreditNft.sol";

contract CreditNftRedemptionCalculatorFacetTest is DiamondSetup {
MockCreditNft _creditNft;
CreditNft _creditNft;

function setUp() public virtual override {
super.setUp();
vm.prank(admin);
IDollar.mint(admin, 10000e18);
uint256 admSupply = IDollar.balanceOf(admin);
assertEq(admSupply, 10000e18);
_creditNft = new MockCreditNft(100);
vm.prank(admin);
_creditNft = new CreditNft(address(diamond));

vm.startPrank(admin);
IManager.setCreditNftAddress(address(_creditNft));
IAccessControl.grantRole(CREDIT_NFT_MANAGER_ROLE, address(this));
IAccessControl.grantRole(GOVERNANCE_TOKEN_MINTER_ROLE, address(this));
vm.stopPrank();
}

function test_getCreditNftAmount_revertsIfDebtTooHigh() public {
uint256 totalSupply = IDollar.totalSupply();
MockCreditNft(IManager.creditNftAddress()).setTotalOutstandingDebt(
totalSupply + 1
);

_creditNft.mintCreditNft(user1, 100000 ether, 1000);
vm.expectRevert("CreditNft to Dollar: DEBT_TOO_HIGH");
ICreditNftRedemptionCalculationFacet.getCreditNftAmount(0);
}

function test_getCreditNftAmount() public {
uint256 totalSupply = IDollar.totalSupply();
MockCreditNft(IManager.creditNftAddress()).setTotalOutstandingDebt(
totalSupply / 2
_creditNft.mintCreditNft(user1, 5000 ether, 10);
assertEq(
ICreditNftRedemptionCalculationFacet.getCreditNftAmount(10000),
40000
);
assertEq(ICreditNftRedemptionCalculationFacet.getCreditNftAmount(10000), 40000);
}
}
Loading
Loading