z7l_recv_packet_filetest.gno
4.25 Kb · 119 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "encoding/hex"
6 "time"
7
8 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
9 "gno.land/p/aib/ibc/types"
10 "gno.land/p/aib/ics23"
11 appstesting "gno.land/r/aib/ibc/apps/testing"
12 "gno.land/r/aib/ibc/core"
13)
14
15// RecvPacket fails app returns empty app acknowledgement
16func main(cur realm) {
17 var (
18 chainID = "chain-id-2"
19 trustedHeight = types.NewHeight(2, 2)
20 clientState = tmtesting.NewClientState(chainID, trustedHeight)
21 // apphash generated by the gen-proof command below
22 apphash, _ = hex.DecodeString("8da82bb625ee946f4b7aa03a82010cb115f9ce3879c7caad8d92e71eb821996e")
23 trustedValset = tmtesting.GenValset()
24 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
25 counterpartyID = "07-tendermint-42"
26 )
27 clientID := core.CreateClient(cross(cur), clientState, consensusState)
28 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
29
30 // Register app
31 var (
32 app = appstesting.NewApp(cross(cur))
33 appPortID = "appID"
34 )
35 app.SetOnRecvPacketReturn(types.RecvPacketResult{
36 Status: types.PacketStatus_Success,
37 Acknowledgement: []byte{},
38 })
39 core.RegisterApp(cross(cur), appPortID, app)
40
41 // Receive the packet
42 // Generate the proof
43 specs := ics23.IavlSpec()
44 // NOTE code generated by:
45 // 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"}]}'
46 proof := []ics23.CommitmentProof{
47
48 // iavl proof
49 ics23.CommitmentProof_Exist{
50 Exist: &ics23.ExistenceProof{
51 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"),
52 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"),
53 Leaf: &ics23.LeafOp{
54 Hash: specs.LeafSpec.Hash,
55 PrehashKey: specs.LeafSpec.PrehashKey,
56 PrehashValue: specs.LeafSpec.PrehashValue,
57 Length: specs.LeafSpec.Length,
58 Prefix: []byte("\x00\x02\x02"),
59 },
60 Path: []*ics23.InnerOp{
61 {
62 Hash: specs.InnerSpec.Hash,
63 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"),
64 Suffix: []byte(""),
65 },
66 {
67 Hash: specs.InnerSpec.Hash,
68 Prefix: []byte("\x04\x08\x02\x20"),
69 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"),
70 },
71 {
72 Hash: specs.InnerSpec.Hash,
73 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"),
74 Suffix: []byte(""),
75 },
76 },
77 },
78 },
79
80 // rootmulti proof
81 ics23.CommitmentProof_Exist{
82 Exist: &ics23.ExistenceProof{
83 Key: []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
84 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"),
85 Leaf: &ics23.LeafOp{
86 Hash: specs.LeafSpec.Hash,
87 PrehashKey: specs.LeafSpec.PrehashKey,
88 PrehashValue: specs.LeafSpec.PrehashValue,
89 Length: specs.LeafSpec.Length,
90 Prefix: []byte("\x00"),
91 },
92 Path: []*ics23.InnerOp{},
93 },
94 },
95 }
96
97 recvPacket := types.MsgRecvPacket{
98 Packet: types.Packet{
99 Sequence: 1,
100 SourceClient: counterpartyID,
101 DestinationClient: clientID,
102 TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
103 Payloads: []types.Payload{{
104 SourcePort: "appID",
105 DestinationPort: "appID",
106 Encoding: "application/json",
107 Value: []byte("{}"),
108 Version: "v1",
109 }},
110 },
111 ProofCommitment: proof,
112 ProofHeight: trustedHeight,
113 }
114
115 core.RecvPacket(cross(cur), recvPacket)
116}
117
118// Error:
119// app acknowledgement cannot be empty