|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import "forge-std/Test.sol"; |
| 5 | +import "../../src/interfaces/IPackageRegistry.sol"; |
| 6 | + |
| 7 | +contract MockPackageRegistry is IPackageRegistry { |
| 8 | + mapping(bytes32 => string) private packages; |
| 9 | + |
| 10 | + function publish(string calldata name, string calldata version, string calldata manifestURI) external { |
| 11 | + bytes32 key = keccak256(abi.encodePacked(name, version)); |
| 12 | + packages[key] = manifestURI; |
| 13 | + } |
| 14 | + |
| 15 | + function getPackageURI(string calldata name, string calldata version) external view returns (string memory) { |
| 16 | + bytes32 key = keccak256(abi.encodePacked(name, version)); |
| 17 | + return packages[key]; |
| 18 | + } |
| 19 | + |
| 20 | + function packageExists(string calldata name, string calldata version) external view returns (bool) { |
| 21 | + bytes32 key = keccak256(abi.encodePacked(name, version)); |
| 22 | + return bytes(packages[key]).length > 0; |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +contract IPackageRegistryTest is Test { |
| 27 | + MockPackageRegistry registry; |
| 28 | + |
| 29 | + function setUp() public { |
| 30 | + registry = new MockPackageRegistry(); |
| 31 | + } |
| 32 | + |
| 33 | + function testPublishPackage() public { |
| 34 | + registry.publish("safe-math-lib", "1.0.0", "ipfs://QmTest123"); |
| 35 | + assertTrue(registry.packageExists("safe-math-lib", "1.0.0")); |
| 36 | + } |
| 37 | + |
| 38 | + function testGetPackageURI() public { |
| 39 | + string memory manifestURI = "ipfs://QmTest123"; |
| 40 | + registry.publish("wallet", "2.1.0", manifestURI); |
| 41 | + |
| 42 | + assertEq(registry.getPackageURI("wallet", "2.1.0"), manifestURI); |
| 43 | + } |
| 44 | + |
| 45 | + function testPackageNotExists() public { |
| 46 | + assertFalse(registry.packageExists("nonexistent", "1.0.0")); |
| 47 | + } |
| 48 | +} |
0 commit comments