z7k_recv_packet_filetest.gno
4.00 Kb · 108 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 "gno.land/r/aib/ibc/core"
12)
13
14// RecvPacket fails no registered app
15func main(cur realm) {
16 var (
17 chainID = "chain-id-2"
18 trustedHeight = types.NewHeight(2, 2)
19 clientState = tmtesting.NewClientState(chainID, trustedHeight)
20 // apphash generated by the gen-proof command below
21 apphash, _ = hex.DecodeString("89d6cd2d65e74eeea7516122e9ef9e46b1fff62efc51db839d08ce034cabbd34")
22 trustedValset = tmtesting.GenValset()
23 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
24 counterpartyID = "07-tendermint-42"
25 )
26 clientID := core.CreateClient(cross(cur), clientState, consensusState)
27 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
28
29 // Receive the packet
30 // Generate the proof of existence of the packet commitment for the
31 // counterparty chain.
32 specs := ics23.IavlSpec()
33 // NOTE code generated by:
34 // 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":"srcAppID","destination_port":"dstAppID","encoding":"application/json","value":"e30=","version":"v1"}]}'
35 proof := []ics23.CommitmentProof{
36
37 // iavl proof
38 ics23.CommitmentProof_Exist{
39 Exist: &ics23.ExistenceProof{
40 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"),
41 Value: []byte("\xae\xf0\xe6\xb1\xba\xbd\xbd\x9a\x75\x74\x25\xbf\x9a\x55\x4a\x80\xd8\x62\x02\x0b\xd8\x47\x2f\x3e\xfe\x38\x95\x31\x65\x10\x1d\x66"),
42 Leaf: &ics23.LeafOp{
43 Hash: specs.LeafSpec.Hash,
44 PrehashKey: specs.LeafSpec.PrehashKey,
45 PrehashValue: specs.LeafSpec.PrehashValue,
46 Length: specs.LeafSpec.Length,
47 Prefix: []byte("\x00\x02\x02"),
48 },
49 Path: []*ics23.InnerOp{
50 {
51 Hash: specs.InnerSpec.Hash,
52 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"),
53 Suffix: []byte(""),
54 },
55 {
56 Hash: specs.InnerSpec.Hash,
57 Prefix: []byte("\x04\x08\x02\x20"),
58 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"),
59 },
60 {
61 Hash: specs.InnerSpec.Hash,
62 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"),
63 Suffix: []byte(""),
64 },
65 },
66 },
67 },
68
69 // rootmulti proof
70 ics23.CommitmentProof_Exist{
71 Exist: &ics23.ExistenceProof{
72 Key: []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
73 Value: []byte("\x56\xfd\x2a\xee\x01\x92\x98\xa1\xc5\xe9\x06\x5b\x15\xdd\xfb\x69\x87\x06\x15\x9c\x9d\xca\x6e\x3d\xe6\xd3\x92\xc6\xa2\x31\x97\xce"),
74 Leaf: &ics23.LeafOp{
75 Hash: specs.LeafSpec.Hash,
76 PrehashKey: specs.LeafSpec.PrehashKey,
77 PrehashValue: specs.LeafSpec.PrehashValue,
78 Length: specs.LeafSpec.Length,
79 Prefix: []byte("\x00"),
80 },
81 Path: []*ics23.InnerOp{},
82 },
83 },
84 }
85
86 recvPacket := types.MsgRecvPacket{
87 Packet: types.Packet{
88 Sequence: 1,
89 SourceClient: counterpartyID,
90 DestinationClient: clientID,
91 TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
92 Payloads: []types.Payload{{
93 SourcePort: "srcAppID",
94 DestinationPort: "dstAppID",
95 Encoding: "application/json",
96 Value: []byte("{}"),
97 Version: "v1",
98 }},
99 },
100 ProofCommitment: proof,
101 ProofHeight: trustedHeight,
102 }
103
104 core.RecvPacket(cross(cur), recvPacket)
105}
106
107// Error:
108// no registered app for port dstAppID