const { expect } = require('chai'); const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); describe('LabContract Integration Tests', () => { async function deployLabContractFixture() { const [owner, researcher1, researcher2] = await ethers.getSigners(); const LabHelper = await ethers.getContractFactory('LabHelper'); const labHelper = await LabHelper.deploy(); await labHelper.deployed(); const LabContract = await ethers.getContractFactory('LabContract', { libraries: { LabHelper: labHelper.address } }); const labContract = await LabContract.deploy(); await labContract.deployed(); return { owner, researcher1, researcher2, labContract, labHelper }; } describe('Contract Deployment', () => { it('should deploy LabContract successfully', async () => { const { labContract } = await loadFixture(deployLabContractFixture); expect(labContract.address).to.not.be.undefined; expect(labContract.address).to.not.equal(ethers.constants.AddressZero); }); }); describe('Lab Registration Flow', () => { it('should allow researcher registration with valid parameters', async () => { const { labContract, researcher1 } = await loadFixture(deployLabContractFixture); const researchMetadata = { name: 'Test Research Project', description: 'Blockchain integration research', publicKey: ethers.utils.keccak256(researcher1.address) }; await expect( labContract.connect(researcher1).registerLab( researchMetadata.name, researchMetadata.description, researchMetadata.publicKey ) ).to.emit(labContract, 'LabRegistered') .withArgs(researcher1.address, researchMetadata.name); }); it('should prevent duplicate lab registrations', async () => { const { labContract, researcher1 } = await loadFixture(deployLabContractFixture); const researchMetadata = { name: 'Unique Research Project', description: 'Blockchain integration research', publicKey: ethers.utils.keccak256(researcher1.address) }; await labContract.connect(researcher1).registerLab( researchMetadata.name, researchMetadata.description, researchMetadata.publicKey ); await expect( labContract.connect(researcher1).registerLab( researchMetadata.name, researchMetadata.description, researchMetadata.publicKey ) ).to.be.revertedWith('Lab already registered'); }); }); describe('Lab Interaction Validation', () => { it('should validate lab registration constraints', async () => { const { labContract, researcher1 } = await loadFixture(deployLabContractFixture); await expect( labContract.connect(researcher1).registerLab( '', 'Invalid Description', ethers.utils.keccak256(researcher1.address) ) ).to.be.revertedWith('Invalid lab name'); await expect( labContract.connect(researcher1).registerLab( 'Valid Name', '', ethers.utils.keccak256(researcher1.address) ) ).to.be.revertedWith('Invalid lab description'); }); }); describe('Advanced Lab Management', () => { it('should update lab metadata correctly', async () => { const { labContract, researcher1 } = await loadFixture(deployLabContractFixture); const initialMetadata = { name: 'Initial Research', description: 'First iteration', publicKey: ethers.utils.keccak256(researcher1.address) }; await labContract.connect(researcher1).registerLab( initialMetadata.name, initialMetadata.description, initialMetadata.publicKey ); const updatedMetadata = { name: 'Updated Research', description: 'Enhanced research scope', publicKey: ethers.utils.keccak256(researcher1.address) }; await expect( labContract.connect(researcher1).updateLabMetadata( updatedMetadata.name, updatedMetadata.description, updatedMetadata.publicKey ) ).to.emit(labContract, 'LabMetadataUpdated') .withArgs(researcher1.address, updatedMetadata.name); }); }); });