From eab7af445144489a48900a84ad6f89dfc282d5ca Mon Sep 17 00:00:00 2001 From: Miao ZhiCheng Date: Tue, 10 Oct 2023 16:59:54 +0300 Subject: [PATCH] update foundry to 2023-10-04 (#1715) * update foundry to 2023-10-04 * check-changeset.sh to detect nix flake changes * remove old remapping files * update lib/forge-std * 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 --------- Co-authored-by: 0xdavinchee <0xdavinchee@gmail.com> --- flake.lock | 6 +-- lib/forge-std | 2 +- .../autowrap/remappings.txt | 4 -- .../scheduler/remappings.txt | 4 -- .../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 ++++++++++++++----- tasks/check-changeset.sh | 24 +++++----- 10 files changed, 56 insertions(+), 41 deletions(-) delete mode 100644 packages/automation-contracts/autowrap/remappings.txt delete mode 100644 packages/automation-contracts/scheduler/remappings.txt diff --git a/flake.lock b/flake.lock index b6e8ae656d..c056a74a30 100644 --- a/flake.lock +++ b/flake.lock @@ -28,11 +28,11 @@ ] }, "locked": { - "lastModified": 1691140388, - "narHash": "sha256-AH3fx2VFGPRSOjnuakab4T4AdUstwTnFTbnkoU4df8Q=", + "lastModified": 1696410815, + "narHash": "sha256-uku47D/L+VzO3sVoZbnexPQPGeQtMwMFBesyaA1vKtE=", "owner": "shazow", "repo": "foundry.nix", - "rev": "6089aad0ef615ac8c7b0c948d6052fa848c99523", + "rev": "a56126a754d73f85d904768fed569a9e250388d9", "type": "github" }, "original": { diff --git a/lib/forge-std b/lib/forge-std index 9dc1514b11..f73c73d201 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 9dc1514b1114ef078fd6be1d8de92904592eeb15 +Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 diff --git a/packages/automation-contracts/autowrap/remappings.txt b/packages/automation-contracts/autowrap/remappings.txt deleted file mode 100644 index 76bdfc31ff..0000000000 --- a/packages/automation-contracts/autowrap/remappings.txt +++ /dev/null @@ -1,4 +0,0 @@ -@openzeppelin/=node_modules/@openzeppelin/ -@superfluid-finance/ethereum-contracts/contracts/=packages/ethereum-contracts/contracts/ -ds-test/=lib/forge-std/lib/ds-test/src/ -forge-std/=lib/forge-std/src/ diff --git a/packages/automation-contracts/scheduler/remappings.txt b/packages/automation-contracts/scheduler/remappings.txt deleted file mode 100644 index 76bdfc31ff..0000000000 --- a/packages/automation-contracts/scheduler/remappings.txt +++ /dev/null @@ -1,4 +0,0 @@ -@openzeppelin/=node_modules/@openzeppelin/ -@superfluid-finance/ethereum-contracts/contracts/=packages/ethereum-contracts/contracts/ -ds-test/=lib/forge-std/lib/ds-test/src/ -forge-std/=lib/forge-std/src/ 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)); diff --git a/tasks/check-changeset.sh b/tasks/check-changeset.sh index f5087250ee..929d147cf7 100755 --- a/tasks/check-changeset.sh +++ b/tasks/check-changeset.sh @@ -34,22 +34,22 @@ function setBuildAll() { # (dependency graph implied below) if [ -n "$GITHUB_ENV" ];then # if ci workflows changed - if grep -E "^.github/workflows/ci.*.yml$" changed-files.list;then + if grep -E "^.github/workflows/ci\..*\.yml$" changed-files.list;then echo "CI workflows changed." setBuildAll fi # if call (reusable) workflows changed - if grep -E "^.github/workflows/call.*.yml$" changed-files.list;then + if grep -E "^.github/workflows/call\..*\.yml$" changed-files.list;then echo "Call workflows changed." setBuildAll fi # if root package.json changed, rebuild everything - if grep -E "^(package.json|yarn.lock)$" changed-files.list;then + if grep -E "^(flake\.nix|flake\.lock|package\.json|yarn\.lock)$" changed-files.list;then echo "Root package.json changed." setBuildAll fi # if specified ethereum-contracts folders and files changed - if grep -E "^packages/ethereum-contracts/(contracts/|scripts/|test/|truffle-config.js|package.json)" changed-files.list;then + if grep -E "^packages/ethereum-contracts/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then BUILD_ETHEREUM_CONTRACTS=1 BUILD_SUBGRAPH=1 BUILD_HOT_FUZZ=1 @@ -57,44 +57,44 @@ if [ -n "$GITHUB_ENV" ];then echo Ethereum contracts, HotFuzz and Subgraph will be tested. fi # if specified hot-fuzz folders and files changed - if grep -E "^packages/hot-fuzz/(contracts/|scripts/|.+.js|.+.yaml|hot-fuzz|package.json)" changed-files.list;then + if grep -E "^packages/hot-fuzz/(contracts/|scripts/|.+\.js|.+\.yaml|hot-fuzz|package\.json)" changed-files.list;then BUILD_HOT_FUZZ=1 echo HotFuzz will be tested. fi # if specified sdk-core folders and files changed - if grep -E "^packages/sdk-core/(src/|test/|package.json|tsconfig.*)" changed-files.list;then + if grep -E "^packages/sdk-core/(src/|test/|package\.json|tsconfig\.*)" changed-files.list;then BUILD_SDK_CORE=1 BUILD_SDK_REDUX=1 BUILD_SUBGRAPH=1 echo SDK-CORE, SDK-REDUX and SUBGRAPH will be tested. fi # if specified sdk-redux folders and files changed - if grep -E "^packages/sdk-redux/(src/|test/|package.json)" changed-files.list;then + if grep -E "^packages/sdk-redux/(src/|test/|package\.json)" changed-files.list;then BUILD_SDK_REDUX=1 echo SDK-REDUX will be tested. fi # if specified subgraph folders and files changed - if grep -E "^packages/subgraph/(subgraph.template.yaml|schema.graphql|config|scripts|src|tasks|test|hardhat.config.ts|package.json|docker-compose.yml)" changed-files.list;then + if grep -E "^packages/subgraph/(subgraph\.template\.yaml|schema\.graphql|config|scripts|src|tasks|test|hardhat\.config\.ts|package\.json|docker-compose\.yml)" changed-files.list;then BUILD_SUBGRAPH=1 echo Subgraph will be tested. fi # if specified haskell folders and files changed - if grep -E "^packages/spec-haskell/(packages/|cabal.project)" changed-files.list;then + if grep -E "^packages/spec-haskell/(packages/|cabal\.project)" changed-files.list;then BUILD_SPEC_HASKELL=1 echo SPEC-HASKELL will be tested. fi # if specified automation-contracts/scheduler folders and files changed - if grep -E "^packages/automation-contracts/scheduler/(contracts/|scripts/|test/|truffle-config.js|package.json)" changed-files.list;then + if grep -E "^packages/automation-contracts/scheduler/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then BUILD_AUTOMATION_CONTRACTS=1 echo Automation Contracts will be tested. fi # if specified automation-contracts/autowrap folders and files changed - if grep -E "^packages/automation-contracts/autowrap/(contracts/|scripts/|test/|truffle-config.js|package.json)" changed-files.list;then + if grep -E "^packages/automation-contracts/autowrap/(contracts/|scripts/|test/|truffle-config\.js|package\.json)" changed-files.list;then BUILD_AUTOMATION_CONTRACTS=1 echo Automation Contracts will be tested. fi # if specified solidity-semantic-money folders and files changed - if grep -E "^packages/solidity-semantic-money/(src/|test/|foundry.toml|Makefile|package.json)" changed-files.list;then + if grep -E "^packages/solidity-semantic-money/(src/|test/|foundry\.toml|Makefile|package\.json)" changed-files.list;then BUILD_SOLIDITY_SEMANTIC_MONEY=1 echo Solidity semantic money will be tested. fi