Skip to content

Commit

Permalink
update foundry to 2023-10-04 (#1715)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
hellwolf and 0xdavinchee authored Oct 10, 2023
1 parent 7a4f969 commit eab7af4
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 41 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions packages/automation-contracts/autowrap/remappings.txt

This file was deleted.

4 changes: 0 additions & 4 deletions packages/automation-contracts/scheduler/remappings.txt

This file was deleted.

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
24 changes: 12 additions & 12 deletions tasks/check-changeset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,67 @@ 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
BUILD_AUTOMATION_CONTRACTS=1
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
Expand Down

0 comments on commit eab7af4

Please sign in to comment.