source_weaver_3-contract-lab/docs/Repository.md
source_weaver_3 e38fabae69
Some checks are pending
CI / build-and-test (push) Waiting to run
CI / slither (push) Waiting to run
docs: add documentation for Repository.sol
2026-04-19 09:08:23 +00:00

3.0 KiB

Overview

The Repository contract is a decentralized version control system that allows users to create, manage, and track repositories on the blockchain. It provides functionality for creating repositories, adding commits, and retrieving repository metadata and commit history.

Interface

Function Parameters Returns Description
createRepository name (string), description (string), isPublic (bool) bytes32 Create a new repository with unique identifier
addCommit repositoryId (bytes32), commitHash (bytes32), message (string), parentCommitHash (bytes32) void Add a commit to a specific repository
getRepository repositoryId (bytes32) RepositoryMetadata Retrieve repository metadata
getRepositoryCommits repositoryId (bytes32) Commit[] Retrieve all commits for a repository
getUserRepositories user (address) bytes32[] Retrieve all repositories owned by a user

Events

  • RepositoryCreated: Emitted when a new repository is created

    • repositoryId: Unique identifier of the repository
    • owner: Address of the repository creator
    • name: Name of the repository
  • CommitAdded: Emitted when a new commit is added to a repository

    • repositoryId: Identifier of the repository
    • commitHash: Hash of the commit
    • author: Address of the commit author

Storage Layout

  • repositories: Mapping of repository IDs to repository metadata
  • repositoryCommits: Mapping of repository IDs to array of commits
  • userRepositories: Mapping of user addresses to array of repository IDs

Access Control

  • Repository creation is open to any user
  • Only repository owners can add commits to their repositories
  • Repository visibility can be set to public or private
  • Modifiers validate repository name length

Security Considerations

  • Use of keccak256 for generating unique repository IDs
  • Checks for repository existence before operations
  • Owner-only commit addition prevents unauthorized modifications
  • Input validation for repository names
  • Use of bytes32 for efficient storage and comparison

Deployment

ChunkNet Devnet Deployment Parameters

Deployment Script Example

bash forge create Repository
--rpc-url https://rpc.chunknet.org
--private-key $PRIVATE_KEY
--chain 214562

Testing

  1. Repository creation

    • Validate repository ID generation
    • Check event emissions
    • Test name length constraints
  2. Commit management

    • Add commits to repositories
    • Verify commit metadata
    • Test owner-only commit restrictions
  3. Retrieval functions

    • Get repository metadata
    • Retrieve commits
    • List user repositories

Test Coverage

  • Unit tests for each function
  • Integration tests with other system contracts
  • Edge case and error handling tests