Skip to content

Commit

Permalink
test: add deposit too large and withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
rori4 committed Mar 17, 2024
1 parent f536f5f commit 1d87e61
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ out/
# Dotenv file
.env
.vscode
lcov.info
lcov.info

# Coverage directory
coverage/
*.info
29 changes: 29 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# generates lcov.info
forge coverage --report lcov --no-match-test testFork

if ! command -v lcov &>/dev/null; then
echo "lcov is not installed. Installing..."
# check if its macos or linux.
if [ "$(uname)" == "Darwin" ]; then
brew install lcov
else
sudo apt-get install lcov
fi
fi

lcov --version

# forge does not instrument libraries https://github.com/foundry-rs/foundry/issues/4854
EXCLUDE="*test* *mock* *node_modules* $(grep -r 'library' contracts -l)"
lcov --rc lcov_branch_coverage=1 \
--output-file forge-pruned-lcov.info \
--remove lcov.info $EXCLUDE

if [ "$CI" != "true" ]; then
genhtml --rc lcov_branch_coverage=1 \
--ignore-errors category \
--output-directory coverage forge-pruned-lcov.info \
&& open coverage/index.html
fi
2 changes: 1 addition & 1 deletion src/ESynth/ESynth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ contract ESynth is ERC20Collateral, Ownable {
function _msgSender() internal view virtual override(ERC20Collateral, Context) returns (address) {
return ERC20Collateral._msgSender();
}
}
}
18 changes: 17 additions & 1 deletion test/unit/esynth/ESynthGeneral.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.20;

import {ESynthTest} from "./lib/ESynthTest.sol";
import {stdError} from "forge-std/Test.sol";
import {Errors} from "src/EVault/shared/Errors.sol";

contract ESynthGeneralTest is ESynthTest {
function testFuzz_mintShouldIncreaseTotalSupplyAndBalance(uint256 amount) public {
Expand Down Expand Up @@ -36,9 +38,23 @@ contract ESynthGeneralTest is ESynthTest {
}
}

function testFuzz_ESynthDeposit(uint256 amount) public {
function testFuzz_depositSimple(uint256 amount) public {
amount = bound(amount, 1, type(uint112).max); // amount needs to be less then MAX_SANE_AMOUNT
esynth.mint(address(esynth), amount); // address(this) should be owner
esynth.deposit(address(eTST), amount);
}

function testFuzz_depositTooLarge(uint256 amount) public {
amount = bound(amount, uint256(type(uint112).max) + 1, type(uint256).max);
esynth.mint(address(esynth), amount);
vm.expectRevert(Errors.E_AmountTooLargeToEncode.selector);
esynth.deposit(address(eTST), amount);
}

function testFuzz_withdrawSimple(uint256 amount) public {
amount = bound(amount, 1, type(uint112).max);
esynth.mint(address(esynth), amount);
esynth.deposit(address(eTST), amount);
esynth.withdraw(address(eTST), amount);
}
}

0 comments on commit 1d87e61

Please sign in to comment.