-
Notifications
You must be signed in to change notification settings - Fork 275
/
test_flashloan.py
36 lines (25 loc) · 1.18 KB
/
test_flashloan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# NOTE: The following tests begin by transferring assets to the deployed flashloan
# contract. this ensures that the tests pass with the base Flashloan implementation,
# i.e. one that does not implement any custom logic.
# The initial transfer should be removed prior to testing your final implementation.
def test_eth_flashloan(accounts, ETH, flashloan):
"""
Test a flashloan that borrows Ethereum.
"""
# transfer ether to the flashloan contract
accounts[0].transfer(flashloan, "2 ether")
flashloan.flashloan(ETH, {"from": accounts[0]})
def test_dai_flashloan(Contract, accounts, DAI, flashloan):
"""
Test a flashloan that borrows DAI.
To use a different asset, swap DAI with any of the fixture names in `tests/conftest.py`
"""
# purchase DAI on uniswap
uniswap_dai = Contract.from_explorer("0x2a1530C4C41db0B0b2bB646CB5Eb1A67b7158667")
uniswap_dai.ethToTokenSwapInput(
1, 10000000000, {"from": accounts[0], "value": "2 ether"}
)
# transfer DAI to the flashloan contract
balance = DAI.balanceOf(accounts[0])
DAI.transfer(flashloan, balance, {"from": accounts[0]})
flashloan.flashloan(DAI, {"from": accounts[0]})