// PKGPATH: gno.land/r/aib/main package main import ( "encoding/base64" "encoding/hex" "time" tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing" "gno.land/p/aib/ibc/types" "gno.land/p/aib/ics23" "gno.land/p/nt/testutils/v0" "gno.land/r/aib/ibc/apps/transfer" "gno.land/r/aib/ibc/core" ) // OnRecvPacket: fails because app version mismatch // NOTE: RecvPacket does not fail if OnRecvPacket fails. func main(cur realm) { var ( chainID = "chain-id-2" trustedHeight = types.NewHeight(2, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) // NOTE this apphash was provided by the gen-proof command below. apphash, _ = hex.DecodeString("0ff7263bc6a1177918ff797255391fcb1f848693d525b628743c2d18b7fec39f") 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) receiver := testutils.TestAddress("receiver") payload := transfer.NewFungibleTokenPacketData("uphoton", "100", "atone1user", receiver.String(), "") payloadBz := payload.ProtoMarshal() // NOTE this base64 value is used in payload.value in the gen-proof command below. println("Payload proto:", base64.StdEncoding.EncodeToString(payloadBz)) // 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":"transfer","destination_port":"transfer","encoding":"application/x-protobuf", "value":"Cgd1cGhvdG9uEgMxMDAaCmF0b25lMXVzZXIiKGcxd2Zqa3hldGZ3ZWpoeWg2bHRhMDQ3aDZsdGEwNDdoNmxsbTgyeWw=","version":"other-version"}]}' 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("\x7b\x09\xe4\x56\x67\xe5\x38\x36\xc2\x3a\xf6\x0f\x92\xa7\x97\x18\x7e\xc9\x89\x00\xd5\x41\xc1\xa8\x1c\xce\x86\xe0\xbc\xf0\xc2\x8f"), 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("\xb1\xd8\x52\xfd\xfc\xfa\xdd\xf6\x22\x1f\x15\xd3\x19\x0d\x17\x93\x5f\xea\xc5\x24\xf1\x45\x16\xcf\x5a\x16\xe6\x5a\x8f\x4c\x3b\xf3"), 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: transfer.PortID, DestinationPort: transfer.PortID, Encoding: transfer.EncodingProtobuf, Value: payloadBz, Version: "other-version", }}, }, 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("\n----------- assert render clients/07-tendermint-1/packet_acknowledgements") // The 2 acknowledgements below must match println("Expected commitment", base64.StdEncoding.EncodeToString( types.CommitAcknowledgement(types.Acknowledgement{ AppAcknowledgements: [][]byte{types.UniversalErrorAcknowledgement()}, }), )) println(core.Render("clients/" + clientID + "/packet_acknowledgements")) } // Output: // Payload proto: Cgd1cGhvdG9uEgMxMDAaCmF0b25lMXVzZXIiKGcxd2Zqa3hldGZ3ZWpoeWg2bHRhMDQ3aDZsdGEwNDdoNmxsbTgyeWw= // 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_acknowledgements // Expected commitment 4vsw3796verKgtQmU00rOp1URN0qh/oW04t3uhoTztc= // {"items":[{"sequence":"1","data":"4vsw3796verKgtQmU00rOp1URN0qh/oW04t3uhoTztc="}],"page":1,"total":1} // 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": "0801121030372d74656e6465726d696e742d34321a0f30372d74656e6465726d696e742d3120e2a1d8cc042a81010a087472616e7366657212087472616e736665721a0d6f746865722d76657273696f6e22166170706c69636174696f6e2f782d70726f746f6275662a440a077570686f746f6e12033130301a0a61746f6e6531757365722228673177666a6b7865746677656a687968366c746130343768366c746130343768366c6c6d3832796c" // } // ], // "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": "0801121030372d74656e6465726d696e742d34321a0f30372d74656e6465726d696e742d3120e2a1d8cc042a81010a087472616e7366657212087472616e736665721a0d6f746865722d76657273696f6e22166170706c69636174696f6e2f782d70726f746f6275662a440a077570686f746f6e12033130301a0a61746f6e6531757365722228673177666a6b7865746677656a687968366c746130343768366c746130343768366c6c6d3832796c" // }, // { // "key": "encoded_acknowledgement_hex", // "value": "0a204774d4a575993f963b1c06573736617a457abef8589178db8d10c94b4ab511ab" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // } // ]