forked from AmazingAng/WTF-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
842de3a
commit 4af6349
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/AaveV3Flashloan.sol"; | ||
|
||
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; | ||
|
||
contract UniswapV2FlashloanTest is Test { | ||
IWETH private weth = IWETH(WETH); | ||
|
||
AaveV3Flashloan private flashloan; | ||
|
||
function setUp() public { | ||
flashloan = new AaveV3Flashloan(); | ||
} | ||
|
||
function testFlashloan() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 1e18); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 100 * 1e18; | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
|
||
// 手续费不足,会revert | ||
function testFlashloanFail() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 4e16); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 100 * 1e18; | ||
// 手续费不足 | ||
vm.expectRevert(); | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/UniswapV2Flashloan.sol"; | ||
|
||
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; | ||
|
||
contract UniswapV2FlashloanTest is Test { | ||
IWETH private weth = IWETH(WETH); | ||
|
||
UniswapV2Flashloan private flashloan; | ||
|
||
function setUp() public { | ||
flashloan = new UniswapV2Flashloan(); | ||
} | ||
|
||
function testFlashloan() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 1e18); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 100 * 1e18; | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
|
||
// 手续费不足,会revert | ||
function testFlashloanFail() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 3e17); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 100 * 1e18; | ||
// 手续费不足 | ||
vm.expectRevert(); | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
import "../src/UniswapV3Flashloan.sol"; | ||
|
||
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; | ||
|
||
contract UniswapV2FlashloanTest is Test { | ||
IWETH private weth = IWETH(WETH); | ||
|
||
UniswapV3Flashloan private flashloan; | ||
|
||
function setUp() public { | ||
flashloan = new UniswapV3Flashloan(); | ||
} | ||
|
||
function testFlashloan() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 1e18); | ||
|
||
uint balBefore = weth.balanceOf(address(flashloan)); | ||
console2.logUint(balBefore); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 1 * 1e18; | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
|
||
// 手续费不足,会revert | ||
function testFlashloanFail() public { | ||
// 换weth,并转入flashloan合约,用做手续费 | ||
weth.deposit{value: 1e18}(); | ||
weth.transfer(address(flashloan), 1e17); | ||
// 闪电贷借贷金额 | ||
uint amountToBorrow = 100 * 1e18; | ||
// 手续费不足 | ||
vm.expectRevert(); | ||
flashloan.flashloan(amountToBorrow); | ||
} | ||
} |