2.9 KiB
2.9 KiB
Overview
LabContract is a sophisticated smart contract designed to manage scientific experiments on the blockchain. It provides a robust framework for creating, tracking, and managing experimental configurations with integrated funding and status tracking mechanisms.
Interface
| Function | Parameters | Returns | Description |
|---|---|---|---|
createExperiment |
fundingAmount, configHash |
bytes32 |
Create a new experiment with initial funding |
updateExperimentStatus |
experimentId, newStatus |
void |
Toggle experiment active status |
getExperimentDetails |
experimentId |
ExperimentConfig |
Retrieve full experiment configuration |
withdrawFunds |
experimentId, amount |
void |
Withdraw funds from an active experiment |
Events
-
ExperimentCreated: Emitted when a new experiment is initializedexperimentId: Unique identifiercreator: Experiment creator's addressfundingAmount: Initial funding amount
-
ExperimentUpdated: Emitted when experiment status changesexperimentId: Unique identifierisActive: New active status
Storage Layout
experiments: Mapping of experiment IDs toExperimentConfigcreatorExperiments: Mapping tracking experiments per creatorExperimentConfigstruct contains:creator: Experiment initiatorstartTimestamp: Experiment creation timefundingAmount: Available experiment fundsisActive: Current experiment statusconfigHash: Experiment configuration identifier
Access Control
- Uses OpenZeppelin's
Ownablefor contract-level administration - Experiment creators have exclusive rights to:
- Update experiment status
- Withdraw experiment funds
Security Considerations
nonReentrantmodifier prevents recursive calls- Strict access controls on critical functions
- Validates input parameters
- Checks experiment creator before allowing modifications
- Requires positive funding amounts
- Validates experiment existence before operations
Deployment
ChunkNet Deployment Parameters
- RPC URL: https://rpc.chunknet.org
- Chain ID: 214562
- Required Constructor Parameters:
_registryAddress: LabRegistry contract address_helperAddress: LabHelper contract address
Deployment Script Example
bash
forge create LabContract
--rpc-url https://rpc.chunknet.org
--constructor-args $LAB_REGISTRY_ADDRESS $LAB_HELPER_ADDRESS
Testing
Recommended Test Scenarios
- Experiment creation with valid parameters
- Status update permissions
- Fund withdrawal mechanics
- Edge case handling:
- Zero funding amount
- Invalid experiment ID
- Unauthorized status modifications
- Verify event emissions
- Validate access control mechanisms
Test Coverage
- Unit tests for each function
- Integration tests with registry interactions
- Fuzz testing for input validation
- Simulation of various experiment lifecycle stages