add audit
Some checks failed
CI / Foundry project (push) Has been cancelled

This commit is contained in:
han
2025-02-12 19:57:09 +07:00
parent 878bd34ef6
commit 5726fc6b9a
15 changed files with 630 additions and 5 deletions

View File

@@ -0,0 +1,99 @@
// 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
}
}

51
test/testMultiSig.t.sol Normal file
View File

@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import {MultiSigWallet} from "../src/MultiSig.sol";
contract MultiSigWalletTest is Test {
MultiSigWallet multiSigWallet;
address user = address(0x123);
address user2 = address(0x456);
function setUp() public {
multiSigWallet = new MultiSigWallet(user, user2);
vm.deal(address(multiSigWallet), 10 ether);
vm.deal(user, 10 ether);
vm.deal(user2, 10 ether);
}
function testSetup() public {
address owner1 = multiSigWallet.owner1();
address owner2 = multiSigWallet.owner2();
assertEq(owner1, user);
assertEq(owner2, user2);
assertEq(address(multiSigWallet).balance, 10 ether);
}
function testUserInRelationshipWithBlockedProfileUnableToWithdraw() public {
uint256 initialMultiSigWalletBalance = address(multiSigWallet).balance;
uint256 initialUserBalance = address(user).balance;
uint256 withdrawBalance = initialMultiSigWalletBalance / 2;
vm.startPrank(user);
// submit tx
multiSigWallet.submitTransaction(address(user), withdrawBalance);
// approve tx
multiSigWallet.approveTransaction(0);
// execute
vm.expectRevert();
multiSigWallet.executeTransaction(0);
vm.stopPrank();
(address to, uint256 value, bool approvedByOwner1, bool approvedByOwner2, bool executed) = multiSigWallet.transactions(0);
assertEq(executed, false); // unable to execute because need both of approval, despite the other user is already blocked
assertEq(address(user).balance, initialUserBalance + withdrawBalance); // user should be able to withdraw their fund from multiSigWallet from a blocked profile
}
}

View File

@@ -94,6 +94,27 @@ contract SoulboundProfileNFTTest is Test {
assertEq(newTokenId, 0, "Token should be removed after blocking");
}
// audit
function testBlockedProfileMintAgain() public {
vm.prank(user);
soulboundNFT.mintProfile("Alice", 25, "ipfs://profileImage");
uint256 tokenId = soulboundNFT.profileToToken(user);
assertEq(tokenId, 1, "Token should exist before blocking");
vm.prank(owner);
soulboundNFT.blockProfile(user);
uint256 newTokenId = soulboundNFT.profileToToken(user);
assertEq(newTokenId, 0, "Token should be removed after blocking");
vm.prank(user);
vm.expectRevert();
// blocked profile should not be able to mint from the same wallet address again
soulboundNFT.mintProfile("Alice", 25, "ipfs://profileImage");
}
// end of audit
function testNonOwnerCannotBlockProfile() public {
vm.prank(user);
soulboundNFT.mintProfile("Alice", 25, "ipfs://profileImage");