跳到正文
Skillpedia
测试7.0k · #13629

integration-tests

它能做什么

这项技能展示如何在真实环境而非内存中运行 GenLayer 合约测试。内容涵盖选择网络,以及编写测试,在检查状态之前先确认每笔交易已成功。

适用场景

  • ✓当你想在真实网络而不是内存中测试 GenLayer 合约的时候。
  • ✓当你需要在上线前确认合约在测试网上能正常运行时。
  • ✓当交易看似成功,但合约状态不正确的时候。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/integration-tests/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想在 studio 网络上为我的 GenLayer 合约运行集成测试,并查看输出。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会针对你选择的网络运行 gltest 工具,并编写测试,用于部署合约、发送交易和读取状态。在读取合约之前,它会检查每笔交易的执行结果。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Integration Tests

Run contracts against a real GenLayer environment (GLSim, Studio, or testnet) with full consensus validation.

Running Tests

# Against default network (from gltest.config.yaml)
gltest tests/integration/ -v -s

# Against specific network
gltest tests/integration/ -v -s --network localnet
gltest tests/integration/ -v -s --network studionet
gltest tests/integration/ -v -s --network testnet_bradbury

Always use -v -s for visible output during development.

Test Pattern

from gltest import get_contract_factory
from gltest.assertions import tx_execution_succeeded

def test_full_flow():
    factory = get_contract_factory("MyContract")
    contract = factory.deploy(args=[])

    # Write methods return transaction receipts
    tx_receipt = contract.set_data(args=["hello"]).transact()
    assert tx_execution_succeeded(tx_receipt)

    # Read methods return values directly
    result = contract.get_data(args=[contract.address]).call()
    assert result == "hello"

ACCEPTED and FINALIZED are transaction lifecycle states, not proof that contract execution succeeded. A transaction can be accepted and finalized with an execution error, and failed execution applies no state changes. For deploy transactions, failed execution means no contract is created.

Always assert tx_execution_succeeded(receipt) before reading state, checking schema/code, or treating a missing contract as an infrastructure issue.

Key Differences from Direct Mode

Direct Mode Integration Tests
Speed ~30ms ~seconds to minutes
Server required No Yes (GLSim, Studio, or testnet)
Consensus Leader only Full leader + validators
Write methods Return values directly Return transaction receipts
Read methods Return values directly Use .call()
Mocking mock_web() / mock_llm() Real web/LLM calls

Write vs Read Calls

Write methods (state-changing):

# .transact() submits and waits for consensus
tx_receipt = contract.method_name(args=[arg1, arg2]).transact()
assert tx_execution_succeeded(tx_receipt)

Read methods (view-only):

# .call() reads without transaction
result = contract.view_method(args=[arg1]).call()

Configuration (gltest.config.yaml)

contract_path: contracts/

networks:
  localnet:
    # GenLayer Studio running locally
  studionet:
    # studio.genlayer.com — gasless, no funding needed (0 GEN balance is fine)
  testnet_bradbury:
    accounts:
      - "${ACCOUNT_PRIVATE_KEY_1}"
      - "${ACCOUNT_PRIVATE_KEY_2}"

Test Markers

import pytest

@pytest.mark.slow
def test_expensive_operation():
    """Excluded by default. Run with: gltest -m slow"""
    pass

Environments

  • GLSim (pip install genlayer-test[sim], glsim --port 4000 --validators 5) — lightweight, no Docker, ~1s startup. Runs Python natively, not in GenVM. Good for fast iteration.
  • Studio local (genlayer up) — full GenVM, real consensus, Docker required. Validates runtime compatibility.
  • studio.genlayer.com (StudioNet) — hosted Studio, no setup, rate-limited (see Common Issues). Gasless: no tokens required. Accounts with 0 GEN balance can deploy and run tests normally.
  • Testnet Bradbury — real network, requires funded accounts.

When to Use Integration Tests

  • Validating consensus (leader + validators agree)
  • Testing real web requests and LLM calls
  • Pre-deployment smoke tests
  • Verifying contract works in actual GenVM (not just Python runner)

Direct mode should cover most logic testing. Use integration tests for final validation before deploying.

Common Issues

"Transaction not found" errors

Clear cache: rm -rf .gltest_cache

Slow tests

Run single tests during development:

gltest tests/integration/test_file.py::test_specific -v -s

JSON serialization

When working with mock validators, convert to dicts:

transaction_context = {"validators": [v.to_dict() for v in mock_validators]}

Studio rate limits (HTTP 429 / -32429)

studio.genlayer.com enforces per-IP limits: 60 req/min, 1000 req/hr, 10000 req/day. Limits aren't permanent — once tripped, further requests are rejected until the current window resets (next minute / hour / day cycle). Throttle batch tests, run heavy suites against localnet (GLSim or local Studio), or pace .transact() calls.

-32028 is the related pending-queue cap — **up to 32 in-flight

常见问题

为什么标记为已接受的交易仍需要检查?

该技能说明,已接受和已最终确认只描述交易的生命周期。交易可能以执行错误结束,因此智能体必须检查执行结果。

我可以在哪些网络上测试?

该技能列出 localnet、studionet 和 testnet Bradbury,默认值来自项目配置文件。

为什么要使用详细输出选项?

该技能建议在开发期间使用,以便查看输出内容。

详情

作者的原始描述

Write and run integration tests against a GenLayer environment.

repo: internet-court/internet-court-skill

热度

GitHub 星标
7.0k
排名
#13629
许可证
—
更新时间
2026/10/26

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能