Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2aaaaa_update_client_filetest.gno

6.03 Kb · 128 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 authorized relayer
 14func main(cur realm) {
 15	core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 16	core.AddRelayer(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 17	// CreateClient and RegisterCounterparty
 18	var (
 19		chainID     = "atomone-1"
 20		height      = uint64(2)
 21		clientState = tmtesting.NewClientState(chainID, types.NewHeight(1, height))
 22		apphash     = tmtesting.Hash("apphash-2")
 23		// priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
 24		val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
 25			"VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
 26		// priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 27		val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
 28			"NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
 29		trustedValset  = tendermint.NewValset(val1, val2)
 30		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
 31	)
 32	clientID := core.CreateClient(cross(cur), clientState, consensusState)
 33	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
 34
 35	// Update clientID
 36	// NOTE code generated by:
 37	// go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-3 -chainid=atomone-1 -header-time-shift=1 -height=5 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 38	{
 39		var (
 40			newHeight       = height + 3 // non-adjacent heigth 5
 41			apphash         = tmtesting.Hash("apphash-3")
 42			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 43			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(1))
 44			valset          = tendermint.NewValset(val1, val2)
 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("\x94\x28\x84\xa4\xd1\xe9\xfe\x7d\xa9\x0f\x4d\x35\xc6\xa7\x0b\x1b\x7e\x83\xe0\xc7\x4b\xc3\x57\xa4\xf2\x35\xf7\x61\x52\xe3\xe6\xde\x58\xf6\x61\x0d\xf3\x00\x37\xc2\x0c\x13\x20\x46\x5e\x43\x26\x1b\xb4\x87\x20\x06\x80\x81\x15\x84\xd4\x98\xeb\xcb\xf2\x42\xbb\x0b"),
 54				},
 55				{
 56					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 57					ValidatorAddress: valset.Validators[1].Address,
 58					Timestamp:        commitTimestamp,
 59					Signature:        []byte("\x49\x3f\x4e\x6e\x7b\x72\x0a\xdb\x90\x6d\xdb\xfd\x24\x67\x9b\x00\xf5\x7d\xc3\x7b\x7f\x71\xf4\xe0\x0d\xce\xed\xfd\x27\xdd\x58\x7b\x04\x25\xa9\x7b\xa7\x60\x40\x7c\x11\x55\xe7\xda\xed\x88\xf3\x78\x54\xeb\x7f\x91\xfb\xd4\xe9\x2a\xd8\x8e\xb6\x11\x0a\xdf\xc9\x0d"),
 60				},
 61			}
 62
 63			msgHeader = tmtesting.NewMsgHeader(
 64				chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
 65				nextValset, trustedValset, signatures,
 66			)
 67		)
 68		core.UpdateClient(cross(cur), clientID, msgHeader)
 69	}
 70
 71	println("----------- assert render clients")
 72	println(core.Render("clients"))
 73	println("\n----------- assert render clients/07-tendermint-1/consensus_states")
 74	println(core.Render("clients/" + clientID + "/consensus_states"))
 75	println("\n----------- assert render clients/07-tendermint-1/consensus_states/1/5")
 76	println(core.Render("clients/" + clientID + "/consensus_states/1/5"))
 77}
 78
 79// Output:
 80// ----------- assert render clients
 81// {"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":5},"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":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}}],"page":1,"total":1}
 82//
 83// ----------- assert render clients/07-tendermint-1/consensus_states
 84// {"items":[{"height":{"revision_number":1,"revision_height":2},"timestamp":1234567890,"root":"YAdxKyKDg+tUQc5Dli2fYkJ2imznqbJ+UDfQ7y0QNlM=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="},{"height":{"revision_number":1,"revision_height":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}],"page":1,"total":1}
 85//
 86// ----------- assert render clients/07-tendermint-1/consensus_states/1/5
 87// {"height":{"revision_number":1,"revision_height":5},"timestamp":1234567950,"root":"m9afpc+PXaYRHdGC7FkrzuzRNn8ONC1xRCzYYAPRCU8=","next_validators_hash":"OJfJuH6dfiZI2d0uAxqamqfIVqV4c4oEAZigvJ8UqFQ="}
 88
 89// Events:
 90// [
 91//   {
 92//     "type": "create_client",
 93//     "attrs": [
 94//       {
 95//         "key": "client_id",
 96//         "value": "07-tendermint-1"
 97//       },
 98//       {
 99//         "key": "client_type",
100//         "value": "07-tendermint"
101//       },
102//       {
103//         "key": "consensus_heights",
104//         "value": "1/2"
105//       }
106//     ],
107//     "pkg_path": "gno.land/r/aib/ibc/core"
108//   },
109//   {
110//     "type": "update_client",
111//     "attrs": [
112//       {
113//         "key": "client_id",
114//         "value": "07-tendermint-1"
115//       },
116//       {
117//         "key": "client_type",
118//         "value": "07-tendermint"
119//       },
120//       {
121//         "key": "consensus_heights",
122//         "value": "1/5"
123//       }
124//     ],
125//     "pkg_path": "gno.land/r/aib/ibc/core"
126//   }
127// ]
128