Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosamorphing authored Nov 25, 2023
1 parent 842de3a commit 4af6349
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Languages/en/57_Flashloan/test/AaveV3Flashloan.t.sol
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);
}
}
38 changes: 38 additions & 0 deletions Languages/en/57_Flashloan/test/UniswapV2Flashloan.t.sol
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);
}
}
41 changes: 41 additions & 0 deletions Languages/en/57_Flashloan/test/UniswapV3Flashloan.t.sol
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);
}
}

0 comments on commit 4af6349

Please sign in to comment.