z2aa_update_client_filetest.gno
5.89 Kb · 126 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 success with non-adjacent height
14func main(cur realm) {
15 // CreateClient and RegisterCounterparty
16 var (
17 chainID = "atomone-1"
18 height = uint64(2)
19 clientState = tmtesting.NewClientState(chainID, types.NewHeight(1, height))
20 apphash = tmtesting.Hash("apphash-2")
21 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
22 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
23 "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
24 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
25 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
26 "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
27 trustedValset = tendermint.NewValset(val1, val2)
28 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
29 )
30 clientID := core.CreateClient(cross(cur), clientState, consensusState)
31 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
32
33 // Update clientID
34 // NOTE code generated by:
35 // go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-3 -chainid=atomone-1 -header-time-shift=1 -height=5 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
36 {
37 var (
38 newHeight = height + 3 // non-adjacent heigth 5
39 apphash = tmtesting.Hash("apphash-3")
40 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
41 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(1))
42 valset = tendermint.NewValset(val1, val2)
43 nextValset = tendermint.NewValset(val1, val2)
44 trustedHeight = clientState.LatestHeight
45
46 signatures = []tendermint.CommitSig{
47 {
48 BlockIDFlag: tendermint.BlockIDFlagCommit,
49 ValidatorAddress: valset.Validators[0].Address,
50 Timestamp: commitTimestamp,
51 Signature: []byte("\x94\x28\x84\xa4\xd1\xe9\xfe\x7d\xa9\x0f\x4d\x35\xc6\xa7\x0b\x1b\x7e\x83\xe0\xc7\x4b\xc3\x57\xa4\xf2\x35\xf7\x61\x52\xe3\xe6\xde\x58\xf6\x61\x0d\xf3\x00\x37\xc2\x0c\x13\x20\x46\x5e\x43\x26\x1b\xb4\x87\x20\x06\x80\x81\x15\x84\xd4\x98\xeb\xcb\xf2\x42\xbb\x0b"),
52 },
53 {
54 BlockIDFlag: tendermint.BlockIDFlagCommit,
55 ValidatorAddress: valset.Validators[1].Address,
56 Timestamp: commitTimestamp,
57 Signature: []byte("\x49\x3f\x4e\x6e\x7b\x72\x0a\xdb\x90\x6d\xdb\xfd\x24\x67\x9b\x00\xf5\x7d\xc3\x7b\x7f\x71\xf4\xe0\x0d\xce\xed\xfd\x27\xdd\x58\x7b\x04\x25\xa9\x7b\xa7\x60\x40\x7c\x11\x55\xe7\xda\xed\x88\xf3\x78\x54\xeb\x7f\x91\xfb\xd4\xe9\x2a\xd8\x8e\xb6\x11\x0a\xdf\xc9\x0d"),
58 },
59 }
60
61 msgHeader = tmtesting.NewMsgHeader(
62 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
63 nextValset, trustedValset, signatures,
64 )
65 )
66 core.UpdateClient(cross(cur), clientID, msgHeader)
67 }
68
69 println("----------- assert render clients")
70 println(core.Render("clients"))
71 println("\n----------- assert render clients/07-tendermint-1/consensus_states")
72 println(core.Render("clients/" + clientID + "/consensus_states"))
73 println("\n----------- assert render clients/07-tendermint-1/consensus_states/1/5")
74 println(core.Render("clients/" + clientID + "/consensus_states/1/5"))
75}
76
77// Output:
78// ----------- assert render clients
79// {"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":5},"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":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}}],"page":1,"total":1}
80//
81// ----------- assert render clients/07-tendermint-1/consensus_states
82// {"items":[{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="},{"height":{"revision_number":1,"revision_height":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}],"page":1,"total":1}
83//
84// ----------- assert render clients/07-tendermint-1/consensus_states/1/5
85// {"height":{"revision_number":1,"revision_height":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}
86
87// Events:
88// [
89// {
90// "type": "create_client",
91// "attrs": [
92// {
93// "key": "client_id",
94// "value": "07-tendermint-1"
95// },
96// {
97// "key": "client_type",
98// "value": "07-tendermint"
99// },
100// {
101// "key": "consensus_heights",
102// "value": "1/2"
103// }
104// ],
105// "pkg_path": "gno.land/r/aib/ibc/core"
106// },
107// {
108// "type": "update_client",
109// "attrs": [
110// {
111// "key": "client_id",
112// "value": "07-tendermint-1"
113// },
114// {
115// "key": "client_type",
116// "value": "07-tendermint"
117// },
118// {
119// "key": "consensus_heights",
120// "value": "1/5"
121// }
122// ],
123// "pkg_path": "gno.land/r/aib/ibc/core"
124// }
125// ]
126