Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2n_update_client_filetest.gno

4.45 Kb · 86 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 fail because non-adjacent update has duplicate validator vote
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=sM8WuH1p/Pimp5Drexi8WrJVKzVua+Korpnngw8UfBrSDCjJi6J6ewFHa515TwWydPl76NzwejOt8hTDdLyXTw==
22		val1 = tendermint.NewValidator("ZCaZM3OK2WXj/uHn1YmlvCO0PQE=", "0gwoyYuiensBR2udeU8FsnT5e+jc8HozrfIUw3S8l08=", 10)
23		// priv=GOXnCdRYBUV1BWzSSqOxaaUbU2WlYZWAV9Y1rm9jywHVNjQk+iEgF3JfouPToU5WqbCzDB24BD8Wmagn9So1Vg==
24		val2 = tendermint.NewValidator("G/wyzTFLGS22DYSh0pGDS5oOfF8=", "1TY0JPohIBdyX6Lj06FOVqmwswwduAQ/FpmoJ/UqNVY=", 10)
25		// priv=G5L9TJSrqBE2JXVughtiAMwKfbEJtoIfHnPwI8FfuYCiKLEFBnCW9D/S28++vdBzzgotPomDaPbFj+k0ubOXjA==
26		val3 = tendermint.NewValidator("rwAy3YKM7CfDIv/ntPfTKpst5Gc=", "oiixBQZwlvQ/0tvPvr3Qc84KLT6Jg2j2xY/pNLmzl4w=", 10)
27		// priv=fKIt0/pH78rh3mS7n5RTfof2GXLrWseudqXCN8PEMhGT5xolmDLRqFaF981HoFhFHe1sP21cRiLCi4YKhe7aLQ==
28		val4 = tendermint.NewValidator("3uXANDs4EN0EdcWcUgaFboSe1Cw=", "k+caJZgy0ahWhffNR6BYRR3tbD9tXEYiwouGCoXu2i0=", 10)
29
30		trustedValset  = tendermint.NewValset(val1, val2, val3, val4)
31		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
32	)
33	clientID := core.CreateClient(cross(cur), clientState, consensusState)
34	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
35
36	// Update clientID
37	// NOTE code generated by:
38	// go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-3 -chainid=atomone-1 -header-time-shift=1 -height=5 -new-validators=4
39	{
40		var (
41			apphash         = tmtesting.Hash("apphash-3")
42			valset          = tendermint.NewValset(val1, val2, val3, val4)
43			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
44			newHeight       = uint64(5)
45			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(1))
46			nextValset      = tendermint.NewValset(val1, val2, val3, val4)
47			trustedHeight   = clientState.LatestHeight
48
49			signatures = []tendermint.CommitSig{
50				{
51					BlockIDFlag:      tendermint.BlockIDFlagCommit,
52					ValidatorAddress: valset.Validators[0].Address,
53					Timestamp:        commitTimestamp,
54					Signature:        []byte("\x82\xb3\xd9\x38\x95\x0d\xe1\xfe\xe6\x97\xe9\xd0\x14\xc8\x22\xe1\x45\x23\x7c\x3f\x61\x82\x30\x7d\x28\x1a\x53\xff\x53\x4d\x28\x66\xdf\x23\x88\x2f\x68\x3f\x34\xa7\xbe\x92\x3e\x61\x80\xef\x32\x3b\x85\xdc\x6b\x97\x93\x6f\x07\xe2\x95\xf9\xb7\xaf\x34\x57\xa0\x01"),
55				},
56				{
57					BlockIDFlag:      tendermint.BlockIDFlagCommit,
58					ValidatorAddress: valset.Validators[0].Address,
59					Timestamp:        commitTimestamp,
60					Signature:        []byte("\x82\xb3\xd9\x38\x95\x0d\xe1\xfe\xe6\x97\xe9\xd0\x14\xc8\x22\xe1\x45\x23\x7c\x3f\x61\x82\x30\x7d\x28\x1a\x53\xff\x53\x4d\x28\x66\xdf\x23\x88\x2f\x68\x3f\x34\xa7\xbe\x92\x3e\x61\x80\xef\x32\x3b\x85\xdc\x6b\x97\x93\x6f\x07\xe2\x95\xf9\xb7\xaf\x34\x57\xa0\x01"),
61				},
62				{
63					BlockIDFlag:      tendermint.BlockIDFlagCommit,
64					ValidatorAddress: valset.Validators[2].Address,
65					Timestamp:        commitTimestamp,
66					Signature:        []byte("\x57\x7c\xf9\x28\xf9\xca\xab\x7e\x80\x88\xb9\xf4\xbf\x96\x4e\x1e\x48\x23\xaf\xc4\xd1\xf1\x95\x3f\x45\xf5\xe2\xa2\x8a\xcf\x01\xdc\xcb\x3b\x04\x4f\x68\x4e\xea\x08\xa3\x27\x87\x3f\x9c\xc5\x4c\xdd\x1d\xfc\xa5\x89\xc7\x6b\xb0\x21\x2c\xdc\xa9\x30\xa9\x74\x35\x03"),
67				},
68				{
69					BlockIDFlag:      tendermint.BlockIDFlagCommit,
70					ValidatorAddress: valset.Validators[3].Address,
71					Timestamp:        commitTimestamp,
72					Signature:        []byte("\x1a\x61\x13\x6d\x91\x60\x67\xf8\x2a\x2b\x2f\xea\xa7\xba\xa4\x00\x58\x6a\x9a\x94\x16\xfb\x73\x94\xb3\x8d\x81\x37\x1f\x90\xcb\x99\x24\x1a\x35\xe6\x36\xba\xd6\x16\x65\x68\xa1\x23\x24\x84\x45\x90\x35\x11\x2d\xd5\xfb\xa8\x24\xd5\xad\x2c\x60\xdd\x91\x2d\xb5\x01"),
73				},
74			}
75
76			msgHeader = tmtesting.NewMsgHeader(
77				chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
78				nextValset, trustedValset, signatures,
79			)
80		)
81		core.UpdateClient(cross(cur), clientID, msgHeader)
82	}
83}
84
85// Error:
86// check trusted validators VP>13: double vote from 64269933738ad965e3fee1e7d589a5bc23b43d01 (0 and 1)