-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from rndquu/feature/489
- Loading branch information
Showing
9 changed files
with
667 additions
and
223 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import "../../src/dollar/UbiquityFormulas.sol"; | ||
|
||
contract UbiquityFormulasTest is Test { | ||
UbiquityFormulas ubiquityFormulas; | ||
|
||
function setUp() public { | ||
ubiquityFormulas = new UbiquityFormulas(); | ||
} | ||
|
||
function testDurationMultiply_ShouldReturnAmount() public { | ||
uint amount = ubiquityFormulas.durationMultiply( | ||
100 ether, | ||
1, | ||
1000000 gwei | ||
); | ||
assertEq(amount, 100100000000000000000); | ||
} | ||
|
||
function testStaking_ShouldReturnAmount() public { | ||
uint amount = ubiquityFormulas.staking(100 ether, 2 ether, 3 ether); | ||
assertEq(amount, 150000000000000000000); | ||
} | ||
|
||
function testRedeemShares_ShouldReturnAmount() public { | ||
uint amount = ubiquityFormulas.redeemShares( | ||
100 ether, | ||
2 ether, | ||
3 ether | ||
); | ||
assertEq(amount, 66666666666666666666); | ||
} | ||
|
||
function testSharePrice_ShouldReturnAmount() public { | ||
uint amount = ubiquityFormulas.sharePrice( | ||
100 ether, | ||
100 ether, | ||
1 ether | ||
); | ||
assertEq(amount, 1000000000000000000); | ||
} | ||
|
||
function testGovernanceMultiply_ShouldReturnAmount() public { | ||
uint amount = ubiquityFormulas.governanceMultiply(1e18, 1 ether); | ||
assertEq(amount, 1050000000000000000); | ||
} | ||
|
||
function testGovernanceMultiply_ShouldReturnAmount_IfNewMultiplierIsTooBig() | ||
public | ||
{ | ||
uint amount = ubiquityFormulas.governanceMultiply(100e18, 1 ether); | ||
assertEq(amount, 100000000000000000000); | ||
} | ||
|
||
function testGovernanceMultiply_ShouldReturnAmount_IfNewMultiplierIsTooSmall() | ||
public | ||
{ | ||
uint amount = ubiquityFormulas.governanceMultiply(1e6, 1 ether); | ||
assertEq(amount, 1000000); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/contracts/test/dollar/core/CreditRedemptionCalculator.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "../../../src/dollar/core/CreditRedemptionCalculator.sol"; | ||
import "../../helpers/LocalTestHelper.sol"; | ||
|
||
contract CreditRedemptionCalculatorTest is LocalTestHelper { | ||
CreditRedemptionCalculator creditCalc; | ||
|
||
// test users | ||
address user; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
user = address(0x01); | ||
|
||
creditCalc = new CreditRedemptionCalculator(manager); | ||
} | ||
|
||
function testConstructor_ShouldInitContract() public { | ||
assertEq(address(creditCalc.manager()), address(manager)); | ||
} | ||
|
||
function testSetConstant_ShouldRevert_IfCalledNotByAdmin() public { | ||
vm.prank(user); | ||
vm.expectRevert("CreditCalculator: not admin"); | ||
creditCalc.setConstant(2 ether); | ||
} | ||
|
||
function testSetConstant_ShouldUpdateCoef() public { | ||
vm.prank(admin); | ||
creditCalc.setConstant(2 ether); | ||
assertEq(creditCalc.getConstant(), 2 ether); | ||
} | ||
|
||
function testGetCreditAmount_ShouldRevert_IfDebtIsTooHigh() public { | ||
vm.mockCall( | ||
manager.dollarTokenAddress(), | ||
abi.encodeWithSelector(IERC20.totalSupply.selector), | ||
abi.encode(1) | ||
); | ||
vm.expectRevert("Credit to Dollar: DEBT_TOO_HIGH"); | ||
creditCalc.getCreditAmount(1 ether, 10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/contracts/test/dollar/core/UbiquityCreditToken.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.16; | ||
|
||
import "../../../src/dollar/core/UbiquityCreditToken.sol"; | ||
import "../../helpers/LocalTestHelper.sol"; | ||
|
||
contract UbiquityCreditTokenTest is LocalTestHelper { | ||
UbiquityCreditToken ubiquityCreditToken; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
vm.prank(admin); | ||
ubiquityCreditToken = new UbiquityCreditToken(manager); | ||
} | ||
|
||
function testRaiseCapital_ShouldMintTokens() public { | ||
assertEq(ubiquityCreditToken.balanceOf(treasuryAddress), 0); | ||
vm.prank(admin); | ||
ubiquityCreditToken.raiseCapital(1e18); | ||
assertEq(ubiquityCreditToken.balanceOf(treasuryAddress), 1e18); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f64dc4c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deployment: Thu Feb 02 2023 01:48:43 (UTC)