Skip to content

Commit

Permalink
test: update buySharesFailed user cases
Browse files Browse the repository at this point in the history
  • Loading branch information
0xashu committed May 21, 2024
1 parent bc64eae commit 58d3eea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
3 changes: 0 additions & 3 deletions test/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ contract BaseTest is Test {
sharesNFT.transferOwnership(owner);
sharesFactory.transferOwnership(owner);
aaveYieldAggregator.transferOwnership(owner);

// vm.prank(owner);
// sharesFactory.migrate(address(aaveYieldAggregator));
}

function testSuccess() public { }
Expand Down
27 changes: 17 additions & 10 deletions test/unit/SharesFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
pragma solidity 0.8.25;

import { console } from "forge-std/console.sol";
import { BaseTest } from "../BaseTest.t.sol";
import { SharesFactoryV1 } from "contracts/core/SharesFactoryV1.sol";
import { IYieldAggregator } from "contracts/interface/IYieldAggregator.sol";
import { BaseTest } from "../BaseTest.t.sol";

contract SharesFactoryTests is BaseTest {
uint8 public defaultCurveType = 0;
Expand Down Expand Up @@ -257,26 +258,32 @@ contract SharesFactoryTests is BaseTest {
*/

function test_buySharesFailed() public {
// invalid yieldAggregator, when sharesFactory not set yieldAggregator
SharesFactoryV1 newSharesFactory = new SharesFactoryV1(
address(sharesNFT),
BASE_PRICE,
INFLECTION_POINT,
INFLECTION_PRICE,
LINEAR_PRICE_SLOPE
);
vm.prank(addrAlice);
vm.expectRevert(bytes("Invalid yieldAggregator"));
newSharesFactory.buyShare{ value: 1 ether }(0, 1, referralReceiver);

// invalid shareId, when id >= shareIndex
uint256 shareIndex = sharesFactory.shareIndex();

vm.prank(addrAlice);
vm.startPrank(addrAlice);
vm.expectRevert(bytes("Invalid shareId"));
sharesFactory.buyShare{ value: 1 ether }(shareIndex, 1, referralReceiver);

vm.prank(addrAlice);
vm.expectRevert(bytes("Invalid shareId"));
sharesFactory.buyShare{ value: 1 ether }(shareIndex * 999, 1, referralReceiver);

// invalid buyer, when alice create shares, only alice can buy it first
vm.prank(addrAlice);
sharesFactory.mintShare(defaultCurveType);
vm.stopPrank();

// invalid value, when value < buyPriceAfterFee
(uint256 buyPriceAfterFee,,,) = sharesFactory.getBuyPriceAfterFee(0, 1, referralReceiver);
vm.prank(addrAlice);
vm.expectRevert(bytes("Insufficient payment"));
sharesFactory.buyShare{ value: buyPriceAfterFee / 2 }(0, 1, referralReceiver);
sharesFactory.buyShare{ value: buyPriceAfterFee }(0, 2, referralReceiver);
}

function test_sellSharesFailed() public {
Expand Down
20 changes: 1 addition & 19 deletions test/unit/YieldAggregator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,11 @@ contract YieldAggregatorTests is BaseTest {
sharesFactory.migrate(address(aaveYieldAggregator));
}

function test_withoutInitialYieldAggregator() public {
// test before set yieldAggregator buy fail
SharesFactoryV1 newSharesFactory = new SharesFactoryV1(
address(sharesNFT),
BASE_PRICE, // basePrice,
INFLECTION_POINT, // inflectionPoint,
INFLECTION_PRICE, // inflectionPrice
LINEAR_PRICE_SLOPE // linearPriceSlope,
);

vm.deal(addrAlice, 10 ether);
vm.prank(addrAlice);
vm.expectRevert(bytes("Invalid yieldAggregator"));
newSharesFactory.buyShare{ value: 5500050111111109 }(0, 1, referralReceiver);
}

function test_setYieldBuffer() public {
vm.skip(true);

// TODO: fix below
_testBuyShares();

vm.warp(YIELD_CLAIM_TIME); // need to fill a number gt current block.timestamp
vm.warp(YIELD_CLAIM_TIME);
uint256 depositedETHAmount = sharesFactory.depositedETHAmount();
uint256 maxYield = aaveYieldAggregator.yieldMaxClaimable(depositedETHAmount);
assertEq(depositedETHAmount, 10000227777777775);
Expand Down

0 comments on commit 58d3eea

Please sign in to comment.