chore: remove outdated documentation and reference files
Some checks failed
AITBC CI/CD Pipeline / lint-and-test (3.11) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.12) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.13) (push) Has been cancelled
AITBC CI/CD Pipeline / test-cli (push) Has been cancelled
AITBC CI/CD Pipeline / test-services (push) Has been cancelled
AITBC CI/CD Pipeline / test-production-services (push) Has been cancelled
AITBC CI/CD Pipeline / security-scan (push) Has been cancelled
AITBC CI/CD Pipeline / build (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-staging (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-production (push) Has been cancelled
AITBC CI/CD Pipeline / performance-test (push) Has been cancelled
AITBC CI/CD Pipeline / docs (push) Has been cancelled
AITBC CI/CD Pipeline / release (push) Has been cancelled
AITBC CI/CD Pipeline / notify (push) Has been cancelled
Security Scanning / Bandit Security Scan (apps/coordinator-api/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (cli/aitbc_cli) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-core/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-crypto/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-sdk/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (tests) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (javascript) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (python) (push) Has been cancelled
Security Scanning / Dependency Security Scan (push) Has been cancelled
Security Scanning / Container Security Scan (push) Has been cancelled
Security Scanning / OSSF Scorecard (push) Has been cancelled
Security Scanning / Security Summary Report (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.11) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.12) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.13) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-summary (push) Has been cancelled
Some checks failed
AITBC CI/CD Pipeline / lint-and-test (3.11) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.12) (push) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.13) (push) Has been cancelled
AITBC CI/CD Pipeline / test-cli (push) Has been cancelled
AITBC CI/CD Pipeline / test-services (push) Has been cancelled
AITBC CI/CD Pipeline / test-production-services (push) Has been cancelled
AITBC CI/CD Pipeline / security-scan (push) Has been cancelled
AITBC CI/CD Pipeline / build (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-staging (push) Has been cancelled
AITBC CI/CD Pipeline / deploy-production (push) Has been cancelled
AITBC CI/CD Pipeline / performance-test (push) Has been cancelled
AITBC CI/CD Pipeline / docs (push) Has been cancelled
AITBC CI/CD Pipeline / release (push) Has been cancelled
AITBC CI/CD Pipeline / notify (push) Has been cancelled
Security Scanning / Bandit Security Scan (apps/coordinator-api/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (cli/aitbc_cli) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-core/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-crypto/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-sdk/src) (push) Has been cancelled
Security Scanning / Bandit Security Scan (tests) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (javascript) (push) Has been cancelled
Security Scanning / CodeQL Security Analysis (python) (push) Has been cancelled
Security Scanning / Dependency Security Scan (push) Has been cancelled
Security Scanning / Container Security Scan (push) Has been cancelled
Security Scanning / OSSF Scorecard (push) Has been cancelled
Security Scanning / Security Summary Report (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.11) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.12) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-cli-level1 (3.13) (push) Has been cancelled
AITBC CLI Level 1 Commands Test / test-summary (push) Has been cancelled
- Remove debugging service documentation (DEBUgging_SERVICES.md) - Remove development logs policy and quick reference guides - Remove E2E test creation summary - Remove gift certificate example file - Remove GitHub pull summary documentation
This commit is contained in:
@@ -1,307 +0,0 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
|
||||
describe("AgentBounty System", function () {
|
||||
let agentBounty, aitbcToken, performanceVerifier;
|
||||
let owner, bountyCreator, agent, arbitrator;
|
||||
|
||||
beforeEach(async function () {
|
||||
// Get signers
|
||||
[owner, bountyCreator, agent, arbitrator] = await ethers.getSigners();
|
||||
|
||||
// Deploy mock AITBC token
|
||||
const MockERC20 = await ethers.getContractFactory("MockERC20");
|
||||
aitbcToken = await MockERC20.deploy("AITBC Token", "AITBC", ethers.utils.parseEther("1000000"));
|
||||
await aitbcToken.deployed();
|
||||
|
||||
// Deploy mock performance verifier
|
||||
const MockPerformanceVerifier = await ethers.getContractFactory("MockPerformanceVerifier");
|
||||
performanceVerifier = await MockPerformanceVerifier.deploy();
|
||||
await performanceVerifier.deployed();
|
||||
|
||||
// Deploy AgentBounty contract
|
||||
const AgentBounty = await ethers.getContractFactory("AgentBounty");
|
||||
agentBounty = await AgentBounty.deploy(
|
||||
aitbcToken.address,
|
||||
performanceVerifier.address
|
||||
);
|
||||
await agentBounty.deployed();
|
||||
|
||||
// Transfer tokens to bounty creator and agent
|
||||
await aitbcToken.transfer(bountyCreator.address, ethers.utils.parseEther("10000"));
|
||||
await aitbcToken.transfer(agent.address, ethers.utils.parseEther("10000"));
|
||||
});
|
||||
|
||||
describe("Bounty Creation", function () {
|
||||
it("Should create a bounty successfully", async function () {
|
||||
const rewardAmount = ethers.utils.parseEther("100");
|
||||
const deadline = Math.floor(Date.now() / 1000) + 86400; // 24 hours from now
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, rewardAmount);
|
||||
|
||||
const tx = await agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"A test bounty for AI agents",
|
||||
rewardAmount,
|
||||
deadline,
|
||||
90, // min_accuracy
|
||||
3600, // max_response_time
|
||||
10, // max_submissions
|
||||
false, // requires_zk_proof
|
||||
["test", "ai"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "BountyCreated");
|
||||
|
||||
expect(event.args.bountyId).to.equal(1);
|
||||
expect(event.args.creator).to.equal(bountyCreator.address);
|
||||
expect(event.args.rewardAmount).to.equal(rewardAmount);
|
||||
});
|
||||
|
||||
it("Should fail if reward amount is zero", async function () {
|
||||
const deadline = Math.floor(Date.now() / 1000) + 86400;
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, ethers.utils.parseEther("100"));
|
||||
|
||||
await expect(
|
||||
agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"Description",
|
||||
0,
|
||||
deadline,
|
||||
90,
|
||||
3600,
|
||||
10,
|
||||
false,
|
||||
["test"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
)
|
||||
).to.be.revertedWith("Reward amount must be greater than 0");
|
||||
});
|
||||
|
||||
it("Should fail if deadline is in the past", async function () {
|
||||
const pastDeadline = Math.floor(Date.now() / 1000) - 3600; // 1 hour ago
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, ethers.utils.parseEther("100"));
|
||||
|
||||
await expect(
|
||||
agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"Description",
|
||||
ethers.utils.parseEther("100"),
|
||||
pastDeadline,
|
||||
90,
|
||||
3600,
|
||||
10,
|
||||
false,
|
||||
["test"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
)
|
||||
).to.be.revertedWith("Deadline must be in the future");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Bounty Submission", function () {
|
||||
let bountyId;
|
||||
|
||||
beforeEach(async function () {
|
||||
const rewardAmount = ethers.utils.parseEther("100");
|
||||
const deadline = Math.floor(Date.now() / 1000) + 86400;
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, rewardAmount);
|
||||
|
||||
const tx = await agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"Description",
|
||||
rewardAmount,
|
||||
deadline,
|
||||
90,
|
||||
3600,
|
||||
10,
|
||||
false,
|
||||
["test"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
bountyId = receipt.events.find(e => e.event === "BountyCreated").args.bountyId;
|
||||
});
|
||||
|
||||
it("Should submit a bounty successfully", async function () {
|
||||
const submissionData = "test submission data";
|
||||
|
||||
const tx = await agentBounty.connect(agent).submitBounty(
|
||||
bountyId,
|
||||
submissionData,
|
||||
[]
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "BountySubmitted");
|
||||
|
||||
expect(event.args.bountyId).to.equal(bountyId);
|
||||
expect(event.args.submitter).to.equal(agent.address);
|
||||
expect(event.args.submissionData).to.equal(submissionData);
|
||||
});
|
||||
|
||||
it("Should fail if bounty doesn't exist", async function () {
|
||||
await expect(
|
||||
agentBounty.connect(agent).submitBounty(
|
||||
999,
|
||||
"test data",
|
||||
[]
|
||||
)
|
||||
).to.be.revertedWith("Bounty does not exist");
|
||||
});
|
||||
|
||||
it("Should fail if bounty is expired", async function () {
|
||||
// Fast forward time past deadline
|
||||
await ethers.provider.send("evm_increaseTime", [86400 * 2]); // 2 days
|
||||
await ethers.provider.send("evm_mine");
|
||||
|
||||
await expect(
|
||||
agentBounty.connect(agent).submitBounty(
|
||||
bountyId,
|
||||
"test data",
|
||||
[]
|
||||
)
|
||||
).to.be.revertedWith("Bounty has expired");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Bounty Verification", function () {
|
||||
let bountyId, submissionId;
|
||||
|
||||
beforeEach(async function () {
|
||||
const rewardAmount = ethers.utils.parseEther("100");
|
||||
const deadline = Math.floor(Date.now() / 1000) + 86400;
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, rewardAmount);
|
||||
|
||||
const tx = await agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"Description",
|
||||
rewardAmount,
|
||||
deadline,
|
||||
90,
|
||||
3600,
|
||||
10,
|
||||
false,
|
||||
["test"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
bountyId = receipt.events.find(e => e.event === "BountyCreated").args.bountyId;
|
||||
|
||||
const submitTx = await agentBounty.connect(agent).submitBounty(
|
||||
bountyId,
|
||||
"test submission data",
|
||||
[]
|
||||
);
|
||||
|
||||
const submitReceipt = await submitTx.wait();
|
||||
submissionId = submitReceipt.events.find(e => e.event === "BountySubmitted").args.submissionId;
|
||||
});
|
||||
|
||||
it("Should verify a bounty successfully", async function () {
|
||||
// Mock performance verifier to return true
|
||||
await performanceVerifier.setMockResult(true);
|
||||
|
||||
const tx = await agentBounty.verifyBounty(submissionId);
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "BountyVerified");
|
||||
|
||||
expect(event.args.submissionId).to.equal(submissionId);
|
||||
expect(event.args.success).to.be.true;
|
||||
});
|
||||
|
||||
it("Should distribute rewards upon successful verification", async function () {
|
||||
// Mock performance verifier to return true
|
||||
await performanceVerifier.setMockResult(true);
|
||||
|
||||
const initialBalance = await aitbcToken.balanceOf(agent.address);
|
||||
|
||||
await agentBounty.verifyBounty(submissionId);
|
||||
|
||||
const finalBalance = await aitbcToken.balanceOf(agent.address);
|
||||
expect(finalBalance).to.be.gt(initialBalance);
|
||||
});
|
||||
|
||||
it("Should handle failed verification", async function () {
|
||||
// Mock performance verifier to return false
|
||||
await performanceVerifier.setMockResult(false);
|
||||
|
||||
const tx = await agentBounty.verifyBounty(submissionId);
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "BountyVerified");
|
||||
|
||||
expect(event.args.success).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Fee Management", function () {
|
||||
it("Should allow owner to update fees", async function () {
|
||||
const newCreationFee = 75; // 0.75%
|
||||
|
||||
await agentBounty.updateCreationFee(newCreationFee);
|
||||
|
||||
expect(await agentBounty.creationFeePercentage()).to.equal(newCreationFee);
|
||||
});
|
||||
|
||||
it("Should prevent non-owners from updating fees", async function () {
|
||||
await expect(
|
||||
agentBounty.connect(bountyCreator).updateCreationFee(75)
|
||||
).to.be.revertedWith("Ownable: caller is not the owner");
|
||||
});
|
||||
|
||||
it("Should validate fee ranges", async function () {
|
||||
// Test fee too high (over 1000 basis points = 10%)
|
||||
await expect(
|
||||
agentBounty.updateCreationFee(1001)
|
||||
).to.be.revertedWith("Fee cannot exceed 1000 basis points");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pausability", function () {
|
||||
it("Should allow owner to pause and unpause", async function () {
|
||||
await agentBounty.pause();
|
||||
expect(await agentBounty.paused()).to.be.true;
|
||||
|
||||
await agentBounty.unpause();
|
||||
expect(await agentBounty.paused()).to.be.false;
|
||||
});
|
||||
|
||||
it("Should prevent operations when paused", async function () {
|
||||
await agentBounty.pause();
|
||||
|
||||
const rewardAmount = ethers.utils.parseEther("100");
|
||||
const deadline = Math.floor(Date.now() / 1000) + 86400;
|
||||
|
||||
await aitbcToken.connect(bountyCreator).approve(agentBounty.address, rewardAmount);
|
||||
|
||||
await expect(
|
||||
agentBounty.connect(bountyCreator).createBounty(
|
||||
"Test Bounty",
|
||||
"Description",
|
||||
rewardAmount,
|
||||
deadline,
|
||||
90,
|
||||
3600,
|
||||
10,
|
||||
false,
|
||||
["test"],
|
||||
"BRONZE",
|
||||
"easy"
|
||||
)
|
||||
).to.be.revertedWith("Pausable: paused");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,331 +0,0 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
|
||||
describe("AgentStaking System", function () {
|
||||
let agentStaking, aitbcToken;
|
||||
let owner, agent, staker1, staker2;
|
||||
|
||||
beforeEach(async function () {
|
||||
// Get signers
|
||||
[owner, agent, staker1, staker2] = await ethers.getSigners();
|
||||
|
||||
// Deploy mock AITBC token
|
||||
const MockERC20 = await ethers.getContractFactory("MockERC20");
|
||||
aitbcToken = await MockERC20.deploy("AITBC Token", "AITBC", ethers.utils.parseEther("1000000"));
|
||||
await aitbcToken.deployed();
|
||||
|
||||
// Deploy AgentStaking contract
|
||||
const AgentStaking = await ethers.getContractFactory("AgentStaking");
|
||||
agentStaking = await AgentStaking.deploy(aitbcToken.address);
|
||||
await agentStaking.deployed();
|
||||
|
||||
// Transfer tokens to stakers
|
||||
await aitbcToken.transfer(staker1.address, ethers.utils.parseEther("10000"));
|
||||
await aitbcToken.transfer(staker2.address, ethers.utils.parseEther("10000"));
|
||||
});
|
||||
|
||||
describe("Agent Registration", function () {
|
||||
it("Should register an agent successfully", async function () {
|
||||
const tx = await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"https://example.com/metadata",
|
||||
["AI", "ML", "NLP"]
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "AgentRegistered");
|
||||
|
||||
expect(event.args.agentAddress).to.equal(agent.address);
|
||||
expect(event.args.name).to.equal("Test Agent");
|
||||
expect(event.args.metadataURI).to.equal("https://example.com/metadata");
|
||||
});
|
||||
|
||||
it("Should fail if agent is already registered", async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
|
||||
await expect(
|
||||
agentStaking.connect(agent).registerAgent(
|
||||
"Another Agent",
|
||||
"metadata2",
|
||||
["ML"]
|
||||
)
|
||||
).to.be.revertedWith("Agent already registered");
|
||||
});
|
||||
|
||||
it("Should update agent metadata", async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
|
||||
await agentStaking.connect(agent).updateAgentMetadata(
|
||||
"Updated Agent",
|
||||
"https://updated.com/metadata",
|
||||
["AI", "ML", "CV"]
|
||||
);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.name).to.equal("Updated Agent");
|
||||
expect(agentInfo.metadataURI).to.equal("https://updated.com/metadata");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Staking Operations", function () {
|
||||
beforeEach(async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
});
|
||||
|
||||
it("Should stake tokens successfully", async function () {
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
|
||||
const tx = await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "TokensStaked");
|
||||
|
||||
expect(event.args.staker).to.equal(staker1.address);
|
||||
expect(event.args.agent).to.equal(agent.address);
|
||||
expect(event.args.amount).to.equal(stakeAmount);
|
||||
});
|
||||
|
||||
it("Should track total staked per agent", async function () {
|
||||
const stakeAmount1 = ethers.utils.parseEther("500");
|
||||
const stakeAmount2 = ethers.utils.parseEther("300");
|
||||
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount1);
|
||||
await aitbcToken.connect(staker2).approve(agentStaking.address, stakeAmount2);
|
||||
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount1);
|
||||
await agentStaking.connect(staker2).stake(agent.address, stakeAmount2);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.totalStaked).to.equal(stakeAmount1.add(stakeAmount2));
|
||||
});
|
||||
|
||||
it("Should unstake tokens successfully", async function () {
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
|
||||
// Fast forward past unstaking delay
|
||||
await ethers.provider.send("evm_increaseTime", [86400 * 7]); // 7 days
|
||||
await ethers.provider.send("evm_mine");
|
||||
|
||||
const initialBalance = await aitbcToken.balanceOf(staker1.address);
|
||||
|
||||
await agentStaking.connect(staker1).unstake(agent.address, stakeAmount);
|
||||
|
||||
const finalBalance = await aitbcToken.balanceOf(staker1.address);
|
||||
expect(finalBalance).to.equal(initialBalance.add(stakeAmount));
|
||||
});
|
||||
|
||||
it("Should fail to unstake before delay period", async function () {
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
|
||||
await expect(
|
||||
agentStaking.connect(staker1).unstake(agent.address, stakeAmount)
|
||||
).to.be.revertedWith("Unstaking delay not met");
|
||||
});
|
||||
|
||||
it("Should fail to unstake more than staked", async function () {
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
const unstakeAmount = ethers.utils.parseEther("1500");
|
||||
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
|
||||
// Fast forward past unstaking delay
|
||||
await ethers.provider.send("evm_increaseTime", [86400 * 7]);
|
||||
await ethers.provider.send("evm_mine");
|
||||
|
||||
await expect(
|
||||
agentStaking.connect(staker1).unstake(agent.address, unstakeAmount)
|
||||
).to.be.revertedWith("Insufficient staked amount");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Reward Distribution", function () {
|
||||
beforeEach(async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
});
|
||||
|
||||
it("Should distribute rewards proportionally", async function () {
|
||||
const rewardAmount = ethers.utils.parseEther("100");
|
||||
|
||||
await aitbcToken.transfer(agentStaking.address, rewardAmount);
|
||||
|
||||
const initialBalance = await aitbcToken.balanceOf(staker1.address);
|
||||
|
||||
await agentStaking.distributeRewards(agent.address, rewardAmount);
|
||||
|
||||
const finalBalance = await aitbcToken.balanceOf(staker1.address);
|
||||
expect(finalBalance).to.equal(initialBalance.add(rewardAmount));
|
||||
});
|
||||
|
||||
it("Should handle multiple stakers proportionally", async function () {
|
||||
// Add second staker
|
||||
const stakeAmount2 = ethers.utils.parseEther("500");
|
||||
await aitbcToken.connect(staker2).approve(agentStaking.address, stakeAmount2);
|
||||
await agentStaking.connect(staker2).stake(agent.address, stakeAmount2);
|
||||
|
||||
const rewardAmount = ethers.utils.parseEther("150");
|
||||
await aitbcToken.transfer(agentStaking.address, rewardAmount);
|
||||
|
||||
const initialBalance1 = await aitbcToken.balanceOf(staker1.address);
|
||||
const initialBalance2 = await aitbcToken.balanceOf(staker2.address);
|
||||
|
||||
await agentStaking.distributeRewards(agent.address, rewardAmount);
|
||||
|
||||
const finalBalance1 = await aitbcToken.balanceOf(staker1.address);
|
||||
const finalBalance2 = await aitbcToken.balanceOf(staker2.address);
|
||||
|
||||
// Staker1 had 1000 tokens, Staker2 had 500 tokens (2:1 ratio)
|
||||
// So rewards should be distributed 100:50
|
||||
expect(finalBalance1).to.equal(initialBalance1.add(ethers.utils.parseEther("100")));
|
||||
expect(finalBalance2).to.equal(initialBalance2.add(ethers.utils.parseEther("50")));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Agent Performance Tracking", function () {
|
||||
beforeEach(async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
});
|
||||
|
||||
it("Should record successful performance", async function () {
|
||||
await agentStaking.recordPerformance(agent.address, true, 95);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.successfulTasks).to.equal(1);
|
||||
expect(agentInfo.totalTasks).to.equal(1);
|
||||
expect(agentInfo.successRate).to.equal(10000); // 100% in basis points
|
||||
});
|
||||
|
||||
it("Should record failed performance", async function () {
|
||||
await agentStaking.recordPerformance(agent.address, false, 60);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.successfulTasks).to.equal(0);
|
||||
expect(agentInfo.totalTasks).to.equal(1);
|
||||
expect(agentInfo.successRate).to.equal(0);
|
||||
});
|
||||
|
||||
it("Should calculate success rate correctly", async function () {
|
||||
// Record multiple performances
|
||||
await agentStaking.recordPerformance(agent.address, true, 90);
|
||||
await agentStaking.recordPerformance(agent.address, true, 85);
|
||||
await agentStaking.recordPerformance(agent.address, false, 70);
|
||||
await agentStaking.recordPerformance(agent.address, true, 95);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.successfulTasks).to.equal(3);
|
||||
expect(agentInfo.totalTasks).to.equal(4);
|
||||
expect(agentInfo.successRate).to.equal(7500); // 75% in basis points
|
||||
});
|
||||
|
||||
it("Should update average accuracy", async function () {
|
||||
await agentStaking.recordPerformance(agent.address, true, 90);
|
||||
await agentStaking.recordPerformance(agent.address, true, 80);
|
||||
await agentStaking.recordPerformance(agent.address, true, 85);
|
||||
|
||||
const agentInfo = await agentStaking.getAgentInfo(agent.address);
|
||||
expect(agentInfo.averageAccuracy).to.equal(8500); // 85% in basis points
|
||||
});
|
||||
});
|
||||
|
||||
describe("Slashing Mechanism", function () {
|
||||
beforeEach(async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
|
||||
const stakeAmount = ethers.utils.parseEther("1000");
|
||||
await aitbcToken.connect(staker1).approve(agentStaking.address, stakeAmount);
|
||||
await agentStaking.connect(staker1).stake(agent.address, stakeAmount);
|
||||
});
|
||||
|
||||
it("Should slash agent stake for misconduct", async function () {
|
||||
const slashAmount = ethers.utils.parseEther("100");
|
||||
|
||||
const initialContractBalance = await aitbcToken.balanceOf(agentStaking.address);
|
||||
|
||||
await agentStaking.slashStake(agent.address, slashAmount, "Test slash reason");
|
||||
|
||||
const finalContractBalance = await aitbcToken.balanceOf(agentStaking.address);
|
||||
expect(finalContractBalance).to.equal(initialContractBalance.sub(slashAmount));
|
||||
});
|
||||
|
||||
it("Should emit slash event", async function () {
|
||||
const slashAmount = ethers.utils.parseEther("100");
|
||||
|
||||
const tx = await agentStaking.slashStake(agent.address, slashAmount, "Test reason");
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "StakeSlashed");
|
||||
|
||||
expect(event.args.agent).to.equal(agent.address);
|
||||
expect(event.args.amount).to.equal(slashAmount);
|
||||
expect(event.args.reason).to.equal("Test reason");
|
||||
});
|
||||
|
||||
it("Should fail to slash more than total staked", async function () {
|
||||
const totalStaked = await agentStaking.getAgentStakedAmount(agent.address);
|
||||
const slashAmount = totalStaked.add(ethers.utils.parseEther("1"));
|
||||
|
||||
await expect(
|
||||
agentStaking.slashStake(agent.address, slashAmount, "Excessive slash")
|
||||
).to.be.revertedWith("Slash amount exceeds total staked");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Access Control", function () {
|
||||
it("Should only allow owner to set performance recorder", async function () {
|
||||
await expect(
|
||||
agentStaking.connect(staker1).setPerformanceRecorder(staker2.address)
|
||||
).to.be.revertedWith("Ownable: caller is not the owner");
|
||||
});
|
||||
|
||||
it("Should allow owner to set performance recorder", async function () {
|
||||
await agentStaking.setPerformanceRecorder(staker2.address);
|
||||
expect(await agentStaking.performanceRecorder()).to.equal(staker2.address);
|
||||
});
|
||||
|
||||
it("Should only allow performance recorder to record performance", async function () {
|
||||
await agentStaking.connect(agent).registerAgent(
|
||||
"Test Agent",
|
||||
"metadata",
|
||||
["AI"]
|
||||
);
|
||||
|
||||
await expect(
|
||||
agentStaking.connect(staker1).recordPerformance(agent.address, true, 90)
|
||||
).to.be.revertedWith("Not authorized to record performance");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,461 +0,0 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
|
||||
describe("AITBC Smart Contract Integration", function () {
|
||||
let aitbcToken, zkVerifier, groth16Verifier;
|
||||
let aiPowerRental, paymentProcessor, performanceVerifier;
|
||||
let disputeResolution, escrowService, dynamicPricing;
|
||||
let owner, provider, consumer, arbitrator, oracle;
|
||||
|
||||
beforeEach(async function () {
|
||||
// Get signers
|
||||
[owner, provider, consumer, arbitrator, oracle] = await ethers.getSigners();
|
||||
|
||||
// Deploy mock contracts for testing
|
||||
const MockERC20 = await ethers.getContractFactory("MockERC20");
|
||||
aitbcToken = await MockERC20.deploy("AITBC Token", "AITBC", ethers.utils.parseEther("1000000"));
|
||||
await aitbcToken.deployed();
|
||||
|
||||
const MockZKVerifier = await ethers.getContractFactory("MockZKVerifier");
|
||||
zkVerifier = await MockZKVerifier.deploy();
|
||||
await zkVerifier.deployed();
|
||||
|
||||
const MockGroth16Verifier = await ethers.getContractFactory("MockGroth16Verifier");
|
||||
groth16Verifier = await MockGroth16Verifier.deploy();
|
||||
await groth16Verifier.deployed();
|
||||
|
||||
// Deploy main contracts
|
||||
const AIPowerRental = await ethers.getContractFactory("AIPowerRental");
|
||||
aiPowerRental = await AIPowerRental.deploy(
|
||||
aitbcToken.address,
|
||||
zkVerifier.address,
|
||||
groth16Verifier.address
|
||||
);
|
||||
await aiPowerRental.deployed();
|
||||
|
||||
const AITBCPaymentProcessor = await ethers.getContractFactory("AITBCPaymentProcessor");
|
||||
paymentProcessor = await AITBCPaymentProcessor.deploy(
|
||||
aitbcToken.address,
|
||||
aiPowerRental.address
|
||||
);
|
||||
await paymentProcessor.deployed();
|
||||
|
||||
const PerformanceVerifier = await ethers.getContractFactory("PerformanceVerifier");
|
||||
performanceVerifier = await PerformanceVerifier.deploy(
|
||||
zkVerifier.address,
|
||||
groth16Verifier.address,
|
||||
aiPowerRental.address
|
||||
);
|
||||
await performanceVerifier.deployed();
|
||||
|
||||
const DisputeResolution = await ethers.getContractFactory("DisputeResolution");
|
||||
disputeResolution = await DisputeResolution.deploy(
|
||||
aiPowerRental.address,
|
||||
paymentProcessor.address,
|
||||
performanceVerifier.address
|
||||
);
|
||||
await disputeResolution.deployed();
|
||||
|
||||
const EscrowService = await ethers.getContractFactory("EscrowService");
|
||||
escrowService = await EscrowService.deploy(
|
||||
aitbcToken.address,
|
||||
aiPowerRental.address,
|
||||
paymentProcessor.address
|
||||
);
|
||||
await escrowService.deployed();
|
||||
|
||||
const DynamicPricing = await ethers.getContractFactory("DynamicPricing");
|
||||
dynamicPricing = await DynamicPricing.deploy(
|
||||
aiPowerRental.address,
|
||||
performanceVerifier.address,
|
||||
aitbcToken.address
|
||||
);
|
||||
await dynamicPricing.deployed();
|
||||
|
||||
// Setup authorizations
|
||||
await aiPowerRental.authorizeProvider(provider.address);
|
||||
await aiPowerRental.authorizeConsumer(consumer.address);
|
||||
await paymentProcessor.authorizePayee(provider.address);
|
||||
await paymentProcessor.authorizePayer(consumer.address);
|
||||
await performanceVerifier.authorizeOracle(oracle.address);
|
||||
await disputeResolution.authorizeArbitrator(arbitrator.address);
|
||||
await escrowService.authorizeArbiter(arbitrator.address);
|
||||
await dynamicPricing.authorizePriceOracle(oracle.address);
|
||||
|
||||
// Transfer tokens to consumer for testing
|
||||
await aitbcToken.transfer(consumer.address, ethers.utils.parseEther("1000"));
|
||||
});
|
||||
|
||||
describe("Contract Deployment", function () {
|
||||
it("Should deploy all contracts successfully", async function () {
|
||||
expect(await aiPowerRental.deployed()).to.be.true;
|
||||
expect(await paymentProcessor.deployed()).to.be.true;
|
||||
expect(await performanceVerifier.deployed()).to.be.true;
|
||||
expect(await disputeResolution.deployed()).to.be.true;
|
||||
expect(await escrowService.deployed()).to.be.true;
|
||||
expect(await dynamicPricing.deployed()).to.be.true;
|
||||
});
|
||||
|
||||
it("Should have correct contract addresses", async function () {
|
||||
expect(await aiPowerRental.aitbcToken()).to.equal(aitbcToken.address);
|
||||
expect(await aiPowerRental.zkVerifier()).to.equal(zkVerifier.address);
|
||||
expect(await aiPowerRental.groth16Verifier()).to.equal(groth16Verifier.address);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AI Power Rental Integration", function () {
|
||||
it("Should create and manage rental agreements", async function () {
|
||||
const duration = 3600; // 1 hour
|
||||
const price = ethers.utils.parseEther("0.01");
|
||||
const gpuModel = "RTX 4090";
|
||||
const computeUnits = 100;
|
||||
|
||||
const tx = await aiPowerRental.connect(consumer).createRental(
|
||||
provider.address,
|
||||
duration,
|
||||
price,
|
||||
gpuModel,
|
||||
computeUnits
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "AgreementCreated");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.provider).to.equal(provider.address);
|
||||
expect(event.args.consumer).to.equal(consumer.address);
|
||||
expect(event.args.price).to.equal(price);
|
||||
});
|
||||
|
||||
it("Should start rental and lock payment", async function () {
|
||||
// Create rental first
|
||||
const duration = 3600;
|
||||
const price = ethers.utils.parseEther("0.01");
|
||||
const platformFee = price.mul(250).div(10000); // 2.5%
|
||||
const totalAmount = price.add(platformFee);
|
||||
|
||||
const createTx = await aiPowerRental.connect(consumer).createRental(
|
||||
provider.address,
|
||||
duration,
|
||||
price,
|
||||
"RTX 4090",
|
||||
100
|
||||
);
|
||||
const createReceipt = await createTx.wait();
|
||||
const agreementId = createReceipt.events.find(e => e.event === "AgreementCreated").args.agreementId;
|
||||
|
||||
// Approve tokens
|
||||
await aitbcToken.connect(consumer).approve(aiPowerRental.address, totalAmount);
|
||||
|
||||
// Start rental
|
||||
const startTx = await aiPowerRental.connect(consumer).startRental(agreementId);
|
||||
const startReceipt = await startTx.wait();
|
||||
const startEvent = startReceipt.events.find(e => e.event === "AgreementStarted");
|
||||
expect(startEvent).to.not.be.undefined;
|
||||
|
||||
// Check agreement status
|
||||
const agreement = await aiPowerRental.getRentalAgreement(agreementId);
|
||||
expect(agreement.status).to.equal(1); // Active
|
||||
});
|
||||
});
|
||||
|
||||
describe("Payment Processing Integration", function () {
|
||||
it("Should create and confirm payments", async function () {
|
||||
const amount = ethers.utils.parseEther("0.01");
|
||||
const agreementId = ethers.utils.formatBytes32String("test-agreement");
|
||||
|
||||
// Approve tokens
|
||||
await aitbcToken.connect(consumer).approve(paymentProcessor.address, amount);
|
||||
|
||||
// Create payment
|
||||
const tx = await paymentProcessor.connect(consumer).createPayment(
|
||||
provider.address,
|
||||
amount,
|
||||
agreementId,
|
||||
"Test payment",
|
||||
0 // Immediate release
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "PaymentCreated");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.from).to.equal(consumer.address);
|
||||
expect(event.args.to).to.equal(provider.address);
|
||||
expect(event.args.amount).to.equal(amount);
|
||||
});
|
||||
|
||||
it("Should handle escrow payments", async function () {
|
||||
const amount = ethers.utils.parseEther("0.01");
|
||||
const releaseTime = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
||||
|
||||
// Approve tokens
|
||||
await aitbcToken.connect(consumer).approve(escrowService.address, amount);
|
||||
|
||||
// Create escrow
|
||||
const tx = await escrowService.connect(consumer).createEscrow(
|
||||
provider.address,
|
||||
arbitrator.address,
|
||||
amount,
|
||||
0, // Standard escrow
|
||||
0, // Manual release
|
||||
releaseTime,
|
||||
"Test escrow"
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "EscrowCreated");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.depositor).to.equal(consumer.address);
|
||||
expect(event.args.beneficiary).to.equal(provider.address);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Performance Verification Integration", function () {
|
||||
it("Should submit and verify performance metrics", async function () {
|
||||
const agreementId = 1;
|
||||
const responseTime = 1000; // 1 second
|
||||
const accuracy = 95;
|
||||
const availability = 99;
|
||||
const computePower = 1000;
|
||||
const throughput = 100;
|
||||
const memoryUsage = 512;
|
||||
const energyEfficiency = 85;
|
||||
|
||||
// Create mock ZK proof
|
||||
const mockZKProof = "0x" + "0".repeat(64);
|
||||
const mockGroth16Proof = "0x" + "0".repeat(64);
|
||||
|
||||
// Submit performance
|
||||
const tx = await performanceVerifier.connect(provider).submitPerformance(
|
||||
agreementId,
|
||||
responseTime,
|
||||
accuracy,
|
||||
availability,
|
||||
computePower,
|
||||
throughput,
|
||||
memoryUsage,
|
||||
energyEfficiency,
|
||||
mockZKProof,
|
||||
mockGroth16Proof
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "PerformanceSubmitted");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.responseTime).to.equal(responseTime);
|
||||
expect(event.args.accuracy).to.equal(accuracy);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Dispute Resolution Integration", function () {
|
||||
it("Should file and manage disputes", async function () {
|
||||
const agreementId = 1;
|
||||
const reason = "Service quality issues";
|
||||
|
||||
// File dispute
|
||||
const tx = await disputeResolution.connect(consumer).fileDispute(
|
||||
agreementId,
|
||||
provider.address,
|
||||
0, // Performance dispute
|
||||
reason,
|
||||
ethers.utils.formatBytes32String("evidence")
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "DisputeFiled");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.initiator).to.equal(consumer.address);
|
||||
expect(event.args.respondent).to.equal(provider.address);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Dynamic Pricing Integration", function () {
|
||||
it("Should update market data and calculate prices", async function () {
|
||||
const totalSupply = 10000;
|
||||
const totalDemand = 8000;
|
||||
const activeProviders = 50;
|
||||
const activeConsumers = 100;
|
||||
const totalVolume = ethers.utils.parseEther("100");
|
||||
const transactionCount = 1000;
|
||||
const averageResponseTime = 2000;
|
||||
const averageAccuracy = 96;
|
||||
const marketSentiment = 75;
|
||||
|
||||
// Update market data
|
||||
const tx = await dynamicPricing.connect(oracle).updateMarketData(
|
||||
totalSupply,
|
||||
totalDemand,
|
||||
activeProviders,
|
||||
activeConsumers,
|
||||
totalVolume,
|
||||
transactionCount,
|
||||
averageResponseTime,
|
||||
averageAccuracy,
|
||||
marketSentiment
|
||||
);
|
||||
|
||||
const receipt = await tx.wait();
|
||||
const event = receipt.events.find(e => e.event === "MarketDataUpdated");
|
||||
expect(event).to.not.be.undefined;
|
||||
expect(event.args.totalSupply).to.equal(totalSupply);
|
||||
expect(event.args.totalDemand).to.equal(totalDemand);
|
||||
|
||||
// Get market price
|
||||
const marketPrice = await dynamicPricing.getMarketPrice(address(0), "");
|
||||
expect(marketPrice).to.be.gt(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Cross-Contract Integration", function () {
|
||||
it("Should handle complete rental lifecycle", async function () {
|
||||
// 1. Create rental agreement
|
||||
const duration = 3600;
|
||||
const price = ethers.utils.parseEther("0.01");
|
||||
const platformFee = price.mul(250).div(10000);
|
||||
const totalAmount = price.add(platformFee);
|
||||
|
||||
const createTx = await aiPowerRental.connect(consumer).createRental(
|
||||
provider.address,
|
||||
duration,
|
||||
price,
|
||||
"RTX 4090",
|
||||
100
|
||||
);
|
||||
const createReceipt = await createTx.wait();
|
||||
const agreementId = createReceipt.events.find(e => e.event === "AgreementCreated").args.agreementId;
|
||||
|
||||
// 2. Approve and start rental
|
||||
await aitbcToken.connect(consumer).approve(aiPowerRental.address, totalAmount);
|
||||
await aiPowerRental.connect(consumer).startRental(agreementId);
|
||||
|
||||
// 3. Submit performance metrics
|
||||
const mockZKProof = "0x" + "0".repeat(64);
|
||||
const mockGroth16Proof = "0x" + "0".repeat(64);
|
||||
|
||||
await performanceVerifier.connect(provider).submitPerformance(
|
||||
agreementId,
|
||||
1000, // responseTime
|
||||
95, // accuracy
|
||||
99, // availability
|
||||
1000, // computePower
|
||||
100, // throughput
|
||||
512, // memoryUsage
|
||||
85, // energyEfficiency
|
||||
mockZKProof,
|
||||
mockGroth16Proof
|
||||
);
|
||||
|
||||
// 4. Complete rental
|
||||
await aiPowerRental.connect(provider).completeRental(agreementId);
|
||||
|
||||
// 5. Verify final state
|
||||
const agreement = await aiPowerRental.getRentalAgreement(agreementId);
|
||||
expect(agreement.status).to.equal(2); // Completed
|
||||
});
|
||||
});
|
||||
|
||||
describe("Security Tests", function () {
|
||||
it("Should prevent unauthorized access", async function () {
|
||||
// Try to create rental without authorization
|
||||
await expect(
|
||||
aiPowerRental.connect(arbitrator).createRental(
|
||||
provider.address,
|
||||
3600,
|
||||
ethers.utils.parseEther("0.01"),
|
||||
"RTX 4090",
|
||||
100
|
||||
)
|
||||
).to.be.revertedWith("Not authorized consumer");
|
||||
});
|
||||
|
||||
it("Should handle emergency pause", async function () {
|
||||
// Pause contracts
|
||||
await aiPowerRental.pause();
|
||||
await paymentProcessor.pause();
|
||||
await performanceVerifier.pause();
|
||||
await disputeResolution.pause();
|
||||
await escrowService.pause();
|
||||
await dynamicPricing.pause();
|
||||
|
||||
// Try to perform operations while paused
|
||||
await expect(
|
||||
aiPowerRental.connect(consumer).createRental(
|
||||
provider.address,
|
||||
3600,
|
||||
ethers.utils.parseEther("0.01"),
|
||||
"RTX 4090",
|
||||
100
|
||||
)
|
||||
).to.be.revertedWith("Pausable: paused");
|
||||
|
||||
// Unpause
|
||||
await aiPowerRental.unpause();
|
||||
await paymentProcessor.unpause();
|
||||
await performanceVerifier.unpause();
|
||||
await disputeResolution.unpause();
|
||||
await escrowService.unpause();
|
||||
await dynamicPricing.unpause();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Gas Optimization Tests", function () {
|
||||
it("Should track gas usage for major operations", async function () {
|
||||
// Create rental
|
||||
const tx = await aiPowerRental.connect(consumer).createRental(
|
||||
provider.address,
|
||||
3600,
|
||||
ethers.utils.parseEther("0.01"),
|
||||
"RTX 4090",
|
||||
100
|
||||
);
|
||||
const receipt = await tx.wait();
|
||||
|
||||
console.log(`Gas used for createRental: ${receipt.gasUsed.toString()}`);
|
||||
|
||||
// Should be reasonable gas usage
|
||||
expect(receipt.gasUsed).to.be.lt(500000); // Less than 500k gas
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Mock contracts for testing
|
||||
const MockERC20Source = `
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract MockERC20 is ERC20 {
|
||||
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) {
|
||||
_mint(msg.sender, initialSupply);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const MockZKVerifierSource = `
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
contract MockZKVerifier {
|
||||
function verifyPerformanceProof(
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
bytes memory
|
||||
) external pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const MockGroth16VerifierSource = `
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
contract MockGroth16Verifier {
|
||||
function verifyProof(bytes memory) external pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -1,10 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract MockERC20 is ERC20 {
|
||||
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) {
|
||||
_mint(msg.sender, initialSupply);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
contract MockGroth16Verifier {
|
||||
function verifyProof(bytes memory) external pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
contract MockZKVerifier {
|
||||
function verifyPerformanceProof(
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
bytes memory
|
||||
) external pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user