// PKGPATH: gno.land/r/aib/main package main import ( "encoding/hex" "time" 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" ) // RecvPacket success with OnRecvPacket error func main(cur realm) { var ( chainID = "chain-id-2" trustedHeight = types.NewHeight(2, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) // NOTE apphash generated by the gen-proof command below apphash, _ = hex.DecodeString("8da82bb625ee946f4b7aa03a82010cb115f9ce3879c7caad8d92e71eb821996e") trustedValset = tmtesting.GenValset() 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 = "appID" ) app.SetOnRecvPacketReturn(types.RecvPacketResult{ Status: types.PacketStatus_Failure, Acknowledgement: []byte{0x01}, }) core.RegisterApp(cross(cur), appPortID, app) // Receive the packet // Generate the proof of existence of the packet commitment for the // counterparty chain. specs := ics23.IavlSpec() // NOTE code generated by: // go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'packet' '{"sequence":1,"source_client":"07-tendermint-42","destination_client":"07-tendermint-1","timeout_timestamp":1234571490,"payloads":[{"source_port":"appID","destination_port":"appID","encoding":"application/json","value":"e30=","version":"v1"}]}' proof := []ics23.CommitmentProof{ // iavl proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ 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\x01\x00\x00\x00\x00\x00\x00\x00\x01"), Value: []byte("\x23\x99\xf6\x84\x16\xb7\xd0\x09\x3b\xe4\x9e\x5f\x8e\xe1\xbe\x1c\x8e\x07\xa0\x93\xc5\x67\x09\x03\x46\xce\x36\xc9\x7d\x11\x71\x71"), 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\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("\x04\x08\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\x0c\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("\xeb\xfd\x02\x8a\x5d\xe1\xcf\x93\xde\x5d\x0b\xa8\xcf\x6e\x0d\x5e\x29\xf8\x80\x1a\x08\x0b\x07\x20\x3c\xf1\xca\xf2\xf4\xdd\xd3\x10"), 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{}, }, }, } recvPacket := types.MsgRecvPacket{ Packet: types.Packet{ Sequence: 1, SourceClient: counterpartyID, DestinationClient: clientID, TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()), Payloads: []types.Payload{{ SourcePort: "appID", DestinationPort: "appID", Encoding: "application/json", Value: []byte("{}"), Version: "v1", }}, }, ProofCommitment: proof, ProofHeight: trustedHeight, } res := core.RecvPacket(cross(cur), recvPacket) println("res:", res) println("\n----------- assert render clients/07-tendermint-1/packet_receipts") println(core.Render("clients/" + clientID + "/packet_receipts")) println("----------- assert render clients/07-tendermint-1/packet_receipts/1") println(core.Render("clients/" + clientID + "/packet_receipts/1")) println("\n----------- assert render clients/07-tendermint-1/packet_acknowledgements") println(core.Render("clients/" + clientID + "/packet_acknowledgements")) println("----------- assert render clients/07-tendermint-1/packet_acknowledgements/1") println(core.Render("clients/" + clientID + "/packet_acknowledgements/1")) println("\n----------- app report") println(app.Report()) // assert NOOP response (res=1) if ack is resubmitted res = core.RecvPacket(cross(cur), recvPacket) 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_receipts // {"items":[{"sequence":"1","data":"Ag=="}],"page":1,"total":1} // ----------- assert render clients/07-tendermint-1/packet_receipts/1 // {"sequence":"1","data":"Ag=="} // // ----------- assert render clients/07-tendermint-1/packet_acknowledgements // {"items":[{"sequence":"1","data":"4vsw3796verKgtQmU00rOp1URN0qh/oW04t3uhoTztc="}],"page":1,"total":1} // ----------- assert render clients/07-tendermint-1/packet_acknowledgements/1 // {"sequence":"1","data":"4vsw3796verKgtQmU00rOp1URN0qh/oW04t3uhoTztc="} // // ----------- app report // OnSendPacket (0) // OnRecvPacket (1) // - sourceClient: 07-tendermint-42 // - destinationClient: 07-tendermint-1 // - sequence: 1 // - payload: // - sourcePort: appID // - destinationPort: appID // - version: v1 // - encoding: application/json // - value: {} // // OnTimeoutPacket (0) // OnAcknowledgementPacket (0) // // res: (1 gno.land/p/aib/ibc/types.ResponseResultType) // // ----------- app report // OnSendPacket (0) // OnRecvPacket (1) // - sourceClient: 07-tendermint-42 // - destinationClient: 07-tendermint-1 // - sequence: 1 // - payload: // - sourcePort: appID // - destinationPort: appID // - version: v1 // - encoding: application/json // - value: {} // // OnTimeoutPacket (0) // OnAcknowledgementPacket (0) // Events: // [ // { // "type": "create_client", // "attrs": [ // { // "key": "client_id", // "value": "07-tendermint-1" // }, // { // "key": "client_type", // "value": "07-tendermint" // }, // { // "key": "consensus_heights", // "value": "2/2" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "recv_packet", // "attrs": [ // { // "key": "packet_source_client", // "value": "07-tendermint-42" // }, // { // "key": "packet_dest_client", // "value": "07-tendermint-1" // }, // { // "key": "packet_sequence", // "value": "1" // }, // { // "key": "packet_timeout_timestamp", // "value": "1234571490" // }, // { // "key": "encoded_packet_hex", // "value": "0801121030372d74656e6465726d696e742d34321a0f30372d74656e6465726d696e742d3120e2a1d8cc042a280a056170704944120561707049441a02763122106170706c69636174696f6e2f6a736f6e2a027b7d" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "write_acknowledgement", // "attrs": [ // { // "key": "packet_source_client", // "value": "07-tendermint-42" // }, // { // "key": "packet_dest_client", // "value": "07-tendermint-1" // }, // { // "key": "packet_sequence", // "value": "1" // }, // { // "key": "packet_timeout_timestamp", // "value": "1234571490" // }, // { // "key": "encoded_packet_hex", // "value": "0801121030372d74656e6465726d696e742d34321a0f30372d74656e6465726d696e742d3120e2a1d8cc042a280a056170704944120561707049441a02763122106170706c69636174696f6e2f6a736f6e2a027b7d" // }, // { // "key": "encoded_acknowledgement_hex", // "value": "0a204774d4a575993f963b1c06573736617a457abef8589178db8d10c94b4ab511ab" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // } // ]