Skip to main content

Overview

Comprehensive testing examples for all ZKScore smart contracts using Hardhat and best practices.

Testing Suite

const { expect } = require('chai');
const { ethers } = require('hardhat');

describe('ZKScore Contract Suite', function() {
  let identitySBT, scoreCalculator, achievementRegistry;
  let owner, user1, user2;
  
  beforeEach(async function() {
    [owner, user1, user2] = await ethers.getSigners();
    
    // Deploy contracts
    const IdentitySBT = await ethers.getContractFactory('IdentitySBT');
    identitySBT = await IdentitySBT.deploy();
    
    const ScoreCalculator = await ethers.getContractFactory('ScoreCalculator');
    scoreCalculator = await ScoreCalculator.deploy();
    
    const AchievementRegistry = await ethers.getContractFactory('AchievementRegistry');
    achievementRegistry = await AchievementRegistry.deploy();
  });
  
  it('Should mint and activate identity', async function() {
    await identitySBT.mint(user1.address, 'alice.zks', 'metadata');
    await identitySBT.connect(user1).activate(1);
    
    expect(await identitySBT.isActivated(1)).to.equal(true);
  });
  
  it('Should calculate score', async function() {
    await scoreCalculator.calculateScore(user1.address);
    const score = await scoreCalculator.getScore(user1.address);
    
    expect(score).to.be.gte(0);
  });
});

Best Practices

  1. Comprehensive Coverage: Test all contract functions
  2. Edge Cases: Test boundary conditions
  3. Gas Optimization: Monitor gas usage
  4. Integration Tests: Test contract interactions