// 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 coins 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("6f64efa36d97452b4555efc37596b7fc36ca80dff8a1784ca8fbf45a102e8e27") 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 testing.SetRealm(testing.NewUserRealm("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")) testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 100))) 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()), "memo") 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 code generated by: // go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'acknowledgement' '{"result":"AQ=="}' 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\x03\x00\x00\x00\x00\x00\x00\x00\x01"), Value: []byte("\x84\x60\xe2\x1f\x73\xb5\x3d\x77\x9e\x4b\x32\x91\xcd\x35\x33\x8e\x92\xfa\xe9\x99\x87\x35\xf1\xa0\xb7\x15\x0c\x07\x4c\x07\x31\xa6"), 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("\x0a\xbc\x9d\x9a\xd7\x2b\x69\x0b\x1c\xbc\xca\x2d\x8a\x35\xb0\xe5\x04\x73\x77\x6a\x1e\x28\x9b\x94\xc7\x3e\x1a\x67\x99\x56\xad\xdd"), 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{ AppAcknowledgements: [][]byte{[]byte(`{"result":"AQ=="}`)}, }, ProofAcked: proof, ProofHeight: trustedHeight, } 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":100} // 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": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a7f0a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a480a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e6531757365722a046d656d6f" // } // ], // "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": "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": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220e2a1d8cc042a7f0a087472616e7366657212087472616e736665721a0769637332302d3122166170706c69636174696f6e2f782d70726f746f6275662a480a0575676e6f7412033130301a28673177796d75343764726872306b7571323039386d3739326c797467746a326e797837377972736d220a61746f6e6531757365722a046d656d6f" // } // ], // "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": "memo" // }, // { // "key": "acknowledgement", // "value": "{\"result\":\"AQ==\"}" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // }, // { // "type": "fungible_token_packet", // "attrs": [ // { // "key": "success", // "value": "\u0001" // } // ], // "pkg_path": "gno.land/r/aib/ibc/apps/transfer" // } // ]