Skip to content

Commit

Permalink
Use correct exploiter address in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JaniAnttonen committed Nov 3, 2022
1 parent 08dddff commit 5d66dd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/BFKLoanMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ contract BFKLoanMarket is Owned(msg.sender) {

function _loan(address loanTaker, uint256 collateral) internal {
require(collateral > 0, "Can't loan with 0 collateral!");
require(
jungfrau.balanceOf(address(this)) > 0,
"No Jungfrau to loan =("
);
uint256 latestPrice = latestAnswer();
loans[loanTaker] = Loan({
bfkAmount: collateral,
Expand Down Expand Up @@ -86,7 +90,6 @@ contract BFKLoanMarket is Owned(msg.sender) {
);
loans[loanTaker] = Loan({bfkAmount: 0, openingPrice: 0});
jungfrau.transferFrom(liquidator, address(this), repayment);
console.log("Tanne asti ei edes paasta");

uint256 liquidatorReward = (repayment / price) * 10**8;
if (blemflarck.balanceOf(address(this)) < liquidatorReward) {
Expand Down
14 changes: 11 additions & 3 deletions src/test/BFKLoanMarket.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ contract BFKLoanMarketTest is Test {
uint256 public constant AMOUNT = 42 * 10**18;

function setUp() public {
address exploiter = 0x7d7356bF6Ee5CDeC22B216581E48eCC700D0497A;

vm.startPrank(exploiter);

priceOracle = new MockPriceOracle();
blemflarck = new Blemflarck();
jungfrau = new Jungfrau();
Expand All @@ -38,13 +42,16 @@ contract BFKLoanMarketTest is Test {

// Fund the bfkLoanMarket with loanable jungfrau
jungfrau.mint(address(bfkLoanMarket), AMOUNT * 2);

// Fund the liquidator with jungfrau
jungfrau.mint(msg.sender, AMOUNT);

vm.stopPrank();
}

function testLoansAndAttack() public {
setUp();

// Fund the liquidator with jungfrau
jungfrau.mint(msg.sender, AMOUNT);
address exploiter = 0x7d7356bF6Ee5CDeC22B216581E48eCC700D0497A;

assertEq(blemflarck.balanceOf(address(this)), AMOUNT);

Expand All @@ -63,6 +70,7 @@ contract BFKLoanMarketTest is Test {
bfkLoanMarket.liquidate(address(this), msg.sender, AMOUNT / 3);

// Should be able to liquidate by updating the oracle override
vm.prank(exploiter);
bfkLoanMarket.updatePrice(1);

// Approve the loan contract to move the liquidator's funds
Expand Down

0 comments on commit 5d66dd2

Please sign in to comment.