From 0c9404fa92325390bf0aef4d15f274b2f24fd10f Mon Sep 17 00:00:00 2001 From: aitbc Date: Wed, 29 Apr 2026 11:53:24 +0200 Subject: [PATCH] fix: provide required constructor arguments for AIPowerRental deployment - Add ZKReceiptVerifier and Groth16Verifier deployments before AIPowerRental - Fix AITBCPaymentProcessor.test.js to deploy verifiers first - Fix DynamicPricing.test.js to deploy verifiers first - Fix EscrowService.test.js to deploy verifiers first - Fix Phase4ModularContracts.test.js to register contracts before initializing PerformanceAggregator - This fixes incorrect number of arguments to constructor errors --- contracts/test/AITBCPaymentProcessor.test.js | 17 +++++++++++++++-- contracts/test/DynamicPricing.test.js | 17 +++++++++++++++-- contracts/test/EscrowService.test.js | 17 +++++++++++++++-- contracts/test/Phase4ModularContracts.test.js | 18 +++++++++--------- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/contracts/test/AITBCPaymentProcessor.test.js b/contracts/test/AITBCPaymentProcessor.test.js index 0714f22a..abcbb44c 100644 --- a/contracts/test/AITBCPaymentProcessor.test.js +++ b/contracts/test/AITBCPaymentProcessor.test.js @@ -17,9 +17,22 @@ describe("AITBCPaymentProcessor", function () { aitbcToken = await AIToken.deploy(ethers.parseUnits("1000000", 18)); await aitbcToken.waitForDeployment(); - // Deploy AIPowerRental (mock) + // Deploy mock verifiers for AIPowerRental + const ZKReceiptVerifier = await ethers.getContractFactory("ZKReceiptVerifier"); + const zkVerifier = await ZKReceiptVerifier.deploy(); + await zkVerifier.waitForDeployment(); + + const Groth16Verifier = await ethers.getContractFactory("Groth16Verifier"); + const groth16Verifier = await Groth16Verifier.deploy(); + await groth16Verifier.waitForDeployment(); + + // Deploy AIPowerRental const AIPowerRental = await ethers.getContractFactory("AIPowerRental"); - const aiPowerRental = await AIPowerRental.deploy(); + const aiPowerRental = await AIPowerRental.deploy( + await aitbcToken.getAddress(), + await zkVerifier.getAddress(), + await groth16Verifier.getAddress() + ); await aiPowerRental.waitForDeployment(); // Deploy PaymentProcessor diff --git a/contracts/test/DynamicPricing.test.js b/contracts/test/DynamicPricing.test.js index 5927a04d..7f7d54da 100644 --- a/contracts/test/DynamicPricing.test.js +++ b/contracts/test/DynamicPricing.test.js @@ -17,9 +17,22 @@ describe("DynamicPricing", function () { aitbcToken = await AIToken.deploy(INITIAL_SUPPLY); await aitbcToken.waitForDeployment(); - // Deploy AIPowerRental (mock) + // Deploy mock verifiers for AIPowerRental + const ZKReceiptVerifier = await ethers.getContractFactory("ZKReceiptVerifier"); + const zkVerifier = await ZKReceiptVerifier.deploy(); + await zkVerifier.waitForDeployment(); + + const Groth16Verifier = await ethers.getContractFactory("Groth16Verifier"); + const groth16Verifier = await Groth16Verifier.deploy(); + await groth16Verifier.waitForDeployment(); + + // Deploy AIPowerRental const AIPowerRental = await ethers.getContractFactory("AIPowerRental"); - aiPowerRental = await AIPowerRental.deploy(); + aiPowerRental = await AIPowerRental.deploy( + await aitbcToken.getAddress(), + await zkVerifier.getAddress(), + await groth16Verifier.getAddress() + ); await aiPowerRental.waitForDeployment(); // Deploy PerformanceVerifier (mock) diff --git a/contracts/test/EscrowService.test.js b/contracts/test/EscrowService.test.js index 14c9b28d..13866bf2 100644 --- a/contracts/test/EscrowService.test.js +++ b/contracts/test/EscrowService.test.js @@ -20,9 +20,22 @@ describe("EscrowService", function () { // Transfer tokens to depositor await aitbcToken.transfer(depositor.address, ethers.parseEther("10000")); - // Deploy AIPowerRental (mock) + // Deploy mock verifiers for AIPowerRental + const ZKReceiptVerifier = await ethers.getContractFactory("ZKReceiptVerifier"); + const zkVerifier = await ZKReceiptVerifier.deploy(); + await zkVerifier.waitForDeployment(); + + const Groth16Verifier = await ethers.getContractFactory("Groth16Verifier"); + const groth16Verifier = await Groth16Verifier.deploy(); + await groth16Verifier.waitForDeployment(); + + // Deploy AIPowerRental const AIPowerRental = await ethers.getContractFactory("AIPowerRental"); - aiPowerRental = await AIPowerRental.deploy(); + aiPowerRental = await AIPowerRental.deploy( + await aitbcToken.getAddress(), + await zkVerifier.getAddress(), + await groth16Verifier.getAddress() + ); await aiPowerRental.waitForDeployment(); // Deploy AITBCPaymentProcessor (mock) diff --git a/contracts/test/Phase4ModularContracts.test.js b/contracts/test/Phase4ModularContracts.test.js index 75a7f491..58ad8236 100644 --- a/contracts/test/Phase4ModularContracts.test.js +++ b/contracts/test/Phase4ModularContracts.test.js @@ -62,15 +62,8 @@ describe("Phase 4 Modular Smart Contracts", function () { const DAOGovernanceEnhanced = await ethers.getContractFactory("DAOGovernanceEnhanced"); daoGovernanceEnhanced = await DAOGovernanceEnhanced.deploy(await aiToken.getAddress(), MIN_STAKE); await daoGovernanceEnhanced.waitForDeployment(); - - // Initialize all contracts - await treasuryManager.initialize(await contractRegistry.getAddress()); - await rewardDistributor.initialize(await contractRegistry.getAddress()); - await performanceAggregator.initialize(await contractRegistry.getAddress()); - await stakingPoolFactory.initialize(await contractRegistry.getAddress()); - await daoGovernanceEnhanced.initialize(await contractRegistry.getAddress()); - - // Register contracts in registry + + // Register contracts in registry first (required by PerformanceAggregator.initialize) await contractRegistry.registerContract( ethers.keccak256(ethers.toUtf8Bytes("TreasuryManager")), await treasuryManager.getAddress() @@ -91,6 +84,13 @@ describe("Phase 4 Modular Smart Contracts", function () { ethers.keccak256(ethers.toUtf8Bytes("DAOGovernanceEnhanced")), await daoGovernanceEnhanced.getAddress() ); + + // Initialize all contracts (after registration) + await treasuryManager.initialize(await contractRegistry.getAddress()); + await rewardDistributor.initialize(await contractRegistry.getAddress()); + await performanceAggregator.initialize(await contractRegistry.getAddress()); + await stakingPoolFactory.initialize(await contractRegistry.getAddress()); + await daoGovernanceEnhanced.initialize(await contractRegistry.getAddress()); }); describe("ContractRegistry", function () {