// PKGPATH: gno.land/r/aib/main package main import ( "chain" "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" "gno.land/r/aib/ibc/apps/transfer" "gno.land/r/aib/ibc/core" ) // OnTimeout: success with native coin func main(cur realm) { var ( chainID = "atomone-1" trustedHeight = types.NewHeight(1, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) apphash, _ = hex.DecodeString("a119217258843545bc79dd7df4c050c6c2a21b1de7c132dd065fd7463f743e2d") // 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) // Transfer the 100ugnot we want to ack coins := chain.NewCoins(chain.NewCoin("ugnot", 100)) testing.SetRealm(testing.NewUserRealm("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")) testing.SetOriginSend(coins) println("----------- assert render total_escrow/ugnot before Transfer") println(transfer.Render("total_escrow/ugnot")) sendPacket, sequence := transfer.Transfer(cross(cur), clientID, "atone1user", "ugnot", 100, uint64(time.Now().Add(10*time.Minute).Unix()), "memo") println("----------- assert render total_escrow/ugnot after Transfer") println(transfer.Render("total_escrow/ugnot")) // 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 apphash generated by the gen-proof command below apphash, _ = hex.DecodeString("82ea91f259352674360c621c4b0a1975cc076e3792b6d22a8bfbe8e7f7d0d2d7") trustedHeight = clientState.LatestHeight var ( commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z") newHeight = uint64(12) 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(), } // For the refund to work we have to fill the realm account transferAppAddr := chain.PackageAddress("gno.land/r/aib/ibc/apps/transfer") testing.IssueCoins(transferAppAddr, coins) res := core.Timeout(cross(cur), timeoutPacket) println("\ntimeout res:", res) println("----------- assert render total_escrow/ugnot after Ack") println(transfer.Render("total_escrow/ugnot")) } // Output: // ----------- assert render total_escrow/ugnot before Transfer // {"denom":"ugnot","amount":0} // ----------- assert render total_escrow/ugnot after Transfer // {"denom":"ugnot","amount":100} // // timeout res: (2 gno.land/p/aib/ibc/types.ResponseResultType) // ----------- assert render total_escrow/ugnot after Ack // {"denom":"ugnot","amount":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": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a7f0a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a480a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e6531757365722a046d656d6f" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "ibc_transfer", // "attrs": [ // { // "key": "sender", // "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" // }, // { // "key": "receiver", // "value": "atone1user" // }, // { // "key": "denom", // "value": "ugnot" // }, // { // "key": "amount", // "value": "100" // }, // { // "key": "memo", // "value": "memo" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // }, // { // "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": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a7f0a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a480a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e6531757365722a046d656d6f" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "timeout", // "attrs": [ // { // "key": "receiver", // "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" // }, // { // "key": "denom", // "value": "ugnot" // }, // { // "key": "amount", // "value": "100" // }, // { // "key": "memo", // "value": "memo" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // } // ]