Skip to content

Commit

Permalink
fix broken build
Browse files Browse the repository at this point in the history
- new foundry updates led to stricter requirements
- deal() doesn't work with SuperToken's because of dynamic balanceOf function
- FlowNFTBase.t.sol included a vm.prank which was unused
- use vm.startPrank over vm.prank in ConstantOutflow/ConstantInflow tests where there was a small issue
  • Loading branch information
0xdavinchee committed Oct 10, 2023
1 parent 6b1e163 commit b18c286
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Handler } from "./handlers/Handler.sol";
// app to be tested
import { FlowSplitter } from "./FlowSplitter.sol";

contract SuperAppInvariants is Test {
abstract contract SuperAppInvariants is Test {
ISuperfluid public host;
ISuperApp public superApp;
Handler public handler; // Focus test to a set of operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ contract ConstantInflowNFTTest is FlowNFTBaseTest {
vm.assume(_tokenOwner != address(0));
vm.assume(_tokenOwner != _operator);

vm.startPrank(_tokenOwner);
_assertEventApprovalForAll(address(constantInflowNFTProxy), _tokenOwner, _operator, _approved);

vm.prank(_tokenOwner);
constantInflowNFTProxy.setApprovalForAll(_operator, _approved);
vm.stopPrank();

_assertOperatorApprovalIsExpected(constantInflowNFTProxy, _tokenOwner, _operator, _approved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ contract ConstantOutflowNFTTest is FlowNFTBaseTest {
vm.assume(_tokenOwner != address(0));
vm.assume(_tokenOwner != _operator);

_assertEventApprovalForAll(address(constantOutflowNFTProxy), _tokenOwner, _operator, _approved);

vm.prank(_tokenOwner);
vm.startPrank(_tokenOwner);
_assertEventApprovalForAll(address(constantOutflowNFTProxy), _tokenOwner, _operator, _approved);
constantOutflowNFTProxy.setApprovalForAll(_operator, _approved);
vm.stopPrank();

_assertOperatorApprovalIsExpected(constantOutflowNFTProxy, _tokenOwner, _operator, _approved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ abstract contract FlowNFTBaseTest is FoundrySuperfluidTester {
for (uint256 i = 0; i < N_TESTERS; i++) {
superTokenMock.mintInternal(TEST_ACCOUNTS[i], INIT_SUPER_TOKEN_BALANCE, "0x", "0x");
}

vm.prank(sf.governance.owner());
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
44 changes: 34 additions & 10 deletions packages/ethereum-contracts/test/foundry/utils/TOGA.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ISuperToken } from "../../../contracts/superfluid/SuperToken.sol";
import { TOGA } from "../../../contracts/utils/TOGA.sol";
import { IERC1820Registry } from "@openzeppelin/contracts/interfaces/IERC1820Registry.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { TestToken } from "../../../contracts/utils/TestToken.sol";

/**
* @title TOGAIntegrationTest
Expand All @@ -18,7 +19,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
TOGA internal toga;

uint256 internal immutable MIN_BOND_DURATION;
uint256 internal constant DEFAULT_BOND_AMOUNT = 1E18;
uint256 internal constant DEFAULT_BOND_AMOUNT = 1e18;
IERC1820Registry internal constant _ERC1820_REG = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);

constructor() FoundrySuperfluidTester(5) {
Expand Down Expand Up @@ -53,6 +54,24 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
assertEq(flowRate, expectedNetFlow, "_assertNetFlow: net flow not equal");
}

/**
* @dev Admin sends `amount` `superToken_` to the `target` address.
* @param superToken_ The Super Token representing the asset.
* @param target The address of the target.
* @param amount The amount to send.
*/
function _helperDeal(ISuperToken superToken_, address target, uint256 amount) internal {
TestToken underlyingToken = TestToken(superToken_.getUnderlyingToken());
uint256 maxAmount = uint256(type(int256).max);
vm.startPrank(admin);
underlyingToken.mint(admin, maxAmount);
underlyingToken.approve(address(superToken_), maxAmount);
superToken_.transferAll(address(1));
superToken_.upgrade(maxAmount);
superToken_.transfer(target, amount);
vm.stopPrank();
}

/**
* @dev Sends a PIC bid.
* @param sender The address of the sender.
Expand Down Expand Up @@ -131,7 +150,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
// setting the lower bound > 1 in order to avoid
// failures due to the exit stream not having enough min deposit
// (clipping related)
bond = bound(bond_, 1E12, INIT_SUPER_TOKEN_BALANCE);
bond = bound(bond_, 1e12, INIT_SUPER_TOKEN_BALANCE);
// before allowing higher limits, also consider that
// the values returned by toga.getMaxExitRateFor() may not be achievable in practice
// because of the flowrate data type restriction
Expand Down Expand Up @@ -260,7 +279,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
prevReward = bound(prevReward, 1, bond - 1); // make sure the bond exceeds it

// simulate pre-existing accumulation of rewards
deal(address(superToken), address(toga), prevReward);
_helperDeal(superToken, address(toga), prevReward);

_helperSendPICBid(alice, superToken, bond, 0);
(, uint256 aliceBond,) = toga.getCurrentPICInfo(superToken);
Expand Down Expand Up @@ -309,7 +328,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
function testPICClosesStream(uint256 bond) public {
bond = _boundBondValue(bond);

_helperSendPICBid(alice, superToken, bond, 1E3);
_helperSendPICBid(alice, superToken, bond, 1e3);

vm.warp(block.timestamp + 1000);
_helperDeleteFlow(superToken, alice, address(toga), alice);
Expand All @@ -324,7 +343,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
_assertNetFlow(superToken, alice, 0);

// bob sends a bid too
_helperSendPICBid(bob, superToken, bond, 1E3);
_helperSendPICBid(bob, superToken, bond, 1e3);
_assertNetFlow(superToken, alice, 0);
}

Expand Down Expand Up @@ -364,7 +383,7 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
assertEq(bond, 0);

// accumulate some new rewards...
deal(address(superToken), address(toga), 1e15);
_helperDeal(superToken, address(toga), 1e15);

(, uint256 bond2,) = toga.getCurrentPICInfo(superToken);
assertGe(bond2, 1e12);
Expand All @@ -386,7 +405,8 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {
function testBondAndExitRateLimits(uint256 bond, int96 exitRate) public {
bond = bound(
bond,
exitRate == 0 ? 1 : 1 << 32, // with small bonds, opening the stream can fail due to CFA deposit having a flow of 1<<32 due to clipping
exitRate == 0 ? 1 : 1 << 32, // with small bonds, opening the stream can fail due to CFA deposit having a
// flow of 1<<32 due to clipping
uint256(type(int256).max) // SuperToken doesn't support the full uint256 range
);

Expand All @@ -399,7 +419,11 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {

exitRate = int96(bound(exitRate, 0, maxExitRate));

deal(address(superToken), alice, uint256(type(int256).max));
vm.startPrank(alice);
superToken.transferAll(address(1));
vm.stopPrank();

_helperDeal(superToken, alice, uint256(type(int256).max));

_helperSendPICBid(alice, superToken, bond, exitRate);
}
Expand All @@ -409,8 +433,8 @@ contract TOGAIntegrationTest is FoundrySuperfluidTester {

(, ISuperToken superToken2) = sfDeployer.deployWrapperSuperToken("TEST2", "TEST2", 18, type(uint256).max);

deal(address(superToken2), alice, INIT_SUPER_TOKEN_BALANCE);
deal(address(superToken2), bob, INIT_SUPER_TOKEN_BALANCE);
_helperDeal(superToken2, alice, INIT_SUPER_TOKEN_BALANCE);
_helperDeal(superToken2, bob, INIT_SUPER_TOKEN_BALANCE);

_helperSendPICBid(alice, superToken, bond, toga.getDefaultExitRateFor(superToken, bond));
_helperSendPICBid(bob, superToken2, bond, toga.getDefaultExitRateFor(superToken, bond));
Expand Down

0 comments on commit b18c286

Please sign in to comment.