integration-tests
Skill này làm gì
Skill này chỉ cách chạy test cho contract GenLayer trên một môi trường thật thay vì trong bộ nhớ. Nó bao gồm chọn mạng và viết test xác nhận mỗi giao dịch thành công trước khi kiểm tra trạng thái.
Khi nào nên dùng
- ✓Khi bạn muốn test contract GenLayer trên một mạng thật thay vì trong bộ nhớ.
- ✓Khi bạn cần xác nhận một contract hoạt động trên testnet trước khi ra mắt.
- ✓Khi một giao dịch có vẻ thành công nhưng trạng thái contract sai.
Liên kết skill
https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/integration-tests/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tôi muốn chạy test tích hợp cho contract GenLayer của mình trên mạng studio và xem kết quả.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent chạy công cụ gltest trên mạng bạn chọn và viết test để triển khai contract, gửi giao dịch và đọc trạng thái. Nó kiểm tra kết quả thực thi của từng giao dịch trước khi đọc contract.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Vì sao một giao dịch được đánh dấu accepted vẫn cần kiểm tra?
Skill giải thích accepted và finalized chỉ mô tả vòng đời giao dịch. Một giao dịch có thể kết thúc với lỗi thực thi, nên agent phải kiểm tra kết quả thực thi.
Tôi có thể test trên mạng nào?
Skill liệt kê localnet, studionet và testnet Bradbury, và mặc định lấy từ file cấu hình dự án.
Vì sao dùng các cờ verbose?
Skill khuyên dùng khi phát triển để bạn thấy được đầu ra.
Chi tiết
Mô tả gốc của tác giả
Write and run integration tests against a GenLayer environment.
Độ phổ biến
- Sao GitHub
- 7.0k
- Vị trí xếp hạng
- #13629
- Giấy phép
- —
- Cập nhật
- 26/10/2026
Bình luận
- …
Thêm skill từ kho mã này
internet-court
7.0kGiúp agent của bạn thanh toán, thuê hoặc giao dịch an toàn với một agent AI khác hoặc dịch vụ trả phí, và chỉ đến hướng dẫn chuyên sâu phù hợp.
genlayer-erc7710-connector
7.0kGiúp agent của bạn kết nối kết quả đánh giá AI với hệ thống quyền hạn, để một đánh giá xấu có thể hạn chế hoặc hủy quyền của agent.
genlayer-intelligent-contracts
7.0kGiúp agent của bạn xác định quy tắc, bằng chứng và đầu ra của một AI judge kiểm tra xem agent khác có làm đúng nhiệm vụ được ủy quyền hay không.
x402-erc7710
7.0kGiúp agent của bạn trả tiền cho dịch vụ web theo từng yêu cầu, và thiết lập chi tiêu định kỳ nằm trong ngân sách quyền hạn.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.