From b18c286081086543bdfe7bf8d24026eec1ced2c5 Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Tue, 10 Oct 2023 14:32:01 +0300 Subject: [PATCH] fix broken build - 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 --- .../apps/SuperAppTester/SuperAppTest.t.sol | 2 +- .../superfluid/ConstantInflowNFT.t.sol | 4 +- .../superfluid/ConstantOutflowNFT.t.sol | 5 ++- .../test/foundry/superfluid/FlowNFTBase.t.sol | 2 - .../test/foundry/utils/TOGA.t.sol | 44 ++++++++++++++----- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/packages/ethereum-contracts/test/foundry/apps/SuperAppTester/SuperAppTest.t.sol b/packages/ethereum-contracts/test/foundry/apps/SuperAppTester/SuperAppTest.t.sol index b76c3f42f1..699ee33eee 100644 --- a/packages/ethereum-contracts/test/foundry/apps/SuperAppTester/SuperAppTest.t.sol +++ b/packages/ethereum-contracts/test/foundry/apps/SuperAppTester/SuperAppTest.t.sol @@ -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 diff --git a/packages/ethereum-contracts/test/foundry/superfluid/ConstantInflowNFT.t.sol b/packages/ethereum-contracts/test/foundry/superfluid/ConstantInflowNFT.t.sol index 970ac35690..c1422b25c9 100644 --- a/packages/ethereum-contracts/test/foundry/superfluid/ConstantInflowNFT.t.sol +++ b/packages/ethereum-contracts/test/foundry/superfluid/ConstantInflowNFT.t.sol @@ -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); } diff --git a/packages/ethereum-contracts/test/foundry/superfluid/ConstantOutflowNFT.t.sol b/packages/ethereum-contracts/test/foundry/superfluid/ConstantOutflowNFT.t.sol index 95108c0cda..4cb8c346b0 100644 --- a/packages/ethereum-contracts/test/foundry/superfluid/ConstantOutflowNFT.t.sol +++ b/packages/ethereum-contracts/test/foundry/superfluid/ConstantOutflowNFT.t.sol @@ -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); } diff --git a/packages/ethereum-contracts/test/foundry/superfluid/FlowNFTBase.t.sol b/packages/ethereum-contracts/test/foundry/superfluid/FlowNFTBase.t.sol index 1b15410680..3c25f69be8 100644 --- a/packages/ethereum-contracts/test/foundry/superfluid/FlowNFTBase.t.sol +++ b/packages/ethereum-contracts/test/foundry/superfluid/FlowNFTBase.t.sol @@ -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()); } /*////////////////////////////////////////////////////////////////////////// diff --git a/packages/ethereum-contracts/test/foundry/utils/TOGA.t.sol b/packages/ethereum-contracts/test/foundry/utils/TOGA.t.sol index b634d34701..42e1fbb8c1 100644 --- a/packages/ethereum-contracts/test/foundry/utils/TOGA.t.sol +++ b/packages/ethereum-contracts/test/foundry/utils/TOGA.t.sol @@ -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 @@ -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) { @@ -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. @@ -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 @@ -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); @@ -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); @@ -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); } @@ -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); @@ -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 ); @@ -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); } @@ -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));