// PKGPATH: gno.land/r/aib/main package main import ( "chain" "encoding/hex" "testing" "time" 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" ) // OnAcknowledgementPacket: success with native coin refund func main(cur realm) { var ( chainID = "chain-id-2" trustedHeight = types.NewHeight(2, 2) clientState = tmtesting.NewClientState(chainID, trustedHeight) apphash, _ = hex.DecodeString("5467ca2d19a7b74dbcd20e33bda91932f912d76595872ec856945af96e743b82") 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) // 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(time.Hour).Unix()), "") println("----------- assert render total_escrow/ugnot after Transfer") println(transfer.Render("total_escrow/ugnot")) // Acknowledge the packet specs := ics23.IavlSpec() // Generate the proof of acknowledgement written during the RecvPacket of the // counterparty client. // NOTE proof generated by: // ./cmd/gen-proof prefix2 07-tendermint-42 acknowledgement $(echo -n UNIVERSAL_ERROR_ACKNOWLEDGEMENT | sha256sum | cut -d' ' -f1) proofAcked := []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\x03\x00\x00\x00\x00\x00\x00\x00\x01"), Value: []byte("\xe2\xfb\x30\xdf\xbf\x7a\xbd\xea\xca\x82\xd4\x26\x53\x4d\x2b\x3a\x9d\x54\x44\xdd\x2a\x87\xfa\x16\xd3\x8b\x77\xba\x1a\x13\xce\xd7"), 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("\x91\x57\xa5\x00\xd6\xc8\xde\x17\x14\xba\xdf\x44\x6d\x17\xb6\xb8\xd3\xa5\x8b\x30\xf8\x54\x83\x18\x66\xd4\x33\x53\x6f\xd2\xea\xb9"), 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{}, }, }, } ackPacket := types.MsgAcknowledgement{ Packet: types.Packet{ Sequence: sequence, SourceClient: clientID, DestinationClient: counterpartyID, TimeoutTimestamp: sendPacket.TimeoutTimestamp, Payloads: sendPacket.Payloads, }, Acknowledgement: types.Acknowledgement{ // This UNIVERSAL_ERROR_ACKNOWLEDGEMENT error should trigger a refund AppAcknowledgements: [][]byte{types.UniversalErrorAcknowledgement()}, }, ProofAcked: proofAcked, ProofHeight: trustedHeight, } // 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.Acknowledgement(cross(cur), ackPacket) println("\nack 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} // // ack 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": "2/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": "1234571490" // }, // { // "key": "encoded_packet_hex", // "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a790a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a420a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e653175736572" // } // ], // "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": "" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // }, // { // "type": "acknowledge_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": "1234571490" // }, // { // "key": "encoded_packet_hex", // "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a790a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a420a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e653175736572" // } // ], // "pkg_path": "gno.land/r/aib/ibc/core" // }, // { // "type": "fungible_token_packet", // "attrs": [ // { // "key": "sender", // "value": "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" // }, // { // "key": "receiver", // "value": "atone1user" // }, // { // "key": "denom", // "value": "ugnot" // }, // { // "key": "amount", // "value": "100" // }, // { // "key": "memo", // "value": "" // }, // { // "key": "acknowledgement", // "value": "Gtԥu\ufffd?\ufffd;\u001c\u0006W76azEz\ufffd\ufffdX\ufffdxۍ\u0010\ufffdKJ\ufffd\u0011\ufffd" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // }, // { // "type": "fungible_token_packet", // "attrs": [ // { // "key": "error", // "value": "receive packet failed" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // } // ]