// PKGPATH: gno.land/r/aib/main package main import ( "encoding/hex" "testing" "time" "gno.land/p/aib/ibc/lightclient/tendermint" tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing" "gno.land/p/aib/ibc/types" "gno.land/p/aib/ics23" appstesting "gno.land/r/aib/ibc/apps/testing" "gno.land/r/aib/ibc/core" ) // Timeout success func main(cur realm) { var ( chainID = "atomone-1" trustedHeight = types.NewHeight(1, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) apphash = tmtesting.Hash("apphash-1") // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A== val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1) // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g== val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1) trustedValset = tendermint.NewValset(val1, val2) consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash()) counterpartyID = "07-tendermint-42" ) clientID := core.CreateClient(cross(cur), clientState, consensusState) core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID) // Register app var ( app = appstesting.NewApp(cross(cur)) appPortID = "app" ) core.RegisterApp(cross(cur), appPortID, app) // Send a packet sendPacket := types.MsgSendPacket{ SourceClient: clientID, TimeoutTimestamp: uint64(time.Now().Add(10 * time.Minute).Unix()), Payloads: []types.Payload{{ SourcePort: appPortID, DestinationPort: "destinationPort", Encoding: "application/json", Value: []byte("{}"), Version: "v1", }}, } sequence := core.SendPacket(cross(cur), sendPacket) // Change block time to after the timeout ctx := testing.GetContext() ctx.Time = time.Now().Add(12 * time.Minute) testing.SetContext(ctx) // Update client with a block created after the timeout // NOTE code generated by: // go run -C ./cmd/gen-block-signatures . -apphash-hex=82ea91f259352674360c621c4b0a1975cc076e3792b6d22a8bfbe8e7f7d0d2d7 -chainid=atomone-1 -header-time-shift=12 -height=12 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g== // NOTE this apphash was provided by the gen-proof command below. apphash, _ = hex.DecodeString("82ea91f259352674360c621c4b0a1975cc076e3792b6d22a8bfbe8e7f7d0d2d7") trustedHeight = clientState.LatestHeight var ( newHeight = uint64(12) commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z") newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(12)) valset = tendermint.NewValset(val1, val2) nextValset = tendermint.NewValset(val1, val2) signatures = []tendermint.CommitSig{ { BlockIDFlag: tendermint.BlockIDFlagCommit, ValidatorAddress: valset.Validators[0].Address, Timestamp: commitTimestamp, Signature: []byte("\x90\x76\xf4\x27\xaf\x23\xd0\xcb\x97\xb1\x6d\xfa\x86\xae\x6d\x46\xe9\xe4\x65\x76\xf2\x6a\x1d\x5f\x83\xa6\x9e\x4a\x28\x55\x6e\x74\x84\x02\xff\x15\xc0\x41\xed\x15\xb7\xef\x3a\x3f\xe1\xe6\xa0\x8f\x34\x83\x9c\x2e\x27\x26\x69\x00\x73\x45\x87\xd2\x3c\xe6\x12\x07"), }, { BlockIDFlag: tendermint.BlockIDFlagCommit, ValidatorAddress: valset.Validators[1].Address, Timestamp: commitTimestamp, Signature: []byte("\x45\x61\x3b\x34\x58\xa1\xf5\x75\x16\x6f\xb3\xad\xda\x12\xa8\xef\xb6\x64\x3f\x6b\x80\x73\x74\xe3\x15\x6f\xe1\x3b\x3f\x50\xed\x0d\xbc\xa7\x54\x11\x72\xe3\x71\x22\x95\xec\x77\x93\x45\x03\x67\xa5\x00\x4c\x84\x3b\x1c\xa4\xf7\x0e\x95\xd1\xe2\x04\xb6\x91\x63\x09"), }, } msgHeader = tmtesting.NewMsgHeader( chainID, newTimestamp, apphash, newHeight, trustedHeight, valset, nextValset, trustedValset, signatures, ) ) core.UpdateClient(cross(cur), clientID, msgHeader) // Timeout the packet // Generate the proof that no RecvPacket have been received by the // counterparty chain. specs := ics23.IavlSpec() // NOTE code generated by: // go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'receipt' proof := []ics23.CommitmentProof{ // iavl proof ics23.CommitmentProof_Nonexist{ Nonexist: &ics23.NonExistenceProof{ Key: []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x02\x00\x00\x00\x00\x00\x00\x00\x01"), Left: &ics23.ExistenceProof{ Key: []byte("\x50"), Value: []byte("\x50"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00\x02\x02"), }, Path: []*ics23.InnerOp{ { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x04\x06\x02\x20"), Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x06\x0a\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"), Suffix: []byte(""), }, }, }, Right: &ics23.ExistenceProof{ Key: []byte("\x72"), Value: []byte("\x72"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00\x02\x02"), }, Path: []*ics23.InnerOp{ { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x02\x04\x02\x20"), Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x04\x06\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"), Suffix: []byte(""), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x06\x0a\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"), Suffix: []byte(""), }, }, }, }, }, // rootmulti proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"), Value: []byte("\x38\x22\xf3\x2f\x21\x66\x53\x63\x29\x4f\x96\xed\xda\x15\xa7\x81\x1a\x67\x6c\x2b\xa9\xdd\xcc\xec\x46\x63\x64\xf1\x00\x69\x82\x7d"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00"), }, Path: []*ics23.InnerOp{}, }, }, } timeoutPacket := types.MsgTimeout{ Packet: types.Packet{ Sequence: sequence, SourceClient: clientID, DestinationClient: counterpartyID, TimeoutTimestamp: sendPacket.TimeoutTimestamp, Payloads: sendPacket.Payloads, }, ProofUnreceived: proof, ProofHeight: msgHeader.GetHeight(), } res := core.Timeout(cross(cur), timeoutPacket) println("res:", res) println("\n----------- assert render clients/07-tendermint-1/packet_commitments") println(core.Render("clients/" + clientID + "/packet_commitments")) println("----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared)") println(core.Render("clients/" + clientID + "/packet_commitments/1")) println("\n----------- app report") println(app.Report()) // assert NOOP response (res=1) if timeout is resubmitted res = core.Timeout(cross(cur), timeoutPacket) println("res:", res) println("\n----------- app report") println(app.Report()) } // Output: // res: (2 gno.land/p/aib/ibc/types.ResponseResultType) // // ----------- assert render clients/07-tendermint-1/packet_commitments // {"items":[],"page":1,"total":1} // ----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared) // {"error":"sequence 1 not found"} // // ----------- app report // OnSendPacket (1) // - sourceClient: 07-tendermint-1 // - destinationClient: 07-tendermint-42 // - sequence: 1 // - payload: // - sourcePort: app // - destinationPort: destinationPort // - version: v1 // - encoding: application/json // - value: {} // // OnRecvPacket (0) // OnTimeoutPacket (1) // - sourceClient: 07-tendermint-1 // - destinationClient: 07-tendermint-42 // - sequence: 1 // - payload: // - sourcePort: app // - destinationPort: destinationPort // - version: v1 // - encoding: application/json // - value: {} // // OnAcknowledgementPacket (0) // // res: (1 gno.land/p/aib/ibc/types.ResponseResultType) // // ----------- app report // OnSendPacket (1) // - sourceClient: 07-tendermint-1 // - destinationClient: 07-tendermint-42 // - sequence: 1 // - payload: // - sourcePort: app // - destinationPort: destinationPort // - version: v1 // - encoding: application/json // - value: {} // // OnRecvPacket (0) // OnTimeoutPacket (1) // - sourceClient: 07-tendermint-1 // - destinationClient: 07-tendermint-42 // - sequence: 1 // - payload: // - sourcePort: app // - destinationPort: destinationPort // - version: v1 // - encoding: application/json // - value: {} // // OnAcknowledgementPacket (0) // Events: // [ // { // "type": "create_client", // "attrs": [ // { // "key": "client_id", // "value": "07-tendermint-1" // }, // { // "key": "client_type", // "value": "07-tendermint" // }, // { // "key": "consensus_heights", // "value": "1/2" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "send_packet", // "attrs": [ // { // "key": "packet_source_client", // "value": "07-tendermint-1" // }, // { // "key": "packet_dest_client", // "value": "07-tendermint-42" // }, // { // "key": "packet_sequence", // "value": "1" // }, // { // "key": "packet_timeout_timestamp", // "value": "1234568490" // }, // { // "key": "encoded_packet_hex", // "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "update_client", // "attrs": [ // { // "key": "client_id", // "value": "07-tendermint-1" // }, // { // "key": "client_type", // "value": "07-tendermint" // }, // { // "key": "consensus_heights", // "value": "1/12" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "timeout_packet", // "attrs": [ // { // "key": "packet_source_client", // "value": "07-tendermint-1" // }, // { // "key": "packet_dest_client", // "value": "07-tendermint-42" // }, // { // "key": "packet_sequence", // "value": "1" // }, // { // "key": "packet_timeout_timestamp", // "value": "1234568490" // }, // { // "key": "encoded_packet_hex", // "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // } // ]