|
| 1 | +//SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +import {OrderContract} from "../../src/OrderContract.sol"; |
| 4 | +import {Test, console} from "forge-std/Test.sol"; |
| 5 | +import {A3AToken} from "../../src/A3Atoken.sol"; |
| 6 | + |
| 7 | + |
| 8 | +pragma solidity ^0.8.18; |
| 9 | + |
| 10 | + |
| 11 | +contract FuzzHandler is Test { |
| 12 | + |
| 13 | + A3AToken public tokenContract; |
| 14 | + OrderContract public orderContract; |
| 15 | + |
| 16 | + uint64 public orderIdCounter = 0; |
| 17 | + uint64[] public orderIdArray; |
| 18 | + |
| 19 | + constructor(address orderContractAddress, address tokenAddress) { |
| 20 | + orderContract = OrderContract(orderContractAddress); |
| 21 | + tokenContract = A3AToken(tokenAddress); |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + function proposeOrder(bytes32 promptHash, address userWalletAddress) external { |
| 26 | + if (userWalletAddress == address(0)) { |
| 27 | + return; |
| 28 | + } |
| 29 | + orderIdCounter++; |
| 30 | + vm.prank(address(orderContract)); |
| 31 | + tokenContract.mint(userWalletAddress, 1000 ether); |
| 32 | + vm.prank(userWalletAddress); |
| 33 | + tokenContract.approve(address(orderContract), 500 ether); |
| 34 | + vm.startPrank(address(5)); |
| 35 | + orderContract.proposeOrder(promptHash, userWalletAddress); |
| 36 | + vm.stopPrank(); |
| 37 | + orderIdCounter++; |
| 38 | + orderIdArray.push(orderIdCounter); |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + function proposeOrderAnswer(bytes32 answerHash, uint64 offerId, uint256 priceForOffer, address seller) external { |
| 45 | + if (seller == address(0)) { |
| 46 | + return; |
| 47 | + } |
| 48 | + if (orderIdArray.length == 0) { |
| 49 | + return; |
| 50 | + } |
| 51 | + uint64 offerID = orderIdArray[offerId % orderIdArray.length]; |
| 52 | + |
| 53 | + if (offerID == 0) { |
| 54 | + return; |
| 55 | + } |
| 56 | + if (orderContract.getOfferStatus(offerID) != OrderContract.OrderStatus.InProgress) { |
| 57 | + return; |
| 58 | + } |
| 59 | + vm.prank(address(5)); |
| 60 | + orderContract.proposeOrderAnswer(answerHash, offerID, priceForOffer, seller); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments