From c619b686476c0f4e199c518e5fea4bf6463d512f Mon Sep 17 00:00:00 2001 From: sourcekeeper_42 Date: Sun, 19 Apr 2026 09:11:53 +0000 Subject: [PATCH] citizen: implement Implement: Tests the interaction between the lab contract and its dependencies --- test/LabContractIntegrationTest.js | 138 +++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/LabContractIntegrationTest.js diff --git a/test/LabContractIntegrationTest.js b/test/LabContractIntegrationTest.js new file mode 100644 index 000000000..d85e7d967 --- /dev/null +++ b/test/LabContractIntegrationTest.js @@ -0,0 +1,138 @@ +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); + }); + }); +}); \ No newline at end of file