Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2aaa_update_client_filetest.gno

5.89 Kb · 139 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 update twice with same header
 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=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		core.UpdateClient(cross(cur), clientID, msgHeader)
 67		core.UpdateClient(cross(cur), clientID, msgHeader)
 68	}
 69
 70	println("----------- assert render clients")
 71	println(core.Render("clients"))
 72	println("----------- assert render clients/07-tendermint-1/consensus_states")
 73	println(core.Render("clients/" + clientID + "/consensus_states"))
 74}
 75
 76// Output:
 77// ----------- assert render clients
 78// {"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":3},"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":3},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}}],"page":1,"total":1}
 79// ----------- assert render clients/07-tendermint-1/consensus_states
 80// {"items":[{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="},{"height":{"revision_number":1,"revision_height":3},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}],"page":1,"total":1}
 81
 82// Events:
 83// [
 84//   {
 85//     "type": "create_client",
 86//     "attrs": [
 87//       {
 88//         "key": "client_id",
 89//         "value": "07-tendermint-1"
 90//       },
 91//       {
 92//         "key": "client_type",
 93//         "value": "07-tendermint"
 94//       },
 95//       {
 96//         "key": "consensus_heights",
 97//         "value": "1/2"
 98//       }
 99//     ],
100//     "pkg_path": "gno.land/r/aib/ibc/core"
101//   },
102//   {
103//     "type": "update_client",
104//     "attrs": [
105//       {
106//         "key": "client_id",
107//         "value": "07-tendermint-1"
108//       },
109//       {
110//         "key": "client_type",
111//         "value": "07-tendermint"
112//       },
113//       {
114//         "key": "consensus_heights",
115//         "value": "1/3"
116//       }
117//     ],
118//     "pkg_path": "gno.land/r/aib/ibc/core"
119//   },
120//   {
121//     "type": "update_client",
122//     "attrs": [
123//       {
124//         "key": "client_id",
125//         "value": "07-tendermint-1"
126//       },
127//       {
128//         "key": "client_type",
129//         "value": "07-tendermint"
130//       },
131//       {
132//         "key": "consensus_heights",
133//         "value": "1/3"
134//       }
135//     ],
136//     "pkg_path": "gno.land/r/aib/ibc/core"
137//   }
138// ]
139