원클릭으로
direct-tests
Write, run, and refine fast direct-mode tests for GenLayer intelligent contracts using the in-memory pytest fixtures.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Write, run, and refine fast direct-mode tests for GenLayer intelligent contracts using the in-memory pytest fixtures.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes or mentions "/commit".
Scaffold a new skill directory using the multi-YAML pattern. Use when user says /create-skill.
Refresh documentation with deterministic generation from source files. Use when user says /docs-refresh.
Deploy, interact with, inspect, and debug GenLayer intelligent contracts with the GenLayer CLI across local Studio, hosted Studio, and testnet.
Install, upgrade, and monitor a GenLayer validator node on AMD64 Linux, including zero-downtime updates and LLM provider setup.
Lint, validate, schema-extract, and typecheck GenLayer intelligent contracts before tests or deployment.
| name | direct-tests |
| description | Write, run, and refine fast direct-mode tests for GenLayer intelligent contracts using the in-memory pytest fixtures. |
Use this skill when you need fast feedback on GenLayer intelligent contracts without a server or Docker stack.
Use this skill for:
Direct mode is ideal for business logic, storage changes, authorization checks, parsing of mocked web or LLM responses, and edge cases. It does not exercise full validator or consensus behavior. Use $integration-tests for that.
In this repo, prefer:
npm run test:direct
Raw pytest commands are still useful when you need to target one file or one case:
pytest tests/direct/ -v
pytest tests/direct/test_specific.py -v
pytest tests/direct/test_specific.py::test_one_case -v
Available from the genlayer-test pytest plugin:
def test_example(direct_vm, direct_deploy, direct_alice, direct_bob):
# direct_vm: VMContext with cheatcodes
# direct_deploy: deploy a contract file
# direct_alice / direct_bob: test addresses
pass
Common fixtures:
direct_vmdirect_deploydirect_alicedirect_bobdirect_charliedirect_ownerdirect_accountsdef test_set_and_get(direct_vm, direct_deploy, direct_alice):
contract = direct_deploy("contracts/my_contract.py")
direct_vm.sender = direct_alice
contract.set_data("hello")
result = contract.get_data(direct_alice)
assert result == "hello"
For contracts that call gl.nondet.web.get():
import json
def test_with_web_mock(direct_vm, direct_deploy, direct_alice):
contract = direct_deploy("contracts/my_contract.py")
direct_vm.sender = direct_alice
direct_vm.mock_web(
r".*api\.example\.com/prices.*",
{"status": 200, "body": '{"price": 42.5}'},
)
contract.update_price("ETH/USD")
assert contract.get_price("ETH/USD") == 42.5
Use the full response form when you need headers or method control:
direct_vm.mock_web(
r"api\.example\.com/data",
{
"response": {
"status": 200,
"headers": {},
"body": json.dumps({"key": "value"}).encode(),
},
"method": "GET",
},
)
For contracts that call gl.nondet.exec_prompt():
import json
direct_vm.mock_llm(
r".*Extract the match result.*",
json.dumps({"score": "2:1", "winner": 1}),
)
direct_vm.clear_mocks()
Use this between scenarios when a single test needs different mocked responses.
# Set transaction sender
direct_vm.sender = direct_alice
# Set native value (wei)
direct_vm.value = 1000000000000000000
# Expect a revert
with direct_vm.expect_revert("Insufficient balance"):
contract.withdraw(1000)
# Temporary sender change
with direct_vm.prank(direct_bob):
contract.method()
# Snapshot and restore state
snap_id = direct_vm.snapshot()
contract.modify_state()
direct_vm.revert(snap_id)
# Set account balance
direct_vm.deal(direct_alice, 1000000000000000000)
# Time travel
direct_vm.warp("2024-06-01T12:00:00Z")
Focus direct tests on:
def test_only_owner(direct_vm, direct_deploy, direct_alice, direct_bob):
contract = direct_deploy("contracts/my_contract.py")
direct_vm.sender = direct_alice
contract.create_item("item_1")
direct_vm.sender = direct_bob
with direct_vm.expect_revert("Only owner"):
contract.delete_item("item_1")
def test_state_flow(direct_vm, direct_deploy, direct_alice):
contract = direct_deploy("contracts/my_contract.py")
direct_vm.sender = direct_alice
contract.create_item("item_1")
assert contract.get_item("item_1")["status"] == "pending"
contract.approve_item("item_1")
assert contract.get_item("item_1")["status"] == "approved"
Put reusable helpers in tests/direct/conftest.py:
import json
def mock_price_api(direct_vm, pair: str, price: float):
direct_vm.mock_web(
rf".*api\.example\.com/prices/{pair}.*",
{"status": 200, "body": json.dumps({"price": price})},
)
$genvm-lint on the contract first.$integration-tests only when validator flow or real environments matter.direct_vm.sender before calling write methods.genvm-lint check ... --json when you need to confirm method names or constructor shape before writing tests.