Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend coverage on uniswapPair mint() #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions part3/contracts/crytic/EchidnaTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,37 @@ import "./Setup.sol";

contract EchidnaTest is Setup {
event logUints(uint unit1, uint unit2);
function testProvideLiquidity(uint amount1, uint amount2) public {
//Preconditions:
amount1 = _between(amount1, 1000, uint(-1));
amount2 = _between(amount2, 1000, uint(-1));

if(!completed) {
_init(amount1, amount2);

function mintLiquidity(uint amount1, uint amount2) public returns (bool,uint,uint) {
//precondition
if(!notInitialLiquidityMint) {
amount1 = _between(amount1, 1000, uint(-1));
amount2 = _between(amount2, 1000, uint(-1));
notInitialLiquidityMint = true;
}

_init(amount1, amount2);

uint lpTokenBalanceBefore = pair.balanceOf(address(user));
(uint reserve0Before, uint reserve1Before,) = pair.getReserves();
uint kBefore = reserve0Before * reserve1Before;

(bool success1,) = user.proxy(address(testToken1),abi.encodeWithSelector(testToken1.transfer.selector, address(pair),amount1));
(bool success2,) = user.proxy(address(testToken2),abi.encodeWithSelector(testToken2.transfer.selector, address(pair),amount2));
require(success1 && success2);

//Action:
(bool success3,) = user.proxy(address(pair),abi.encodeWithSelector(bytes4(keccak256("mint(address)")), address(user)));

return (success3, lpTokenBalanceBefore, kBefore);
}
//Allows to mint liquidity not just on initial scenario and extend coverage
function testProvideLiquidity(uint amount1, uint amount2) public {
//perform preconditions and action on mintLiquidity
(bool success, uint lpTokenBalanceBefore, uint kBefore) = mintLiquidity(amount1, amount2);
//Postconditions:
if(success3) {
if(success) {
uint lpTokenBalanceAfter = pair.balanceOf(address(user));
(uint reserve0After, uint reserve1After,) = pair.getReserves();
uint kAfter = reserve0After * reserve1After;
Expand All @@ -34,6 +44,7 @@ contract EchidnaTest is Setup {
}

}

function testSwap(uint amount1, uint amount2) public {

if(!completed) {
Expand All @@ -48,8 +59,6 @@ contract EchidnaTest is Setup {

//Postcondition:
assert(!success1); //call should never succeed



}

}
5 changes: 1 addition & 4 deletions part3/contracts/crytic/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract Setup {
UniswapV2ERC20 testToken1;
UniswapV2ERC20 testToken2;
Users user;
bool completed;
bool notInitialLiquidityMint;

constructor() public {
testToken1 = new UniswapV2ERC20();
Expand All @@ -32,12 +32,9 @@ contract Setup {
function _init(uint amount1, uint amount2) internal {
testToken1.mint(address(user), amount1);
testToken2.mint(address(user), amount2);
completed = true;
}

function _between(uint val, uint low, uint high) internal pure returns(uint) {
return low + (val % (high-low +1));
}


}