z10c_upgrade_client_filetest.gno
7.60 Kb · 174 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4
5import (
6 "encoding/hex"
7 "time"
8
9 "gno.land/p/aib/ibc/lightclient/tendermint"
10 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
11 "gno.land/p/aib/ibc/types"
12 "gno.land/p/aib/ics23"
13 "gno.land/r/aib/ibc/core"
14)
15
16// UpgradeClient success: verify upgraded client + consensus state proofs
17// generated by `go run -C ./cmd/gen-proof . upgrade` and apply the upgrade
18// to the existing client.
19func main(cur realm) {
20 core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
21 core.AddRelayer(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
22
23 // NOTE code generated by:
24 // go run -C ./cmd/gen-proof . upgrade
25 //
26 // Plan height: 100
27 // Upgraded chain id: chain-after-upgrade-2
28 // Upgraded latest height: 2-1
29 // Upgraded timestamp (unix): 1700000000
30 // Multistore root (apphash): f798f6bd56268e30a1f6ceb223e3330ee47d992f5a888de5b78dfd934e344a27
31 apphash, _ := hex.DecodeString("f798f6bd56268e30a1f6ceb223e3330ee47d992f5a888de5b78dfd934e344a27")
32 specs := ics23.IavlSpec()
33
34 // Current client at the upgrade plan height; consensus root is the
35 // multistore apphash gen-proof committed.
36 currentChainID := "current-chain-1"
37 currentHeight := types.NewHeight(1, 100)
38 clientState := tmtesting.NewClientState(currentChainID, currentHeight)
39 clientState.UpgradePath = []string{"upgrade", "upgradedIBCState"}
40 consensusState := tendermint.ConsensusState{
41 Timestamp: time.Now().UTC(),
42 Root: tendermint.NewMerkleRoot(apphash),
43 NextValidatorsHash: tmtesting.GenValset().Hash(),
44 }
45 clientID := core.CreateClient(cross(cur), clientState, consensusState)
46
47 // The upgraded states the relayer submits must reconstruct the same
48 // bytes the counterparty committed (Any-wrapped, ZeroCustomFields for
49 // the client). Use values matching the gen-proof scenario.
50 nextValsHash := make([]byte, 32)
51 for i := range nextValsHash {
52 nextValsHash[i] = byte(i + 1)
53 }
54 upgradedClient := tendermint.ClientState{
55 ChainID: "chain-after-upgrade-2",
56 TrustLevel: tendermint.NewFraction(1, 3),
57 TrustingPeriod: 2 * 7 * 24 * time.Hour,
58 UnbondingPeriod: 3 * 7 * 24 * time.Hour,
59 MaxClockDrift: 10 * time.Second,
60 LatestHeight: types.NewHeight(2, 1),
61 ProofSpecs: ics23.GetSDKProofSpecs(),
62 UpgradePath: []string{"upgrade", "upgradedIBCState"},
63 }
64 upgradedConsState := tendermint.ConsensusState{
65 Timestamp: time.Unix(1700000000, 0).UTC(),
66 Root: tendermint.NewMerkleRoot([]byte(tendermint.SentinelRoot)),
67 NextValidatorsHash: nextValsHash,
68 }
69
70 clientProof := []ics23.CommitmentProof{
71 // iavl proof
72 ics23.CommitmentProof_Exist{
73 Exist: &ics23.ExistenceProof{
74 Key: []byte("\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65\x2f\x31\x30\x30\x2f\x75\x70\x67\x72\x61\x64\x65\x64\x43\x6c\x69\x65\x6e\x74"),
75 Value: []byte("\x0a\x2b\x2f\x69\x62\x63\x2e\x6c\x69\x67\x68\x74\x63\x6c\x69\x65\x6e\x74\x73\x2e\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2e\x76\x31\x2e\x43\x6c\x69\x65\x6e\x74\x53\x74\x61\x74\x65\x12\x7c\x0a\x15\x63\x68\x61\x69\x6e\x2d\x61\x66\x74\x65\x72\x2d\x75\x70\x67\x72\x61\x64\x65\x2d\x32\x12\x00\x1a\x00\x22\x04\x08\x80\xdf\x6e\x2a\x00\x32\x00\x3a\x04\x08\x02\x10\x01\x42\x19\x0a\x09\x08\x01\x18\x01\x20\x01\x2a\x01\x00\x12\x0c\x0a\x02\x00\x01\x10\x21\x18\x04\x20\x0c\x30\x01\x42\x19\x0a\x09\x08\x01\x18\x01\x20\x01\x2a\x01\x00\x12\x0c\x0a\x02\x00\x01\x10\x20\x18\x01\x20\x01\x30\x01\x4a\x07\x75\x70\x67\x72\x61\x64\x65\x4a\x10\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65"),
76 Leaf: &ics23.LeafOp{
77 Hash: specs.LeafSpec.Hash,
78 PrehashKey: specs.LeafSpec.PrehashKey,
79 PrehashValue: specs.LeafSpec.PrehashValue,
80 Length: specs.LeafSpec.Length,
81 Prefix: []byte("\x00\x02\x02"),
82 },
83 Path: []*ics23.InnerOp{
84 {
85 Hash: specs.InnerSpec.Hash,
86 Prefix: []byte("\x02\x04\x02\x20"),
87 Suffix: []byte("\x20\x9c\x29\x97\x40\x53\xa4\x0c\x45\xb4\x4b\xce\x96\x00\xfa\x17\xfa\xeb\xa1\xfa\xa0\xc7\x2e\xa5\x75\x63\x80\x70\x02\x79\xef\x8b\xee"),
88 },
89 {
90 Hash: specs.InnerSpec.Hash,
91 Prefix: []byte("\x04\x06\x02\x20"),
92 Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"),
93 },
94 {
95 Hash: specs.InnerSpec.Hash,
96 Prefix: []byte("\x06\x0e\x02\x20\x7b\x0d\x2c\x83\x0d\xb3\xa2\x71\xb1\x1a\x3a\xda\xc5\x21\x99\x66\x8d\x86\x3b\x38\xb1\xcb\x4f\xd2\x4f\xe7\x4d\x3f\x30\x20\x41\x5d\x20"),
97 Suffix: []byte(""),
98 },
99 },
100 },
101 },
102 // rootmulti proof
103 ics23.CommitmentProof_Exist{
104 Exist: &ics23.ExistenceProof{
105 Key: []byte("\x75\x70\x67\x72\x61\x64\x65"),
106 Value: []byte("\xe5\x58\x62\xc7\x50\x66\x4f\xa8\xcc\xe2\x3b\x36\x65\xbe\x8d\x52\xb9\x51\x08\xfc\x48\x12\x33\xf0\x24\x68\x02\xfd\x18\x93\x5e\xfc"),
107 Leaf: &ics23.LeafOp{
108 Hash: specs.LeafSpec.Hash,
109 PrehashKey: specs.LeafSpec.PrehashKey,
110 PrehashValue: specs.LeafSpec.PrehashValue,
111 Length: specs.LeafSpec.Length,
112 Prefix: []byte("\x00"),
113 },
114 Path: []*ics23.InnerOp{},
115 },
116 },
117 }
118
119 consStateProof := []ics23.CommitmentProof{
120 // iavl proof
121 ics23.CommitmentProof_Exist{
122 Exist: &ics23.ExistenceProof{
123 Key: []byte("\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65\x2f\x31\x30\x30\x2f\x75\x70\x67\x72\x61\x64\x65\x64\x43\x6f\x6e\x73\x53\x74\x61\x74\x65"),
124 Value: []byte("\x0a\x2e\x2f\x69\x62\x63\x2e\x6c\x69\x67\x68\x74\x63\x6c\x69\x65\x6e\x74\x73\x2e\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2e\x76\x31\x2e\x43\x6f\x6e\x73\x65\x6e\x73\x75\x73\x53\x74\x61\x74\x65\x12\x3b\x0a\x06\x08\x80\xe2\xcf\xaa\x06\x12\x0f\x0a\x0d\x73\x65\x6e\x74\x69\x6e\x65\x6c\x5f\x72\x6f\x6f\x74\x1a\x20\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"),
125 Leaf: &ics23.LeafOp{
126 Hash: specs.LeafSpec.Hash,
127 PrehashKey: specs.LeafSpec.PrehashKey,
128 PrehashValue: specs.LeafSpec.PrehashValue,
129 Length: specs.LeafSpec.Length,
130 Prefix: []byte("\x00\x02\x02"),
131 },
132 Path: []*ics23.InnerOp{
133 {
134 Hash: specs.InnerSpec.Hash,
135 Prefix: []byte("\x02\x04\x02\x20\xb8\xd1\x78\xec\x21\x73\xd5\x34\x83\xa7\x2b\xd0\x34\xcc\xbd\xbc\xaf\x7b\x63\x7c\xba\x52\xd8\xf1\x5c\x9f\xd6\x24\xb9\xe9\xc3\x9a\x20"),
136 Suffix: []byte(""),
137 },
138 {
139 Hash: specs.InnerSpec.Hash,
140 Prefix: []byte("\x04\x06\x02\x20"),
141 Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"),
142 },
143 {
144 Hash: specs.InnerSpec.Hash,
145 Prefix: []byte("\x06\x0e\x02\x20\x7b\x0d\x2c\x83\x0d\xb3\xa2\x71\xb1\x1a\x3a\xda\xc5\x21\x99\x66\x8d\x86\x3b\x38\xb1\xcb\x4f\xd2\x4f\xe7\x4d\x3f\x30\x20\x41\x5d\x20"),
146 Suffix: []byte(""),
147 },
148 },
149 },
150 },
151 // rootmulti proof
152 ics23.CommitmentProof_Exist{
153 Exist: &ics23.ExistenceProof{
154 Key: []byte("\x75\x70\x67\x72\x61\x64\x65"),
155 Value: []byte("\xe5\x58\x62\xc7\x50\x66\x4f\xa8\xcc\xe2\x3b\x36\x65\xbe\x8d\x52\xb9\x51\x08\xfc\x48\x12\x33\xf0\x24\x68\x02\xfd\x18\x93\x5e\xfc"),
156 Leaf: &ics23.LeafOp{
157 Hash: specs.LeafSpec.Hash,
158 PrehashKey: specs.LeafSpec.PrehashKey,
159 PrehashValue: specs.LeafSpec.PrehashValue,
160 Length: specs.LeafSpec.Length,
161 Prefix: []byte("\x00"),
162 },
163 Path: []*ics23.InnerOp{},
164 },
165 },
166 }
167
168 core.UpgradeClient(cross(cur), clientID, upgradedClient, upgradedConsState, clientProof, consStateProof)
169
170 println("upgrade succeeded")
171}
172
173// Output:
174// upgrade succeeded