Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2a_update_client_filetest.gno

5.62 Kb · 124 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 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=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	}
 68
 69	println("----------- assert render clients")
 70	println(core.Render("clients"))
 71	println("----------- assert render clients/07-tendermint-1/consensus_states")
 72	println(core.Render("clients/" + clientID + "/consensus_states"))
 73	println("----------- assert render client status")
 74	println(core.Render("clients/" + clientID + "/status"))
 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":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}
 80// ----------- assert render clients/07-tendermint-1/consensus_states
 81// {"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}
 82// ----------- assert render client status
 83// {"status":"Active"}
 84
 85// Events:
 86// [
 87//   {
 88//     "type": "create_client",
 89//     "attrs": [
 90//       {
 91//         "key": "client_id",
 92//         "value": "07-tendermint-1"
 93//       },
 94//       {
 95//         "key": "client_type",
 96//         "value": "07-tendermint"
 97//       },
 98//       {
 99//         "key": "consensus_heights",
100//         "value": "1/2"
101//       }
102//     ],
103//     "pkg_path": "gno.land/r/aib/ibc/core"
104//   },
105//   {
106//     "type": "update_client",
107//     "attrs": [
108//       {
109//         "key": "client_id",
110//         "value": "07-tendermint-1"
111//       },
112//       {
113//         "key": "client_type",
114//         "value": "07-tendermint"
115//       },
116//       {
117//         "key": "consensus_heights",
118//         "value": "1/3"
119//       }
120//     ],
121//     "pkg_path": "gno.land/r/aib/ibc/core"
122//   }
123// ]
124