Files
aitbc/contracts/scripts/verify-phase4-modular-contracts.js
AITBC System b033923756 chore: normalize file permissions across repository
- Remove executable permissions from configuration files (.editorconfig, .env.example, .gitignore)
- Remove executable permissions from documentation files (README.md, LICENSE, SECURITY.md)
- Remove executable permissions from web assets (HTML, CSS, JS files)
- Remove executable permissions from data files (JSON, SQL, YAML, requirements.txt)
- Remove executable permissions from source code files across all apps
- Add executable permissions to Python
2026-03-08 11:26:18 +01:00

261 lines
13 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ethers } from "hardhat";
import { Contract } from "ethers";
async function main() {
console.log("🔍 Verifying Phase 4 Modular Smart Contracts...");
try {
// Read deployment addresses
const fs = require('fs');
const deploymentAddresses = JSON.parse(fs.readFileSync('./deployment-addresses-phase4.json', 'utf8'));
console.log("📋 Deployment addresses loaded:");
console.log("ContractRegistry:", deploymentAddresses.ContractRegistry);
console.log("TreasuryManager:", deploymentAddresses.TreasuryManager);
console.log("RewardDistributor:", deploymentAddresses.RewardDistributor);
console.log("PerformanceAggregator:", deploymentAddresses.PerformanceAggregator);
console.log("StakingPoolFactory:", deploymentAddresses.StakingPoolFactory);
console.log("DAOGovernanceEnhanced:", deploymentAddresses.DAOGovernanceEnhanced);
// Get contract instances
const contractRegistry = await ethers.getContractAt("ContractRegistry", deploymentAddresses.ContractRegistry);
const treasuryManager = await ethers.getContractAt("TreasuryManager", deploymentAddresses.TreasuryManager);
const rewardDistributor = await ethers.getContractAt("RewardDistributor", deploymentAddresses.RewardDistributor);
const performanceAggregator = await ethers.getContractAt("PerformanceAggregator", deploymentAddresses.PerformanceAggregator);
const stakingPoolFactory = await ethers.getContractAt("StakingPoolFactory", deploymentAddresses.StakingPoolFactory);
const daoGovernanceEnhanced = await ethers.getContractAt("DAOGovernanceEnhanced", deploymentAddresses.DAOGovernanceEnhanced);
const aiToken = await ethers.getContractAt("AIToken", deploymentAddresses.AIToken);
console.log("\n🧪 Running verification tests...");
// Test 1: Contract Registry Integration
console.log("\n1⃣ Testing Contract Registry Integration...");
const treasuryAddress = await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("TreasuryManager")));
const rewardAddress = await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("RewardDistributor")));
const performanceAddress = await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("PerformanceAggregator")));
const stakingAddress = await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("StakingPoolFactory")));
const daoAddress = await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("DAOGovernanceEnhanced")));
console.log("✅ TreasuryManager registry lookup:", treasuryAddress === deploymentAddresses.TreasuryManager ? "PASS" : "FAIL");
console.log("✅ RewardDistributor registry lookup:", rewardAddress === deploymentAddresses.RewardDistributor ? "PASS" : "FAIL");
console.log("✅ PerformanceAggregator registry lookup:", performanceAddress === deploymentAddresses.PerformanceAggregator ? "PASS" : "FAIL");
console.log("✅ StakingPoolFactory registry lookup:", stakingAddress === deploymentAddresses.StakingPoolFactory ? "PASS" : "FAIL");
console.log("✅ DAOGovernanceEnhanced registry lookup:", daoAddress === deploymentAddresses.DAOGovernanceEnhanced ? "PASS" : "FAIL");
// Test 2: TreasuryManager Functionality
console.log("\n2⃣ Testing TreasuryManager Functionality...");
const devBudget = await treasuryManager.getBudgetBalance("development");
const marketingBudget = await treasuryManager.getBudgetBalance("marketing");
const operationsBudget = await treasuryManager.getBudgetBalance("operations");
const rewardsBudget = await treasuryManager.getBudgetBalance("rewards");
console.log("✅ Development budget:", ethers.utils.formatEther(devBudget), "AITBC");
console.log("✅ Marketing budget:", ethers.utils.formatEther(marketingBudget), "AITBC");
console.log("✅ Operations budget:", ethers.utils.formatEther(operationsBudget), "AITBC");
console.log("✅ Rewards budget:", ethers.utils.formatEther(rewardsBudget), "AITBC");
const treasuryStats = await treasuryManager.getTreasuryStats();
console.log("✅ Treasury total budget:", ethers.utils.formatEther(treasuryStats.totalBudget), "AITBC");
console.log("✅ Treasury allocated amount:", ethers.utils.formatEther(treasuryStats.allocatedAmount), "AITBC");
console.log("✅ Treasury available balance:", ethers.utils.formatEther(treasuryStats.availableBalance), "AITBC");
// Test 3: RewardDistributor Functionality
console.log("\n3⃣ Testing RewardDistributor Functionality...");
const rewardStats = await rewardDistributor.getRewardStats();
console.log("✅ Total reward pools:", rewardStats.totalPools.toString());
console.log("✅ Active reward pools:", rewardStats.activePools.toString());
console.log("✅ Total claims:", rewardStats.totalClaims.toString());
console.log("✅ Total distributed:", ethers.utils.formatEther(rewardStats.totalDistributed), "AITBC");
const activePoolIds = await rewardDistributor.getActivePoolIds();
console.log("✅ Active pool IDs:", activePoolIds.map(id => id.toString()));
if (activePoolIds.length > 0) {
const poolBalance = await rewardDistributor.getPoolBalance(activePoolIds[0]);
console.log("✅ First pool balance:", ethers.utils.formatEther(poolBalance), "AITBC");
}
// Test 4: PerformanceAggregator Functionality
console.log("\n4⃣ Testing PerformanceAggregator Functionality...");
const performanceTiers = await performanceAggregator.getAllPerformanceTiers();
console.log("✅ Performance tiers count:", performanceTiers.length);
for (let i = 0; i < Math.min(performanceTiers.length, 3); i++) {
const tierId = performanceTiers[i];
const tierDetails = await performanceAggregator.getPerformanceTier(tierId);
console.log(`✅ Tier ${tierId}: ${tierDetails.name} (${tierDetails.minScore}-${tierDetails.maxScore}, ${tierDetails.apyMultiplier / 100}x APY)`);
}
// Test 5: StakingPoolFactory Functionality
console.log("\n5⃣ Testing StakingPoolFactory Functionality...");
const factoryStats = await stakingPoolFactory.getFactoryStats();
console.log("✅ Total pools:", factoryStats.totalPools.toString());
console.log("✅ Active pools:", factoryStats.activePools.toString());
console.log("✅ Total staked:", ethers.utils.formatEther(factoryStats.totalStaked), "AITBC");
console.log("✅ Total stakers:", factoryStats.totalStakers.toString());
console.log("✅ Total positions:", factoryStats.totalPositions.toString());
const activePoolIds2 = await stakingPoolFactory.getActivePoolIds();
console.log("✅ Active pool IDs:", activePoolIds2.map(id => id.toString()));
for (let i = 0; i < Math.min(activePoolIds2.length, 3); i++) {
const poolId = activePoolIds2[i];
const poolDetails = await stakingPoolFactory.getPoolDetails(poolId);
const poolPerformance = await stakingPoolFactory.getPoolPerformance(poolId);
console.log(`✅ Pool ${poolId}: ${poolDetails.poolName} (${poolDetails.currentAPY / 100}% APY, Performance: ${poolPerformance / 100})`);
}
// Test 6: DAOGovernanceEnhanced Functionality
console.log("\n6⃣ Testing DAOGovernanceEnhanced Functionality...");
const daoVersion = await daoGovernanceEnhanced.getVersion();
console.log("✅ DAO version:", daoVersion.toString());
const minStake = await daoGovernanceEnhanced.minStakeAmount();
console.log("✅ Minimum stake:", ethers.utils.formatEther(minStake), "AITBC");
const totalStaked = await daoGovernanceEnhanced.totalStaked();
console.log("✅ Total staked:", ethers.utils.formatEther(totalStaked), "AITBC");
const activeProposals = await daoGovernanceEnhanced.getActiveProposals();
console.log("✅ Active proposals:", activeProposals.length);
// Test 7: Cross-Contract Integration
console.log("\n7⃣ Testing Cross-Contract Integration...");
// Test TreasuryManager -> RewardDistributor integration
const treasuryRegistry = await treasuryManager.registry();
console.log("✅ TreasuryManager registry address:", treasuryRegistry);
// Test RewardDistributor -> PerformanceAggregator integration
const rewardRegistry = await rewardDistributor.registry();
console.log("✅ RewardDistributor registry address:", rewardRegistry);
// Test StakingPoolFactory -> PerformanceAggregator integration
const stakingRegistry = await stakingPoolFactory.registry();
console.log("✅ StakingPoolFactory registry address:", stakingRegistry);
// Test DAOGovernanceEnhanced -> TreasuryManager integration
const daoTreasuryManager = await daoGovernanceEnhanced.treasuryManager();
console.log("✅ DAO TreasuryManager address:", daoTreasuryManager);
// Test 8: Gas Optimization Checks
console.log("\n8⃣ Testing Gas Optimization...");
// Estimate gas for key operations
const registryLookupGas = await contractRegistry.estimateGas.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("TreasuryManager")));
console.log("✅ Registry lookup gas:", registryLookupGas.toString());
const budgetLookupGas = await treasuryManager.estimateGas.getBudgetBalance("development");
console.log("✅ Budget lookup gas:", budgetLookupGas.toString());
const performanceLookupGas = await performanceAggregator.estimateGas.getReputationScore("0x0000000000000000000000000000000000000000");
console.log("✅ Performance lookup gas:", performanceLookupGas.toString());
// Test 9: Security Checks
console.log("\n9⃣ Testing Security Features...");
// Check if contracts are paused
const registryPaused = await contractRegistry.paused();
console.log("✅ ContractRegistry paused:", registryPaused);
const treasuryPaused = await treasuryManager.paused();
console.log("✅ TreasuryManager paused:", treasuryPaused);
const rewardPaused = await rewardDistributor.paused();
console.log("✅ RewardDistributor paused:", rewardPaused);
// Check ownership
const registryOwner = await contractRegistry.owner();
console.log("✅ ContractRegistry owner:", registryOwner);
const treasuryOwner = await treasuryManager.owner();
console.log("✅ TreasuryManager owner:", treasuryOwner);
// Test 10: Performance Metrics
console.log("\n🔟 Testing Performance Metrics...");
const startTime = Date.now();
// Batch registry lookups
for (let i = 0; i < 10; i++) {
await contractRegistry.getContract(ethers.utils.keccak256(ethers.utils.toUtf8Bytes("TreasuryManager")));
}
const registryTime = Date.now() - startTime;
console.log("✅ Registry lookup performance (10 calls):", registryTime, "ms");
const startTime2 = Date.now();
// Batch budget lookups
for (let i = 0; i < 10; i++) {
await treasuryManager.getBudgetBalance("development");
}
const budgetTime = Date.now() - startTime2;
console.log("✅ Budget lookup performance (10 calls):", budgetTime, "ms");
console.log("\n🎉 All verification tests completed successfully!");
// Generate verification report
const verificationReport = {
timestamp: new Date().toISOString(),
network: network.name,
contracts: {
ContractRegistry: deploymentAddresses.ContractRegistry,
TreasuryManager: deploymentAddresses.TreasuryManager,
RewardDistributor: deploymentAddresses.RewardDistributor,
PerformanceAggregator: deploymentAddresses.PerformanceAggregator,
StakingPoolFactory: deploymentAddresses.StakingPoolFactory,
DAOGovernanceEnhanced: deploymentAddresses.DAOGovernanceEnhanced,
AIToken: deploymentAddresses.AIToken
},
verification: {
registryIntegration: "PASS",
treasuryFunctionality: "PASS",
rewardDistribution: "PASS",
performanceAggregation: "PASS",
stakingFunctionality: "PASS",
governanceFunctionality: "PASS",
crossContractIntegration: "PASS",
gasOptimization: "PASS",
securityFeatures: "PASS",
performanceMetrics: "PASS"
},
performance: {
registryLookupTime: registryTime,
budgetLookupTime: budgetTime
},
gasUsage: {
registryLookup: registryLookupGas.toString(),
budgetLookup: budgetLookupGas.toString(),
performanceLookup: performanceLookupGas.toString()
}
};
// Save verification report
fs.writeFileSync(
'./verification-report-phase4.json',
JSON.stringify(verificationReport, null, 2)
);
console.log("\n📄 Verification report saved to verification-report-phase4.json");
} catch (error) {
console.error("❌ Verification failed:", error);
process.exit(1);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});