Introducing a new way to review your PRs.

Read the announcement

lfdt-ibc / ibc-go

Inter-Blockchain Communication Protocol (IBC) implementation in Golang.

View on GitHub

20 documents · Updated Nov 13, 2026

docs / go-testing-harness

Go testing harness

The Go testing harness provides a small, repeatable network for module-level IBC tests. It lets a test create in-memory chains, connect them through IBC clients and handshakes, relay packets with proofs, and inspect the resulting state without running external nodes. See also integration and test infrastructure and end-to-end suite and simulation app.

Test network

The harness models a test network as several application-backed chains. A coordinator owns the chains and keeps their block times aligned, while each chain exposes accounts, validators, headers, application state, and IBC state to the test.

flowchart LR
    Test[Module test] --> Coordinator[Coordinator]
    Coordinator --> ChainA[TestChain A]
    Coordinator --> ChainB[TestChain B]
    ChainA <-->|IBC path| ChainB
    ChainA --> AppA[In-memory testing app]
    ChainB --> AppB[In-memory testing app]

Coordinator

The Coordinator creates a set of TestChain values and provides one clock for the whole test network. A block commit on a chain advances that shared time, so client headers and proof times remain usable across chains. Tests normally call NewCoordinator and select chains by the generated test chain ID. NewCustomAppCoordinator lets a test supply a different application factory. testing/coordinator.go is the main entry point.

The coordinator also offers group operations for committing blocks and for setting up mock or transfer channels. The path methods are the preferred setup interface; the older coordinator setup methods only delegate to them.

References: testing/coordinator.go• L21-51 testing/coordinator.go• L54-85 testing/coordinator.go• L88-142 testing/coordinator.go• L157-173

TestChain

The TestChain is the chain-side test boundary. It wraps a testing application with a proposed header, the last committed IBC header, validator sets, trusted validator history, transaction accounts, and codec and transaction settings. Its constructor starts from an initialized genesis state with bonded validators and funded sender accounts, then commits the first block so another chain can create a client for it.

NextBlock finalizes and commits the proposed block, applies validator changes, records trusted validators, and prepares the next header. SendMsgs signs and delivers a transaction, commits its result, updates the shared clock, and reports a non-zero transaction result as an error. GetContext makes direct keeper writes target the next block state, including writes made between commits. This keeps test setup changes subject to the same commit boundary as transaction changes.

References: testing/chain.go• L51-95 testing/chain.go• L97-182 testing/chain.go• L221-240 testing/chain.go• L338-388 testing/chain.go• L390-453 testing/chain_test.go• L81-94

Application factory

The TestingApp interface is the minimum application surface that the harness needs. It provides ABCI block and transaction calls plus access to the base application, IBC keeper, transaction configuration, codec, and committed height. An AppCreator returns this application with its genesis data, which allows a module test to replace the default in-memory simulation app while keeping the same chain and path model.

The default factory creates an in-memory SimApp. The standard app exposes core IBC, transfer, interchain accounts, packet-forwarding, rate-limit, mock, and IBC v2 routes so module tests can use a common application boundary. Its test transaction checks also include the IBC redundant-relay check.

References: testing/testing_app.go• L36-58 testing/testing_app.go• L60-142 testing/…/app.go• L141-189 testing/…/app.go• L402-486 testing/…/ante.go• L15-52

IBC topology

The harness separates one chain-side endpoint from the pair of endpoints that form a path. This matches the IBC model: clients and connections belong to a chain, while a channel has a local side and a counterparty side.

Endpoint

An Endpoint identifies one side of an IBC link. It points to its TestChain, stores the client, connection, and channel IDs, and holds the configuration for the client type, connection delay, channel port, version, and ordering. Its Counterparty link gives each endpoint access to the chain that owns the other side.

Endpoint operations cover the main test actions: create or update a client, perform connection and channel handshake steps, send and receive packets, write or acknowledge acknowledgements, and exercise timeout paths. The operations query the counterparty chain for the proof needed by the next IBC message. They also expose small state helpers for client, consensus, connection, and channel records.

References: testing/endpoint.go• L26-72 testing/endpoint.go• L91-165 testing/endpoint.go• L232-316 testing/endpoint.go• L331-427 testing/endpoint.go• L441-610 testing/endpoint.go• L626-704

Path

The Path is a pair of linked endpoints between two test chains. NewPath creates the default topology, while NewTransferPath selects the transfer port and its channel version. A path can set both channels to ordered delivery, disable unique channel IDs for legacy cases, or be reversed when the same link must be viewed from the other direction.

The standard setup moves through clients, connections, and channels. IBC v2 setup stops after clients and counterparty registration because v2 does not use the v1 connection and channel handshake sequence.

References: testing/path.go• L15-60 testing/path.go• L135-185 testing/path.go• L187-246 testing/endpoint_v2.go• L15-23 testing/config.go• L15-62

Handshake lifecycle

The handshake helpers express the order in which a relayer would establish an IBC link. Each step commits state on one chain, updates the client that observes the counterparty, obtains a proof, and submits the next message. The helper finishes with a client update so both sides can use the new connection or channel state.

