function likeUser(address liked) external payable {
likes[msg.sender][liked] = true;
emit Liked(msg.sender, liked);
if (likes[liked][msg.sender]) {
matches[msg.sender].push(liked);
matches[liked].push(msg.sender);
emit Matched(msg.sender, liked);
matchRewards(liked, msg.sender);
}
}
contract LikeRegistryTest is Test {
LikeRegistry public likeRegistry;
SoulboundProfileNFT public profileNFT;
address public alice = address(1);
address public bob = address(2);
event Liked(address indexed liker, address indexed liked);
event Matched(address indexed user1, address indexed user2);
function setUp() public {
profileNFT = new SoulboundProfileNFT();
likeRegistry = new LikeRegistry(address(profileNFT));
vm.prank(alice);
profileNFT.mintProfile("Alice", 25, "alice_uri");
vm.prank(bob);
profileNFT.mintProfile("Bob", 28, "bob_uri");
}
function testIncorrectEventOrderAndBalances() public {
vm.deal(alice, 2 ether);
vm.deal(bob, 2 ether);
vm.startPrank(alice);
likeRegistry.likeUser{value: 1 ether}(bob);
assertEq(likeRegistry.userBalances(alice), 0, "User balance should be updated");
vm.stopPrank();
vm.startPrank(bob);
vm.expectEmit(true, true, false, true);
emit Liked(bob, alice);
vm.expectEmit(true, true, false, true);
emit Matched(bob, alice);
likeRegistry.likeUser{value: 1 ether}(alice);
vm.stopPrank();
address[] memory aliceMatches = likeRegistry.getMatches();
assertEq(aliceMatches.length, 1, "Alice should have one match");
}
function testLikeWithoutMatch() public {
vm.deal(alice, 2 ether);
uint256 initialBalance = address(likeRegistry).balance;
vm.prank(alice);
likeRegistry.likeUser{value: 1 ether}(bob);
assertEq(address(likeRegistry).balance, initialBalance + 1 ether, "Contract should receive ETH");
assertEq(likeRegistry.userBalances(alice), 0, "User balance should be updated");
}
}
function likeUser(address liked) external payable {
userBalances[msg.sender] += msg.value;
if (likes[liked][msg.sender]) {
likes[msg.sender][liked] = true;
matches[msg.sender].push(liked);
matches[liked].push(msg.sender);
emit Matched(msg.sender, liked);
matchRewards(liked, msg.sender);
} else {
likes[msg.sender][liked] = true;
emit Liked(msg.sender, liked);
}
}