Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ test-results/
playwright-report/
.playwright/
.hardhat-node.pid
.vite-server.pid
# Note: test/e2e/fixtures/deployment.json is tracked for testing purposes

# Test results (generated)
test/e2e/fixtures/setup-results.json

# Temporary logs
/tmp/*.log
49 changes: 49 additions & 0 deletions hardhat.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: {
compilers: [
{
version: "0.8.0",
settings: {
viaIR: false,
optimizer: {
enabled: true,
runs: 200,
},
},
},
{
version: "0.8.20",
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200,
},
},
}
],
// The following overrides ensure that contracts with "Stack too deep" errors are compiled with viaIR enabled.
// AddressClaim.sol requires viaIR to compile due to stack depth issues.
overrides: {
"contracts/AddressClaim.sol": {
version: "0.8.20",
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200,
},
},
},
}
},
paths: {
sources: "./contracts",
tests: "./test/hardhat",
cache: "./cache",
artifacts: "./artifacts"
}
};
21 changes: 0 additions & 21 deletions hardhat.config.js

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.0.0",
"description": "<div align=\"center\"> <p> <img src=\"https://pbs.twimg.com/media/DOZbENEXkAA2EMr.png\" width=\"250\" /> </p> <p> ✨ Censorship immune, Decentralised Human Network & Identity Platform ✨ </p> <p> </p> </div>",
"main": "index.js",
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "type": "module" declaration has been removed from package.json, which changes the entire project's module system from ES modules to CommonJS. This is a significant change that affects all JavaScript files in the project. While the PR description mentions this was needed to fix ES module conflicts with test files, this could break other parts of the codebase that expect ES module syntax. Consider renaming test files to .cjs instead of changing the project-wide module system.

Suggested change
"main": "index.js",
"main": "index.js",
"type": "module",

Copilot uses AI. Check for mistakes.
"type": "module",
"directories": {
"test": "test"
},
Expand All @@ -24,7 +23,10 @@
"test:e2e:simple": "playwright test --config=playwright.config.simple.js",
"test:e2e:web3": "bash scripts/run-all-tests-web3.sh",
"test:e2e:all": "bash scripts/run-all-tests-web3.sh",
"test:setup": "bash scripts/setup-test-env.sh"
"test:setup": "bash scripts/setup-test-env.sh",
"test:comprehensive": "bash scripts/run-comprehensive-tests.sh",
"test:setup-network": "hardhat run test/e2e/setup/setup-user-network.cjs --network localhost",
"test:generate-report": "node test/e2e/helpers/generate-report.cjs"
},
"keywords": [],
"author": "",
Expand Down
22 changes: 12 additions & 10 deletions playwright.config.js β†’ playwright.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ export default defineConfig({
],

// Web server configuration - start dev server before tests
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
stdout: 'ignore',
stderr: 'pipe',
},
// Commented out since the test runner script already starts the server
// webServer: {
// command: 'npm run dev',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// timeout: 120 * 1000,
// stdout: 'ignore',
// stderr: 'pipe',
// },

// Global setup and teardown
globalSetup: require.resolve('./test/e2e/setup/global-setup.js'),
globalTeardown: require.resolve('./test/e2e/setup/global-teardown.js'),
// Commented out since the test runner script handles Hardhat and Vite setup
// globalSetup: require.resolve('./test/e2e/setup/global-setup.cjs'),
// globalTeardown: require.resolve('./test/e2e/setup/global-teardown.cjs'),
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
185 changes: 185 additions & 0 deletions scripts/run-comprehensive-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/bin/bash

###############################################################################
# Comprehensive Test Runner for Pocketbook
#
# This script runs the complete test suite including:
# 1. Contract compilation
# 2. Hardhat node setup
# 3. Contract deployment
# 4. User network configuration
# 5. E2E test execution
# 6. Report generation
###############################################################################

set -e # Exit on any error

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Project root
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_ROOT"

echo -e "${BLUE}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "β•‘ β•‘"
echo "β•‘ Pocketbook Comprehensive Test Suite Runner β•‘"
echo "β•‘ β•‘"
echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•"
echo -e "${NC}\n"

# Cleanup function
cleanup() {
echo -e "\n${YELLOW}🧹 Cleaning up...${NC}"

# Kill Hardhat node if running
if [ -f .hardhat-node.pid ]; then
PID=$(cat .hardhat-node.pid)
if ps -p $PID > /dev/null 2>&1; then
echo " Stopping Hardhat node (PID: $PID)"
kill $PID 2>/dev/null || true
sleep 2
fi
rm -f .hardhat-node.pid
fi

# Kill dev server if running
if [ -f .vite-server.pid ]; then
PID=$(cat .vite-server.pid)
if ps -p $PID > /dev/null 2>&1; then
echo " Stopping Vite dev server (PID: $PID)"
kill $PID 2>/dev/null || true
sleep 2
fi
rm -f .vite-server.pid
fi

echo -e "${GREEN} βœ“ Cleanup complete${NC}"
}

# Register cleanup on exit
trap cleanup EXIT INT TERM

# Step 1: Install dependencies (if needed)
echo -e "${BLUE}πŸ“¦ Step 1: Checking dependencies...${NC}"
if [ ! -d "node_modules" ]; then
echo " Installing npm packages..."
npm install
else
echo -e "${GREEN} βœ“ Dependencies already installed${NC}"
fi

# Step 2: Compile contracts
echo -e "\n${BLUE}πŸ”¨ Step 2: Compiling smart contracts...${NC}"
npx hardhat compile
echo -e "${GREEN} βœ“ Contracts compiled${NC}"

# Step 3: Start Hardhat node
echo -e "\n${BLUE}πŸš€ Step 3: Starting Hardhat local node...${NC}"
npx hardhat node > /tmp/hardhat.log 2>&1 &
HARDHAT_PID=$!
echo $HARDHAT_PID > .hardhat-node.pid
echo " Hardhat node PID: $HARDHAT_PID"

# Wait for Hardhat to start
echo " Waiting for Hardhat node to be ready..."
for i in {1..30}; do
if grep -q "Started HTTP and WebSocket JSON-RPC server" /tmp/hardhat.log 2>/dev/null; then
echo -e "${GREEN} βœ“ Hardhat node is ready${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED} βœ— Hardhat node failed to start${NC}"
cat /tmp/hardhat.log
exit 1
fi
sleep 1
done

# Step 4: Deploy contracts
echo -e "\n${BLUE}🚒 Step 4: Deploying contracts to local network...${NC}"
npx hardhat run test/e2e/setup/deploy-contracts.cjs --network localhost
echo -e "${GREEN} βœ“ Contracts deployed${NC}"

# Step 5: Setup user network
echo -e "\n${BLUE}πŸ‘₯ Step 5: Configuring test user network...${NC}"
npx hardhat run test/e2e/setup/setup-user-network.cjs --network localhost
echo -e "${GREEN} βœ“ User network configured${NC}"

# Step 6: Start dev server
echo -e "\n${BLUE}🌐 Step 6: Starting Vite dev server...${NC}"
npm run dev > /tmp/vite.log 2>&1 &
VITE_PID=$!
echo $VITE_PID > .vite-server.pid
echo " Vite server PID: $VITE_PID"

# Wait for Vite to start
echo " Waiting for dev server to be ready..."
for i in {1..30}; do
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo -e "${GREEN} βœ“ Dev server is ready${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED} βœ— Dev server failed to start${NC}"
cat /tmp/vite.log
exit 1
fi
sleep 1
done

# Step 7: Run E2E tests
echo -e "\n${BLUE}πŸ§ͺ Step 7: Running E2E test suite...${NC}"
echo " This may take several minutes..."

# Run Playwright tests with explicit output paths
if npx playwright test --reporter=list --reporter=json --reporter=html --output=test-results; then
echo -e "${GREEN} βœ“ Tests completed${NC}"
TEST_STATUS="passed"
else
echo -e "${YELLOW} ⚠ Some tests may have failed${NC}"
TEST_STATUS="completed_with_errors"
fi

# Step 8: Generate reports
echo -e "\n${BLUE}πŸ“Š Step 8: Generating test reports...${NC}"
node test/e2e/helpers/generate-report.cjs
echo -e "${GREEN} βœ“ Reports generated${NC}"

# Step 9: Display summary
echo -e "\n${BLUE}"
echo "╔════════════════════════════════════════════════════════════╗"
echo "β•‘ Test Run Summary β•‘"
echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•"
echo -e "${NC}"

echo -e "Status: ${GREEN}${TEST_STATUS}${NC}"
echo ""
echo "πŸ“ Generated Artifacts:"
echo " - HTML Report: test_results/test-report.html"
echo " - Markdown Report: test_results/test-report.md"
echo " - Playwright Report: playwright-report/index.html"
echo " - Screenshots: screenshots/e2e/*.png"
echo " - Test Results: test-results/*.json"
echo ""

if [ "$TEST_STATUS" = "passed" ]; then
echo -e "${GREEN}✨ All tests completed successfully!${NC}"
else
echo -e "${YELLOW}⚠️ Test run completed with some issues. Check reports for details.${NC}"
fi

echo ""
echo "To view the HTML report, run:"
echo " open test_results/test-report.html"
echo ""
echo "To view the Playwright report, run:"
echo " npm run test:e2e:report"
echo ""

exit 0
18 changes: 18 additions & 0 deletions src/config/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ export const NETWORKS = {
contractAddress: import.meta.env.VITE_CONTRACT_ADDRESS_MUMBAI || null,
handleRegistryAddress: import.meta.env.VITE_HANDLE_REGISTRY_ADDRESS_MUMBAI || null,
isTestnet: true
},

// Hardhat Local Network (for testing)
31337: {
chainId: 31337,
chainIdHex: '0x7a69',
name: 'Hardhat',
shortName: 'Hardhat',
rpcUrl: 'http://127.0.0.1:8545',
blockExplorer: null,
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18
},
contractAddress: import.meta.env.VITE_CONTRACT_ADDRESS_HARDHAT || '0x5FbDB2315678afecb367f032d93F642f64180aa3',
handleRegistryAddress: import.meta.env.VITE_HANDLE_REGISTRY_ADDRESS_HARDHAT || null,
isTestnet: true
}
};

Expand Down
Loading