sequenceDiagram
    participant A as Chain A endpoint
    participant B as Chain B endpoint
    A->>A: Create client
    B->>B: Create client
    A->>A: ConnectionOpenInit
    B->>B: Update client and ConnectionOpenTry
    A->>A: Update client and ConnectionOpenAck
    B->>B: Update client and ConnectionOpenConfirm
    A->>A: ChannelOpenInit
    B->>B: Update client and ChannelOpenTry
    A->>A: Update client and ChannelOpenAck
    B->>B: Update client and ChannelOpenConfirm

References: testing/path.go• L152-216 testing/path.go• L218-246 testing/endpoint.go• L91-164 testing/endpoint.go• L232-305 testing/endpoint.go• L331-427

Packet relay

Packet relay helpers model the two proof-bearing halves of IBC packet delivery. For v1, Path.RelayPacketWithResults finds the source commitment on either side, updates the receiving client, submits packet receipt, reads the acknowledgement from the receive result, and submits the acknowledgement back to the source. Endpoint methods also expose timeout and timeout-on-close operations.

For v2, the endpoint sends a message with one or more payloads, reads the sequence from the typed transaction response, receives the packet on the counterparty, obtains a structured acknowledgement, and acknowledges it on the source. Both versions update the observing client after state changes so later proof checks use current consensus state.

References: testing/path.go• L63-126 testing/endpoint.go• L441-597 testing/endpoint_v2.go• L25-64 testing/endpoint_v2.go• L67-151

Event and proof handling

The harness turns ABCI events and application state into the values that a test needs to continue an IBC flow. This keeps module tests focused on behavior instead of event encoding, commitment keys, or proof conversion.

Event extraction

Event helpers extract client IDs, connection IDs, channel IDs, packets, and acknowledgements from transaction results. V1 packet events carry packet fields as named attributes. V2 events may carry the packet as one encoded value or expose a smaller set of packet fields. The parsers return an error when the expected event or value is missing or cannot be decoded.

The event assertion helper checks event type and expected key-value attributes. It does not compare the event index flag, and it accounts for the message index attribute that the Cosmos SDK adds to retrieved events.

References: testing/events.go• L23-60 testing/events.go• L63-153 testing/events.go• L155-239 testing/events.go• L242-345 testing/events_test.go• L23-228 testing/events_test.go• L230-392

Commitment proofs

Proof helpers query application state at the height that an IBC client can verify. TestChain supports IBC store proofs, upgrade store proofs, and consensus-state proofs. Endpoint operations use these helpers for connection, channel, packet commitment, acknowledgement, receipt, and timeout messages.

The solo machine helper uses the same host key model to build signed proofs for a counterparty that is not a running test chain. It can create client and handshake messages, send packets, and produce proofs for commitments, acknowledgements, absent receipts, and closed channels.

References: testing/chain.go• L260-335 testing/endpoint.go• L75-89 testing/endpoint.go• L308-316 testing/endpoint.go• L481-595 testing/solomachine.go• L39-71 testing/solomachine.go• L126-150 testing/solomachine.go• L266-447 testing/solomachine.go• L485-609

Mock application components

The mock packages provide controlled IBC applications for tests that need channel and packet behavior without a real application feature. They make success, failure, asynchronous acknowledgement, callback, event, and middleware cases available through small test-controlled values.

V1 mock application

The v1 mock application implements the IBC module callback contract used by the port router. IBCApp stores optional callback functions. IBCModule delegates to those functions when present and supplies safe defaults when they are absent. The default receive behavior returns a success acknowledgement for known mock data, no acknowledgement for asynchronous data, and an error acknowledgement for other data.

The mock also emits distinct receive, acknowledgement, and timeout events. Tests can therefore verify both the IBC result and the application callback boundary.

References: testing/…/ibc_app.go• L12-127 testing/…/ibc_module.go• L22-43 testing/…/ibc_module.go• L44-160 testing/…/events.go• L7-41 testing/…/mock.go• L28-53

V2 mock application

The v2 mock application uses payloads rather than v1 packet data. Its callback set covers send, receive, acknowledgement, and timeout actions. The default receive result distinguishes success, asynchronous handling, and failure, while helper constructors create payloads for each case.

References: testing/…/ibc_app.go• L11-16 testing/…/ibc_module.go• L15-80 testing/…/mock.go• L11-47

Middleware mock

The block-upgrade middleware mock wraps the same callback model as the v1 mock application. It supplies channel and packet callbacks and reports an application version, while its ICS4 wrapper and underlying-application hooks are deliberately unused. This gives middleware tests a controlled stack boundary without adding a real upgradeable module.

References: testing/…/middleware.go• L21-35 testing/…/middleware.go• L38-132 testing/…/middleware.go• L135-171

Test utilities

The remaining helpers support common module-test needs that do not belong to one endpoint operation. They provide stable defaults, custom counterparty behavior, transaction response decoding, validator updates, proposal progress, generated test data, and error checks.

