Skip to content
Skillpedia
Testing7.0k Β· #13626

direct-tests

What it does

This skill shows how to write quick tests for GenLayer intelligent contracts, which run in memory and finish in tens of milliseconds. It explains the test fixtures and how to fake web responses, for developers testing GenLayer contracts.

When to use it

  • βœ“When you want fast checks on a GenLayer contract while you are still writing it.
  • βœ“When your contract fetches web data and you need to test it with fake responses.
  • βœ“When you want to run one test file or one test case during development.

Skill link

https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/direct-tests/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/direct-tests/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œI want quick tests for my GenLayer contract that do not need a server.”

5 new skills a week. 1 minute to read.

How it works

The skill gives the agent test patterns that use built-in fixtures for the contract, the deployer and test accounts. The agent writes tests that deploy the contract in memory, call its functions and check the results, and runs them with pytest.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Direct Mode Tests

Write fast, in-memory tests for intelligent contracts. No server, no Docker β€” tests run in ~30-50ms.

Running Tests

pytest tests/direct/ -v
pytest tests/direct/test_specific.py -v
pytest tests/direct/test_specific.py::test_one_case -v

Fixtures

Available from 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   β€” test address
    # direct_bob     β€” test address
    pass

All fixtures: direct_vm, direct_deploy, direct_alice, direct_bob, direct_charlie, direct_owner, direct_accounts

Basic Test Pattern

def 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"

Mocking Web Requests

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

    # Pattern: regex matching on URL
    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

Full mock format (when you need headers/method control)

direct_vm.mock_web(
    r"api\.example\.com/data",
    {
        "response": {
            "status": 200,
            "headers": {},
            "body": json.dumps({"key": "value"}).encode()
        },
        "method": "GET"
    }
)

Mocking LLM Responses

For contracts that call gl.nondet.exec_prompt():

direct_vm.mock_llm(
    r".*Extract the match result.*",  # Regex on prompt text
    json.dumps({"score": "2:1", "winner": 1}),
)

Clearing Mocks

direct_vm.clear_mocks()  # Reset between test scenarios

VMContext Cheatcodes

# Set transaction sender
direct_vm.sender = direct_alice

# Set native value (wei)
direct_vm.value = 1000000000000000000  # 1 ETH

# Expect a revert
with direct_vm.expect_revert("Insufficient balance"):
    contract.withdraw(1000)

# Temporary sender change
with direct_vm.prank(direct_bob):
    contract.method()  # Called as bob

# Snapshot and restore state
snap_id = direct_vm.snapshot()
contract.modify_state()
direct_vm.revert(snap_id)  # State restored

# Set account balance
direct_vm.deal(direct_alice, 1000000000000000000)

# Time travel
direct_vm.warp("2024-06-01T12:00:00Z")

Test Organization

tests/direct/
β”œβ”€β”€ conftest.py           # Shared fixtures and mock helpers
β”œβ”€β”€ test_<feature>.py     # Tests per feature/method
└── test_<feature>_web.py # Tests requiring web/LLM mocks

What to Test in Direct Mode

Category Example
State transitions Create β†’ read back β†’ verify fields
Validation / reverts Invalid inputs, unauthorized callers
Access control Owner-only methods, role checks
Edge cases Empty state, boundary values, overflow
Web/LLM parsing Mock responses β†’ verify extraction logic

Common Patterns

Testing access control

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")

Testing state transitions

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"

Reusable mock helpers (conftest.py)

import json

def mock_price_api(direct_vm, pair: str, price: float):
    """Mock a price API response."""
    direct_vm.mock_web(
        rf".*api\.example\.com/prices/{pair}.*",
        {"status": 200, "body": json.dumps({"price": price})},
    )

Tips

  • Always direct_vm.sender = ... bef
FAQ

Do these tests need Docker or a running server?

No. The skill says direct tests run in memory, with no server or Docker.

How can I test a contract that calls the web?

The skill shows how to mock web requests by matching the URL and returning a fake response.

How do I run just one test?

Use pytest with the test file path and the test name, as the skill shows.

Details

Original description by the author

Write and run fast direct mode tests for GenLayer intelligent contracts.

repo: internet-court/internet-court-skill

Popularity

GitHub stars
7.0k
Ranking position
#13626
License
β€”
Updated
10/26/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills