100 lines
3.2 KiB
Solidity
100 lines
3.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.19;
|
|
|
|
import "forge-std/Test.sol";
|
|
import "../src/SoulboundProfileNFT.sol";
|
|
import "../src/LikeRegistry.sol";
|
|
import {MultiSigWallet} from "../src/MultiSig.sol";
|
|
|
|
contract LikeRegistryTest is Test {
|
|
SoulboundProfileNFT soulboundNFT;
|
|
LikeRegistry likeRegistry;
|
|
address user = address(0x123);
|
|
address user2 = address(0x456);
|
|
address owner = address(this); // Test contract acts as the owner
|
|
|
|
function setUp() public {
|
|
soulboundNFT = new SoulboundProfileNFT();
|
|
likeRegistry = new LikeRegistry(address(soulboundNFT));
|
|
|
|
vm.deal(user, 10 ether);
|
|
vm.deal(user2, 10 ether);
|
|
}
|
|
|
|
function testGetMatches() public {
|
|
vm.prank(user);
|
|
address[] memory matches = likeRegistry.getMatches();
|
|
address[] memory empty;
|
|
assertEq(matches, empty);
|
|
}
|
|
|
|
function testMatchMiscalculation() public {
|
|
uint256 likeAmount = 1 ether;
|
|
uint256 FIXEDFEE = 10;
|
|
uint256 fees = ((likeAmount + likeAmount) * FIXEDFEE) / 100;
|
|
uint multiSigFund = likeAmount + likeAmount - fees;
|
|
|
|
// user mint profile
|
|
vm.prank(user);
|
|
soulboundNFT.mintProfile("Alice", 25, "ipfs://profileImage");
|
|
uint256 userTokenId = soulboundNFT.profileToToken(user);
|
|
assertEq(userTokenId, 1, "Token ID should be 1");
|
|
|
|
// user2 mint profile
|
|
vm.prank(user2);
|
|
soulboundNFT.mintProfile("Bob", 27, "ipfs://profileImage");
|
|
uint256 user2TokenId = soulboundNFT.profileToToken(user2);
|
|
assertEq(user2TokenId, 2, "Token ID should be 2");
|
|
|
|
// likeRegistry has 0 ether
|
|
assertEq(address(likeRegistry).balance, 0);
|
|
|
|
// user likes user2 with 1 eth
|
|
vm.prank(user);
|
|
likeRegistry.likeUser{value: likeAmount}(user2);
|
|
|
|
// user2 likes uer with 1 eth and match
|
|
vm.prank(user2);
|
|
address multiSigAddress = likeRegistry.likeUser{value: likeAmount}(user);
|
|
assert(multiSigAddress != address(0));
|
|
|
|
// get user matches
|
|
vm.prank(user);
|
|
address[] memory userMatches = likeRegistry.getMatches();
|
|
assertEq(userMatches.length, 1);
|
|
assertEq(userMatches[0], address(user2));
|
|
|
|
assertEq(address(multiSigAddress).balance, multiSigFund); // giving a like for each user 1 ether should give the wallet 1.8 ether
|
|
assertEq(address(likeRegistry).balance, fees); // likeRegistry should have balance equal to `fees`, and send the rest of fund to the MultisigWallet
|
|
}
|
|
|
|
function testSendMoneyToLikeRegistry() public {
|
|
uint256 sendAmount = 1 ether;
|
|
uint256 initialLikeRegistryFund = address(likeRegistry).balance;
|
|
|
|
// user send money directly to like registry contract
|
|
vm.prank(user);
|
|
(bool success,) = payable(address(likeRegistry)).call{value: sendAmount}("");
|
|
uint256 likeRegistryFundAfterFunded = address(likeRegistry).balance;
|
|
|
|
assertEq(success, true);
|
|
assertEq(initialLikeRegistryFund, 0);
|
|
assertEq(likeRegistryFundAfterFunded, sendAmount);
|
|
|
|
// check userBalances
|
|
uint256 userUserBalance = likeRegistry.userBalances(user);
|
|
assertEq(userUserBalance, sendAmount); // sending money directly to contract should adjust userBalance to reflect the address fund
|
|
|
|
// owner try to withdraw money
|
|
vm.prank(owner);
|
|
vm.expectRevert();
|
|
likeRegistry.withdrawFees(); // the contract will assume that there is no fees to withdraw
|
|
|
|
// try to withdraw money
|
|
vm.prank(user);
|
|
vm.expectRevert();
|
|
likeRegistry.withdrawFees(); // there is no withdraw function for user
|
|
}
|
|
}
|
|
|