z2s_update_client_filetest.gno
6.16 Kb · 120 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "time"
6
7 "gno.land/p/aib/ibc/lightclient/tendermint"
8 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
9 "gno.land/p/aib/ibc/types"
10 "gno.land/r/aib/ibc/core"
11)
12
13// UpdateClient fails new consensus state timestamp is after the next
14// consensus state.
15func main(cur realm) {
16 // CreateClient and RegisterCounterparty
17 var (
18 chainID = "atomone-1"
19 height = uint64(2)
20 clientState = tmtesting.NewClientState(chainID, types.NewHeight(1, height))
21 apphash = tmtesting.Hash("apphash-2")
22 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
23 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
24 "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
25 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
26 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
27 "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
28 trustedValset = tendermint.NewValset(val1, val2)
29 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
30 )
31 clientID := core.CreateClient(cross(cur), clientState, consensusState)
32 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
33
34 // Add height 5 at duration+5
35 // NOTE code generated by:
36 // go run -C ./cmd/gen-block-signatures . -chainid=atomone-1 -header-time-shift=5 -height=5 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
37 {
38 var (
39 apphash = tmtesting.Hash("apphash-5")
40 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
41 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
42 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
43 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
44 valset = tendermint.NewValset(val1, val2)
45 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
46 newHeight = uint64(5)
47 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(5))
48 nextValset = tendermint.NewValset(val1, val2)
49 trustedHeight = clientState.LatestHeight
50
51 signatures = []tendermint.CommitSig{
52 {
53 BlockIDFlag: tendermint.BlockIDFlagCommit,
54 ValidatorAddress: valset.Validators[0].Address,
55 Timestamp: commitTimestamp,
56 Signature: []byte("\x84\x70\x8b\xba\x3d\x32\xd2\xb9\xed\xcd\x3c\x36\x1e\xc0\xf4\xc1\x93\x20\x2e\xc7\xfe\x6a\x9f\xdf\xe7\x21\x47\x9e\xe6\x42\xb8\x23\x56\xd5\x51\xa0\x67\x83\x74\x13\xb3\xb1\xcd\x3f\x71\xd5\x51\x76\xce\xbe\x0f\x24\x02\x04\x98\xc8\xc1\xce\x4c\xfb\x04\x02\xbf\x04"),
57 },
58 {
59 BlockIDFlag: tendermint.BlockIDFlagCommit,
60 ValidatorAddress: valset.Validators[1].Address,
61 Timestamp: commitTimestamp,
62 Signature: []byte("\x2f\xdb\x5e\xdd\xec\xd2\x1a\x8f\xd6\x7f\x56\xcb\x87\x00\x1e\x0b\x1b\xbb\xa6\xcc\xb7\x2e\x87\xca\x59\x4f\x00\xa2\xf1\xd1\xef\xe8\xc5\x29\x43\xba\x0e\xeb\xed\x35\x23\x12\xdb\x1e\x21\x6f\xcb\xd3\xe7\x00\xce\xcd\x0e\x9c\x45\xad\xb6\xae\xe2\x96\x07\xe8\x4b\x0b"),
63 },
64 }
65
66 msgHeader = tmtesting.NewMsgHeader(
67 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
68 nextValset, trustedValset, signatures,
69 )
70 )
71 core.UpdateClient(cross(cur), clientID, msgHeader)
72 }
73
74 // Add height 4 at duration+6 (so older than height 5)
75 // NOTE code generated by:
76 // go run -C ./cmd/gen-block-signatures . -chainid=atomone-1 -header-time-shift=6 -height=4 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
77 {
78 var (
79 apphash = tmtesting.Hash("apphash-4")
80 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
81 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
82 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
83 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
84 valset = tendermint.NewValset(val1, val2)
85 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
86 newHeight = uint64(4)
87 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(6))
88 nextValset = tendermint.NewValset(val1, val2)
89 trustedHeight = clientState.LatestHeight
90
91 signatures = []tendermint.CommitSig{
92 {
93 BlockIDFlag: tendermint.BlockIDFlagCommit,
94 ValidatorAddress: valset.Validators[0].Address,
95 Timestamp: commitTimestamp,
96 Signature: []byte("\x7e\x5f\x1b\x68\x12\x02\x85\x0f\xee\x1d\x1c\x89\x68\xce\x2b\xb8\x88\xd7\x66\xbb\x95\xea\x18\x8f\x63\x4f\x81\x7b\x1c\xde\x64\xf2\x5f\x58\x6d\xdf\x0f\xee\xfd\x36\xff\xbf\x53\xa6\x5f\xb1\x43\xc8\x6e\xab\x1e\xf4\x10\xde\xeb\x11\xa6\xd9\xb4\x8e\x17\xaf\x58\x07"),
97 },
98 {
99 BlockIDFlag: tendermint.BlockIDFlagCommit,
100 ValidatorAddress: valset.Validators[1].Address,
101 Timestamp: commitTimestamp,
102 Signature: []byte("\x2c\x7c\x13\xd8\x67\x5e\xdb\x77\xc9\xd1\x1a\x5b\x4f\x61\x09\xb6\xd5\x9a\x99\x13\x7b\xbc\xd3\x6a\x0f\x1c\x99\x7c\xaf\xb6\xb2\x5f\x78\xe0\x5b\x78\xf5\xd9\xe9\xa6\x42\xd7\xd7\x97\xb9\x8f\xb8\xaf\x23\x35\x3f\x65\x9a\xd7\x3a\x3f\x74\x7a\x08\x23\x2a\x3f\x41\x0d"),
103 },
104 }
105
106 msgHeader = tmtesting.NewMsgHeader(
107 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
108 nextValset, trustedValset, signatures,
109 )
110 )
111 core.UpdateClient(cross(cur), clientID, msgHeader)
112 }
113
114 println("----------- assert render client status")
115 println(core.Render("clients/" + clientID + "/status")) // client should be frozen
116}
117
118// Output:
119// ----------- assert render client status
120// {"status":"Frozen"}