Skip to content

cypherpulse/checkmate-hardhat

Repository files navigation

Checkmate-Journal Hashing

Checkmate-Journal Hashing is a Solidity smart contract that allows users to securely store and manage hashes of their journal entries on the Ethereum blockchain. Each user can add new journal hashes, retrieve all their stored hashes, and check the total number of hashes they have submitted. This system provides integrity and traceability for journal data, ensuring that entries are tamper-proof and verifiable without revealing the actual content of the journals.

Introduction

Checkmate Journal Hashing is a smart contract project designed to securely store and manage journal entry hashes on the Ethereum blockchain. Each user can add their own journal hashes, retrieve all their hashes, and check the count of their entries. This ensures integrity and traceability for journal data without exposing the actual content.

Smart Contract Overview

  • Contract Name: JournalHash
  • Main Features:
    • Add a journal hash for the sender
    • Retrieve all journal hashes for any user
    • Get the count of journal hashes for any user
  • Security:
    • Only the sender can add their own hashes
    • All hashes are public (anyone can read them)

Hardhat Introduction

Hardhat is a development environment for Ethereum smart contracts. It provides tools for compiling, deploying, testing, and debugging contracts. Key features include:

  • Local test network (Hardhat Network)
  • TypeScript/JavaScript support
  • Plugin ecosystem (TypeChain, solidity-coverage, etc.)
  • Easy integration with ethers.js

Key Hardhat Commands

  • pnpm add --dev hardhat
    Installs Hardhat as a development dependency using pnpm.

  • npx hardhat init
    Initializes a new Hardhat project with sample files and configuration.

  • npx hardhat compile
    Compiles all smart contracts in the contracts/ directory and generates artifacts.

  • npx hardhat test
    Runs all tests in the test/ directory using Mocha and Chai.

  • npx hardhat node
    Starts a local Ethereum test network for development and testing.

  • npx hardhat run scripts/deploy.ts --network localhost
    Runs the deployment script on the specified network (e.g., local Hardhat node).

  • npx hardhat coverage
    Generates a test coverage report for your smart contracts.

  • npx hardhat console
    Opens an interactive console to interact with your contracts and network.

Testing Guide

All contract functions are covered by automated tests using Hardhat, Mocha, and Chai. Tests are located in the test/JournalHash.ts file.

How to Run All Tests

npx hardhat test

How to Run Tests for Each Function

  • addJournalHash
     npx hardhat test --grep "should add a journal hash for the sender"
    
  • getJournalHashes
     npx hardhat test --grep "should return all journal hashes for a user"
    
  • getJournalHashCount
     npx hardhat test --grep "should return the correct count of journal hashes"
    
  • Different users
     npx hardhat test --grep "should allow different users to store their own hashes"
    

Coverage

To see the percentage of code covered by tests:

npx hardhat coverage

Project Structure

contracts/           # Solidity smart contracts
artifacts/           # Compiled contract artifacts
cache/               # Hardhat cache files
test/                # Test files (TypeScript/JavaScript)
typechain-types/     # TypeChain generated types
scripts/             # Deployment and interaction scripts
hardhat.config.ts    # Hardhat configuration
.env                 # Environment variables (not committed)

.gitignore Recommendations

node_modules/
pnpm-lock.yaml
artifacts/
cache/
typechain-types/
.env
.DS_Store
Thumbs.db
.vscode/
.idea/
coverage/
*.log
build-info/

Getting Started

  1. Clone the repository
  2. Install dependencies: pnpm install
  3. Compile contracts: npx hardhat compile
  4. Run tests: npx hardhat test
  5. Check coverage: npx hardhat coverage

For questions or contributions, feel free to open an issue or pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors