Search Apps Documentation Source Content File Folder Download Copy Actions Download

z8aaaa_update_client_misbehaviour_filetest.gno

7.15 Kb · 156 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 valid misbehaviour:
 14// header1.height == header2.height && header1.Hash != header2.hash
 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	// 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=0 -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			valset          = tendermint.NewValset(val1, val2)
 42			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 43			newHeight       = uint64(4)
 44			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(0))
 45			nextValset      = tendermint.NewValset(val1, val2)
 46			trustedHeight   = clientState.LatestHeight
 47
 48			signatures = []tendermint.CommitSig{
 49				{
 50					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 51					ValidatorAddress: valset.Validators[0].Address,
 52					Timestamp:        commitTimestamp,
 53					Signature:        []byte("\x2e\xba\x21\xb0\x2f\xd2\x85\xb9\xef\x82\x68\xdc\xef\xd1\xd1\x12\x70\x88\x94\x10\x7e\x4d\x49\xac\x46\x3d\x86\xe2\xf2\xae\x38\xb4\xa5\xab\x0c\xc1\x8f\x8a\x59\xda\x36\x17\x01\xe4\x16\x49\xbf\x03\x86\xf0\x31\x3f\x30\x37\x9e\x47\x28\x72\x3b\x0c\x89\xb9\x94\x05"),
 54				},
 55				{
 56					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 57					ValidatorAddress: valset.Validators[1].Address,
 58					Timestamp:        commitTimestamp,
 59					Signature:        []byte("\x67\xcc\xc6\xc4\x20\xa0\xcb\x36\xaf\x33\x5c\xf8\xe4\xad\x47\x49\x38\x9d\x9e\xa3\x7c\xe6\x88\x81\x62\x51\x7f\xcc\xa5\x92\x0d\x98\xe9\xbe\x71\x2d\x22\xcd\x41\x30\x28\x83\x03\xcb\xf5\xd7\x28\xde\x7b\x92\x85\x9e\xa6\xe5\xde\x50\x89\x2d\x2b\xc5\x9d\x9a\x33\x00"),
 60				},
 61			}
 62		)
 63
 64		header1 = tmtesting.NewMsgHeader(
 65			chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
 66			nextValset, trustedValset, signatures,
 67		)
 68	}
 69	// NOTE code generated by:
 70	// go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-other -chainid=atomone-1 -header-time-shift=0 -height=4 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 71	{
 72		var (
 73			apphash         = tmtesting.Hash("apphash-other")
 74			valset          = tendermint.NewValset(val1, val2)
 75			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 76			newHeight       = uint64(4)
 77			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(0))
 78			nextValset      = tendermint.NewValset(val1, val2)
 79			trustedHeight   = clientState.LatestHeight
 80
 81			signatures = []tendermint.CommitSig{
 82				{
 83					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 84					ValidatorAddress: valset.Validators[0].Address,
 85					Timestamp:        commitTimestamp,
 86					Signature:        []byte("\xe8\x4a\xd3\x9a\x59\xf7\x95\xa4\xdc\x49\xb6\xac\x31\x29\x40\x35\x9d\x04\x06\xc1\x8e\xd1\x0e\xe9\x9f\xd3\x03\xcc\xd6\xb8\x9a\xb7\xa6\xca\xb8\xf6\xe5\xcb\x7e\x55\x14\xa2\x76\xa7\x96\x3f\x70\xed\x38\x8b\x53\x96\x15\xf0\x27\x23\xbc\xb6\x56\xc0\x11\x00\x5a\x05"),
 87				},
 88				{
 89					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 90					ValidatorAddress: valset.Validators[1].Address,
 91					Timestamp:        commitTimestamp,
 92					Signature:        []byte("\xf2\xfe\x16\xb2\xdc\xe4\x19\x5c\x24\x79\x3f\x88\x84\x5a\x5a\xee\x9c\x62\x99\x60\x0f\x3d\x36\xaa\x14\x83\x21\x4c\xe5\x95\xe6\xad\x73\xd0\x7d\xfb\x0f\x04\x44\xe4\xd7\x2e\x57\xa1\x60\x8b\xfa\x0d\x42\x93\x97\x55\x25\x6e\x87\x92\x1c\x9b\xc1\xdf\x37\xed\xd8\x0f"),
 93				},
 94			}
 95		)
 96
 97		header2 = tmtesting.NewMsgHeader(
 98			chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
 99			nextValset, trustedValset, signatures,
100		)
101	}
102	msg := &tendermint.Misbehaviour{
103		Header1: header1,
104		Header2: header2,
105	}
106
107	core.UpdateClient(cross(cur), clientID, msg)
108
109	println("----------- assert render clients")
110	println(core.Render("clients"))
111	println("----------- assert render clients/07-tendermint-1/consensus_states")
112	println(core.Render("clients/" + clientID + "/consensus_states"))
113}
114
115// Output:
116// ----------- assert render clients
117// {"items":[{"id":"07-tendermint-1","type":"07-tendermint","creator":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm","status":"Frozen","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":1},"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":"cmlnaEh97r8fwZo58weAGWc3eqq+T3xXT9C88GVXRUc="}}],"page":1,"total":1}
118// ----------- assert render clients/07-tendermint-1/consensus_states
119// {"items":[{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"cmlnaEh97r8fwZo58weAGWc3eqq+T3xXT9C88GVXRUc="}],"page":1,"total":1}
120
121// Events:
122// [
123//   {
124//     "type": "create_client",
125//     "attrs": [
126//       {
127//         "key": "client_id",
128//         "value": "07-tendermint-1"
129//       },
130//       {
131//         "key": "client_type",
132//         "value": "07-tendermint"
133//       },
134//       {
135//         "key": "consensus_heights",
136//         "value": "1/2"
137//       }
138//     ],
139//     "pkg_path": "gno.land/r/aib/ibc/core"
140//   },
141//   {
142//     "type": "client_misbehaviour",
143//     "attrs": [
144//       {
145//         "key": "client_id",
146//         "value": "07-tendermint-1"
147//       },
148//       {
149//         "key": "client_type",
150//         "value": "07-tendermint"
151//       }
152//     ],
153//     "pkg_path": "gno.land/r/aib/ibc/core"
154//   }
155// ]
156