Default values

The testing package centralizes IDs, client timing, ports, channel versions, denominations, packet data, commitment prefixes, and timeout values. The defaults make independent module tests use the same network assumptions. Config objects allow a test to change the client, connection, or channel behavior without rebuilding the topology.

References: testing/values.go• L25-81 testing/config.go• L15-62

Solo machine counterparty

Solomachine represents a signed, non-chain counterparty for light-client and proof tests. It tracks signing keys, sequence, time, and diversifier state. It can advance its signed headers and generate a single-key or multisignature proof, which lets a test cover client verification and packet paths without a second application.

References: testing/solomachine.go• L36-101 testing/solomachine.go• L104-198 testing/solomachine.go• L201-263 testing/solomachine.go• L450-482

State and response helpers

Chain helpers expose client heights, timeout values, acknowledgements, and sender accounts. Other utilities apply validator updates, move governance proposals through their time periods, decode typed message responses, generate bounded random strings, and match wrapped errors to a target error. These helpers keep module tests aligned with the same block, time, and transaction rules as path tests.

References: testing/chain.go• L456-489 testing/chain.go• L597-661 testing/utils.go• L23-99 testing/…/test_helpers.go• L107-138

Change checklist

When these files or sections are changed, remember to consider these:

  • When event names or attribute encodings change, update the v1 and v2 event parsers together with the path relay assumptions.
  • When client header, block commit, validator, or clock behavior changes, check proof heights, trusted validator records, and every call that updates a counterparty client.
  • When endpoint defaults change, check NewPath, NewTransferPath, mock channel setup, and module callbacks that validate port, version, or ordering.
  • When the TestingApp contract changes, check the default app creator and every custom app creator used by module tests.
  • When v2 packet or acknowledgement encoding changes, check both response decoding in endpoint_v2.go and event decoding in events.go.
  • When mock callback defaults or payload values change, check tests that use success, failure, and asynchronous packet paths.
  • When the testing app routes or ante handler changes, check both v1 and v2 mock paths and tests that depend on duplicate-relay rejection.
  • When GetContext or block finalization changes, check direct keeper writes made before CommitBlock and writes made during message execution.

Important failure modes

TriggerConsequenceGuard
A test commits a chain without advancing the coordinator timeCounterparty headers can have stale or equal times, so client updates or proof checks failCommit through Coordinator.CommitBlock, CommitNBlocks, or a transaction path that advances the shared clock
A packet is relayed before the receiving chain updates its clientThe receive message has no usable proof of the source commitmentUse the path or endpoint relay helpers, which update the observing client before receipt
A v1 parser reads v2 events, or a v2 parser reads v1 eventsPacket or acknowledgement extraction fails or produces incomplete dataSelect the parser that matches the channel protocol and event encoding
A mock test expects an acknowledgement for async mock dataThe mock returns no v1 acknowledgement or an async v2 resultAssert the asynchronous result and complete the later acknowledgement step explicitly
An endpoint is created without linking its counterpartyClient creation, proof queries, and handshake steps cannot find the other chainBuild endpoints with NewPath or set both Counterparty fields before use
A solo machine proof is generated for the wrong host key or sequenceClient verification rejects the proofUse the matching Solomachine proof helper for the state being tested and keep its sequence in step
A direct keeper write uses a context outside the next block stateThe test may read a value that is not included in the next commitObtain the chain context through TestChain.GetContext and commit the chain before relying on the value
A v2 packet test assumes the packet always comes from an eventPacket construction fails even though the typed message response contains the sequenceUse the v2 send result and use event parsing only for event-shaped inputs

Key files

FileWhy to read it
testing/coordinator.goDefines the test network, shared time, chain lookup, and block commit rules.
testing/chain.goDefines the chain boundary, transaction flow, block lifecycle, validator state, context, and proof queries.
testing/testing_app.goDefines the application contract and the default in-memory app factory.
testing/path.goDefines endpoint pairs, setup sequences, and v1 packet relay.
testing/endpoint.goDefines client, connection, channel, packet, timeout, and state operations for one chain side.
testing/endpoint_v2.goDefines v2 client-counterparty registration and payload packet flow.
testing/events.goDefines event-to-ID, packet, acknowledgement, and event assertion helpers.
testing/config.go and testing/values.goDefine the defaults that give paths and module tests a shared starting point.
testing/…/ibc_app.go and testing/…/ibc_module.goShow how v1 callback behavior is injected and how default mock results work.
testing/…/ibc_app.go and testing/…/ibc_module.goShow the v2 callback and payload model.
testing/…/middleware.goShows the controlled middleware boundary used by stack tests.
testing/…/app.go and testing/…/ante.goDefine the common in-memory app routes and transaction checks used by the harness.
testing/solomachine.goShows how tests model a signed non-chain counterparty and its proofs.
testing/utils.go and testing/…/test_helpers.goProvide shared state, response, proposal, validator, and transaction helpers.
modules/…/transfer_test.goShows a module test that builds paths and relays transfers across more than one chain.