z2q_update_client_filetest.gno
3.44 Kb · 73 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 blockID.Hash and Header.Hash mismatch
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=", 2)
24 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
25 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
26 "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 3)
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=3 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
36 {
37 var (
38 apphash = tmtesting.Hash("apphash-3")
39 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
40 newHeight = height + 1 // adjacent height
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("\x5c\xd2\x8b\xe3\x4b\x60\x3e\xaa\x75\x3c\xce\x24\xfe\x15\x75\x55\x84\xd4\xa3\xce\xbe\x0f\x94\xe9\xf7\x27\xb3\x7a\xdd\x02\x2d\xa0\x0b\xa7\x83\x7f\x50\xc3\xde\x3d\x95\x59\xb3\xad\xed\xd0\xdd\x23\x1d\x39\x9a\x8e\x1f\xc3\xcf\xdb\x1d\xa9\x93\xf5\x9a\xc0\x2b\x05"),
52 },
53 {
54 BlockIDFlag: tendermint.BlockIDFlagCommit,
55 ValidatorAddress: valset.Validators[1].Address,
56 Timestamp: commitTimestamp,
57 Signature: []byte("\x34\x41\x2e\x78\x7f\xbf\x70\xef\x14\x48\xe3\x14\xd5\x83\xdc\x42\xff\x40\xf6\x5b\x71\x62\x09\xf9\x6f\x54\x63\x3e\xdb\xc5\x98\xc0\x9e\xa7\xde\x33\xac\xa7\x5f\xbb\xd6\x63\x49\xe1\xe9\x98\x86\x03\x46\x6a\x7e\xb6\x5d\xe5\x71\xe5\x1e\x5d\x4d\xd8\x8d\xbe\x2f\x01"),
58 },
59 }
60
61 msgHeader = tmtesting.NewMsgHeader(
62 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
63 nextValset, trustedValset, signatures,
64 )
65 )
66 msgHeader.Commit.BlockID.Hash = tmtesting.Hash("other hash")
67
68 core.UpdateClient(cross(cur), clientID, msgHeader)
69 }
70}
71
72// Error:
73// expected BlockID#Hash and Header#Hash to be the same, got "aad9a74f487dfccef6f80cfae921f559edf9ab9b9246686cbd32a9825325639f" != "b68a342c6770741e9e70fdc24bb54cddf2442e2cf8461da50919ff0765bc8ea3"