unit-test-writer
БесплатноБез исполняемых скриптовНе проверенWrite Solidity unit tests for EigenLayer contracts. Use when the user asks to write tests, add test coverage, create unit tests, or test a function. Follows…
Об этом скилле
Unit Test Writer
Write comprehensive unit tests for EigenLayer Solidity contracts following the project's established conventions.
Test File Structure
Each test file follows this structure:
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
// Import the contract under test
import "src/contracts/path/to/ContractUnderTest.sol";
// Import the appropriate test setup
import "src/test/utils/EigenLayerUnitTestSetup.sol";
// Import any required mocks
import "src/test/mocks/SomeMock.sol";
/// @title ContractUnderTestUnitTests
/// @notice Base contract for all ContractUnderTest unit tests
contract ContractUnderTestUnitTests is EigenLayerUnitTestSetup, IContractErrors, IContractEvents, IContractTypes {
// Test state variables
ContractUnderTest contractUnderTest;
function setUp() public virtual override {
EigenLayerUnitTestSetup.setUp();
// Deploy and initialize contract under test
// Set up default test values
// Configure mocks
}
// Helper functions
}
/// @title ContractUnderTestUnitTests_functionName
/// @notice Unit tests for ContractUnderTest.functionName
contract ContractUnderTestUnitTests_functionName is ContractUnderTestUnitTests {
function setUp() public override {
super.setUp();
// Function-specific setup
}
// Revert tests
function test_Revert_Paused() public { }
function test_Revert_NotPermissioned() public { }
function test_Revert_InvalidInput() public { }
// Success tests
function test_functionName_Success() public { }
// Fuzz tests
function testFuzz_functionName_VariableName(uint256 value) public { }
}
Test Contract Naming Convention
- Base contract:
{ContractName}UnitTests - Per-function contracts:
{ContractName}UnitTests_{functionName}
Test Function Naming Convention
| Pattern | Purpose |
|---|---|
test_Revert_Paused |
Test function reverts when paused |
test_Revert_NotPermissioned |
Test function reverts for unauthorized callers |
test_Revert_NotOwner |
Test function reverts for non-owner |
test_Revert_Invalid{Thing} |
Test function reverts for invalid inputs |
test_Revert_{ErrorName} |
Test function reverts with specific error |
test_{functionName}_Success |
Test successful execution (happy path) |
test_{functionName}_{Scenario} |
Test specific scenario |
testFuzz_{functionName}_{Scenario} |
Fuzz test with bounded variable |
Coverage Requirements
For each function, ensure:
1. Revert Cases (Branch Coverage)
- Pausable functions: Test
CurrentlyPausedrevert - Permissioned functions: Test
InvalidPermissionsorNotOwnerrevert - Input validation: Test each require/revert condition
- State checks: Test precondition failures
2. Happy Path (Line Coverage)
- Call function with valid inputs
- Verify emitted events with
cheats.expectEmit(true, true, true, true, address(contract)) - Verify state changes with assertions
3. Fuzz Tests
- Use
bound()to constrain fuzz inputs to valid ranges - Test edge cases and variable inputs
- For complex tests or when standard fuzz inputs are too slow, use the
Randomnesstype fromsrc/test/utils/Random.sol
Using Mocks
External contract calls should use mocks from src/test/mocks/:
// In setUp()
allocationManagerMock.setIsOperatorSet(operatorSet, true);
// Mock pattern: Mocks expose setters to control return values
mock.setSomeValue(expectedValue);
// Then the contract under test calls mock.getSomeValue() and gets expectedValue
Creating New Mock Contracts
If a mock doesn't exist in src/test/mocks/, create one following this pattern:
Location: src/test/mocks/{ContractName}Mock.sol
Structure:
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;
import "forge-std/Test.sol";
import "src/contracts/interfaces/IContractName.sol";
contract ContractNameMock is Test {
receive() external payable {}
fallback() external payable {}
// Storage for mock return values
mapping(bytes32 => bool) public _someMapping;
// Setter to configure mock behavior
function setSomeValue(bytes32 key, bool value) external {
_someMapping[key] = value;
}
// Interface method that returns configured value
function someValue(bytes32 key) external view returns (bool) {
return _someMapping[key];
}
}
Key principles:
- Inherit from
Test- Gives access to cheatcodes if needed - Include
receive()andfallback()- Allows the mock to receive ETH and handle unknown calls gracefully - Only implement what's needed - Add functions on a need-to-implement basis as tests require them
- Prefix storage with
_- Use_variableNamefor internal mock storage to distinguish from interface getters - Create setters for each value - Pattern:
setX()to configure,getX()orx()to return the configured val
Установить unit-test-writer в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGlobGrepEditWriteBash(forge:*)FAQ
Что делает скилл unit-test-writer?
Write Solidity unit tests for EigenLayer contracts. Use when the user asks to write tests, add test coverage, create unit tests, or test a function. Follows project conventions with per-function test contracts and mock dependencies.
Как установить скилл unit-test-writer?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unit-test-writer запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic