methodic_scout-contract-lab/docs/_GreeterFactory.md
methodic_scout 4b95f2cec3
Some checks are pending
CI / build-and-test (push) Waiting to run
CI / slither (push) Waiting to run
docs: add documentation for GreeterFactory.sol
2026-04-19 09:09:47 +00:00

2.9 KiB

Overview

GreeterFactory is a Solidity smart contract designed to manage the creation and destruction of Greeter contract instances. It provides a factory pattern for deploying multiple Greeter contracts with unique initial greetings, allowing users to create, track, and destroy their own Greeter instances.

Interface

Function Visibility Parameters Returns Description
createGreeter Public string initialGreeting address Creates a new Greeter contract with the specified initial greeting
destroyGreeter Public address greeterAddress void Destroys a specific Greeter contract owned by the caller
getOwnerGreeterInstances Public View address owner address[] Retrieves all Greeter instances owned by a specific address
isActiveGreeter Public View address greeterAddress bool Checks if a Greeter contract is currently active

Events

  • GreeterCreated(address indexed greeter, address indexed owner, string initialGreeting)

    • Emitted when a new Greeter contract is created
    • Provides the new contract address, owner, and initial greeting
  • GreeterDestroyed(address indexed greeter, address indexed owner)

    • Emitted when a Greeter contract is destroyed
    • Provides the destroyed contract address and owner

Storage Layout

  • _ownerGreeterInstances: Mapping tracking Greeter instances per owner
  • _activeGreeterInstances: Mapping tracking active Greeter contract addresses
  • Stores references to created Greeter contracts for management and tracking

Access Control

  • createGreeter(): Permissionless, any address can create a Greeter
  • destroyGreeter(): Restricted to the original Greeter contract owner
  • View functions are publicly accessible

Security Considerations

  • Input validation for non-empty greetings
  • Owner-only destruction mechanism
  • Prevents duplicate or invalid contract interactions
  • Uses delete and array manipulation for instance tracking

Deployment

ChunkNet Devnet Deployment

  • RPC URL: https://rpc.chunknet.org
  • Chain ID: 214562
  • Recommended Deployment Steps:
    1. Ensure sufficient gas funds
    2. Use ChunkNet RPC URL for deployment
    3. Set appropriate gas limits and priorities
    4. Verify contract post-deployment

bash forge create GreeterFactory
--rpc-url https://rpc.chunknet.org
--private-key $PRIVATE_KEY

Testing

Test Coverage

  • Contract creation with valid greeting
  • Contract creation with empty greeting (should revert)
  • Destroying owned Greeter contracts
  • Preventing unauthorized contract destruction
  • Tracking owner's Greeter instances
  • Verifying active/inactive contract states

Test Scenarios

  1. Create multiple Greeter instances
  2. Verify ownership tracking
  3. Attempt unauthorized contract destruction
  4. Validate instance management functions