test: add foundry tests for EvidenceScoutTest.sol
Some checks are pending
CI / build-and-test (push) Waiting to run
CI / slither (push) Waiting to run

This commit is contained in:
evidence_scout 2026-04-19 09:11:34 +00:00
parent 4532e6d293
commit cac95f59c4

View File

@ -0,0 +1,117 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Test, console2} from "forge-std/Test.sol";
import {EvidenceScout} from "../contracts/EvidenceScout.sol";
import {RepositoryHelper} from "../contracts/helpers/RepositoryHelper.sol";
import {RepositoryInterface} from "../contracts/interfaces/RepositoryInterface.sol";
contract EvidenceScoutTest is Test {
EvidenceScout public scout;
RepositoryHelper public helper;
address public owner;
address public testRepository;
address public secondRepository;
function setUp() public {
owner = address(this);
scout = new EvidenceScout(owner);
helper = new RepositoryHelper();
testRepository = address(new MockRepository());
secondRepository = address(new MockRepository());
}
function test_RepositoryRegistration() public {
vm.startPrank(owner);
bool registered = scout.registerRepository(testRepository);
assertTrue(registered, "Repository should be registerable");
address[] memory repositories = scout.getRegisteredRepositories();
assertEq(repositories.length, 1, "Should have one registered repository");
assertEq(repositories[0], testRepository, "Registered repository address mismatch");
vm.stopPrank();
}
function testFuzz_RepositoryRegistration(address randomRepository) public {
vm.startPrank(owner);
bool registered = scout.registerRepository(randomRepository);
assertTrue(registered, "Random repository should be registerable");
vm.stopPrank();
}
function test_RepositoryInteraction() public {
vm.startPrank(owner);
scout.registerRepository(testRepository);
bytes32 testDataHash = keccak256(abi.encodePacked("TestEvidence"));
bool interactionResult = scout.interactWithRepository(testRepository, testDataHash);
assertTrue(interactionResult, "Repository interaction should succeed");
bytes32 retrievedHash = scout.getRepositoryInteractionHash(testRepository);
assertEq(retrievedHash, testDataHash, "Interaction hash should match");
vm.stopPrank();
}
function testRevert_UnauthorizedRepositoryInteraction() public {
address unauthorized = address(0x123);
vm.startPrank(unauthorized);
bytes32 testDataHash = keccak256(abi.encodePacked("UnauthorizedEvidence"));
vm.expectRevert("Unauthorized repository interaction");
scout.interactWithRepository(testRepository, testDataHash);
vm.stopPrank();
}
function test_MultipleRepositoryRegistration() public {
vm.startPrank(owner);
scout.registerRepository(testRepository);
scout.registerRepository(secondRepository);
address[] memory repositories = scout.getRegisteredRepositories();
assertEq(repositories.length, 2, "Should have two registered repositories");
vm.stopPrank();
}
function test_RepositoryRemoval() public {
vm.startPrank(owner);
scout.registerRepository(testRepository);
bool removed = scout.removeRepository(testRepository);
assertTrue(removed, "Repository should be removable");
address[] memory repositories = scout.getRegisteredRepositories();
assertEq(repositories.length, 0, "No repositories should remain after removal");
vm.stopPrank();
}
function testGas_RepositoryRegistration() public {
vm.startPrank(owner);
scout.registerRepository(testRepository);
vm.stopPrank();
}
function testGas_RepositoryInteraction() public {
vm.startPrank(owner);
scout.registerRepository(testRepository);
bytes32 testDataHash = keccak256(abi.encodePacked("TestEvidence"));
scout.interactWithRepository(testRepository, testDataHash);
vm.stopPrank();
}
}
contract MockRepository is RepositoryInterface {
mapping(bytes32 => bool) private _validatedHashes;
function validateHash(bytes32 dataHash) external returns (bool) {
_validatedHashes[dataHash] = true;
return true;
}
function getValidationStatus(bytes32 dataHash) external view returns (bool) {
return _validatedHashes[dataHash];
}
}