z8aa_update_client_misbehaviour_filetest.gno
8.06 Kb · 168 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 with unfound misbehaviour:
14// header1.height > header2.height && header1.time > header2.time
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=", 1)
25 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
26 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
27 "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
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 // Build valid misbehavior
35 var header1, header2 *tendermint.MsgHeader
36 // NOTE code generated by:
37 // go run -C ./cmd/gen-block-signatures . -chainid=atomone-1 -header-time-shift=1 -height=4 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
38 {
39 var (
40 apphash = tmtesting.Hash("apphash-4")
41 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
42 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
43 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
44 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
45 valset = tendermint.NewValset(val1, val2)
46 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
47 newHeight = uint64(4)
48 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(1))
49 nextValset = tendermint.NewValset(val1, val2)
50 trustedHeight = clientState.LatestHeight
51
52 signatures = []tendermint.CommitSig{
53 {
54 BlockIDFlag: tendermint.BlockIDFlagCommit,
55 ValidatorAddress: valset.Validators[0].Address,
56 Timestamp: commitTimestamp,
57 Signature: []byte("\xd8\xb6\x83\x5e\x89\xbb\xd9\xf1\x68\x1e\x3a\x6b\x0b\xd8\xad\x24\x05\x4d\x3b\x21\xfe\xff\x97\x77\x06\x82\xa7\x97\x9d\x51\x4d\x05\x5f\x08\x34\x1c\xcc\x49\xeb\x37\xe2\x8a\x15\xca\x54\x4d\x67\x4a\xde\xf4\x84\x5d\x74\xfd\x0e\xe4\x01\xe7\x9b\x8d\x4f\x41\x82\x0d"),
58 },
59 {
60 BlockIDFlag: tendermint.BlockIDFlagCommit,
61 ValidatorAddress: valset.Validators[1].Address,
62 Timestamp: commitTimestamp,
63 Signature: []byte("\xd2\x41\x4f\xb2\x07\x44\xb4\xa1\x76\x95\xc9\x8a\x89\xa8\x4b\x3e\xea\x97\x33\xd9\x98\x0d\xad\xdf\xc2\xce\x86\x6d\x84\x64\x60\x91\x56\xa5\xa8\xb5\x39\xbe\x1b\x4e\x1c\xc9\xf2\x3b\x89\x4a\xab\xe7\x90\x49\x5f\x29\xf6\x11\xec\xa0\xd7\x35\x2c\x9b\xe4\x1c\xd2\x02"),
64 },
65 }
66 )
67
68 header1 = tmtesting.NewMsgHeader(
69 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
70 nextValset, trustedValset, signatures,
71 )
72 }
73 // NOTE code generated by:
74 // go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-3 -chainid=atomone-1 -header-time-shift=0 -height=3 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
75 {
76 var (
77 apphash = tmtesting.Hash("apphash-3")
78 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
79 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
80 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
81 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
82 valset = tendermint.NewValset(val1, val2)
83 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
84 newHeight = uint64(3)
85 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(0))
86 nextValset = tendermint.NewValset(val1, val2)
87 trustedHeight = clientState.LatestHeight
88
89 signatures = []tendermint.CommitSig{
90 {
91 BlockIDFlag: tendermint.BlockIDFlagCommit,
92 ValidatorAddress: valset.Validators[0].Address,
93 Timestamp: commitTimestamp,
94 Signature: []byte("\x51\xa4\x8f\x78\x42\x4e\x6e\x0d\xc3\x2b\xe6\xcb\x09\x5c\xe5\x7d\x35\x84\xcf\xb1\x0f\x53\x72\x0c\x41\xde\xd3\x6d\xbc\x81\x28\x64\x41\xf7\xe9\x1e\xa9\x93\xd0\xa4\x84\x16\xca\xa8\xa3\x8e\x56\x45\xec\xae\x1d\x24\xb4\xa8\xf4\x29\x85\x04\x06\xe4\x18\x6b\x7d\x08"),
95 },
96 {
97 BlockIDFlag: tendermint.BlockIDFlagCommit,
98 ValidatorAddress: valset.Validators[1].Address,
99 Timestamp: commitTimestamp,
100 Signature: []byte("\xd9\xd6\x82\x83\x78\x75\xfa\x2e\xd7\x1b\xa5\x3d\xfe\xb3\x80\xb6\xc7\x59\x20\x45\x10\xdf\x0c\x19\xd1\xcc\xfc\x37\xd5\x59\x79\x95\x93\x60\x08\xfb\x5f\xa0\x87\x95\x51\x1e\x29\xed\x94\xd1\x31\x5e\xda\x90\x86\x11\xbe\xb2\x88\x68\xe1\xba\xa7\x31\xc7\xa2\xda\x07"),
101 },
102 }
103 )
104
105 header2 = tmtesting.NewMsgHeader(
106 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
107 nextValset, trustedValset, signatures,
108 )
109 }
110 msg := &tendermint.Misbehaviour{
111 Header1: header1,
112 Header2: header2,
113 }
114
115 core.UpdateClient(cross(cur), clientID, msg)
116
117 println("----------- assert render clients")
118 println(core.Render("clients"))
119 println("----------- assert render clients/07-tendermint-1/consensus_states")
120 println(core.Render("clients/" + clientID + "/consensus_states"))
121}
122
123// Output:
124// ----------- assert render clients
125// {"items":[{"id":"07-tendermint-1","type":"07-tendermint","creator":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","status":"Active","counterparty_client_id":"07-tendermint-2","counterparty_merke_prefix":["iavlStoreKey","prefix2"],"client_state":{"chain_id":"atomone-1","latest_height":{"revision_number":1,"revision_height":2},"frozen_height":{"revision_number":0,"revision_height":0},"trust_level":{"numerator":1,"denominator":3},"trusting_period":3600,"unbonding_period":10800,"max_clock_drift":3600,"upgrade_path":[]},"last_consensus_state":{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}}],"page":1,"total":1}
126// ----------- assert render clients/07-tendermint-1/consensus_states
127// {"items":[{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}],"page":1,"total":1}
128
129// Events:
130// [
131// {
132// "type": "create_client",
133// "attrs": [
134// {
135// "key": "client_id",
136// "value": "07-tendermint-1"
137// },
138// {
139// "key": "client_type",
140// "value": "07-tendermint"
141// },
142// {
143// "key": "consensus_heights",
144// "value": "1/2"
145// }
146// ],
147// "pkg_path": "gno.land/r/aib/ibc/core"
148// },
149// {
150// "type": "update_client",
151// "attrs": [
152// {
153// "key": "client_id",
154// "value": "07-tendermint-1"
155// },
156// {
157// "key": "client_type",
158// "value": "07-tendermint"
159// },
160// {
161// "key": "consensus_heights",
162// "value": ""
163// }
164// ],
165// "pkg_path": "gno.land/r/aib/ibc/core"
166// }
167// ]
168