Search Apps Documentation Source Content File Folder Download Copy Actions Download

z9g_recover_client_filetest.gno

5.02 Kb · 101 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// RecoverClient failure: substitute has mismatching immutable client state
 14// (different MaxClockDrift).
 15func main(cur realm) {
 16	core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 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		val1        = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
 23			"VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
 24		val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
 25			"NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
 26		trustedValset  = tendermint.NewValset(val1, val2)
 27		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
 28	)
 29	subjectID := core.CreateClient(cross(cur), clientState, consensusState)
 30
 31	// Freeze the subject via misbehaviour so it reaches Frozen status.
 32	header1, header2 := freezingHeaders(chainID, clientState.LatestHeight, trustedValset, consensusState.Timestamp)
 33	core.UpdateClient(cross(cur), subjectID, &tendermint.Misbehaviour{Header1: header1, Header2: header2})
 34
 35	// Substitute has a different MaxClockDrift (30m instead of default 1h).
 36	substituteState := tmtesting.NewClientState(chainID, clientState.LatestHeight)
 37	substituteState.MaxClockDrift = 30 * time.Minute
 38	substituteID := core.CreateClient(cross(cur), substituteState, consensusState)
 39
 40	core.RecoverClient(cross(cur), subjectID, substituteID)
 41}
 42
 43func freezingHeaders(chainID string, trustedHeight types.Height,
 44	trustedValset *tendermint.ValidatorSet, baseTime time.Time,
 45) (*tendermint.MsgHeader, *tendermint.MsgHeader) {
 46	var header1, header2 *tendermint.MsgHeader
 47	{
 48		var (
 49			apphash         = tmtesting.Hash("apphash-4")
 50			val1            = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 51			val2            = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 52			valset          = tendermint.NewValset(val1, val2)
 53			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 54			signatures      = []tendermint.CommitSig{
 55				{
 56					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 57					ValidatorAddress: valset.Validators[0].Address,
 58					Timestamp:        commitTimestamp,
 59					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"),
 60				},
 61				{
 62					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 63					ValidatorAddress: valset.Validators[1].Address,
 64					Timestamp:        commitTimestamp,
 65					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"),
 66				},
 67			}
 68		)
 69		header1 = tmtesting.NewMsgHeader(chainID, baseTime, apphash, 4,
 70			trustedHeight, valset, tendermint.NewValset(val1, val2), trustedValset, signatures)
 71	}
 72	{
 73		var (
 74			apphash         = tmtesting.Hash("apphash-3")
 75			val1            = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 76			val2            = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 77			valset          = tendermint.NewValset(val1, val2)
 78			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 79			signatures      = []tendermint.CommitSig{
 80				{
 81					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 82					ValidatorAddress: valset.Validators[0].Address,
 83					Timestamp:        commitTimestamp,
 84					Signature:        []byte("\x51\xa4\x8f\x78\x42\x4e\x6e\x0d\xc3\x2b\xe6\xcb\x09\x5c\xe5\x7d\x35\x84\xcf\xb1\x0f\x53\x72\x0c\x41\xde\xd3\x6d\xbc\x81\x28\x64\x41\xf7\xe9\x1e\xa9\x93\xd0\xa4\x84\x16\xca\xa8\xa3\x8e\x56\x45\xec\xae\x1d\x24\xb4\xa8\xf4\x29\x85\x04\x06\xe4\x18\x6b\x7d\x08"),
 85				},
 86				{
 87					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 88					ValidatorAddress: valset.Validators[1].Address,
 89					Timestamp:        commitTimestamp,
 90					Signature:        []byte("\xd9\xd6\x82\x83\x78\x75\xfa\x2e\xd7\x1b\xa5\x3d\xfe\xb3\x80\xb6\xc7\x59\x20\x45\x10\xdf\x0c\x19\xd1\xcc\xfc\x37\xd5\x59\x79\x95\x93\x60\x08\xfb\x5f\xa0\x87\x95\x51\x1e\x29\xed\x94\xd1\x31\x5e\xda\x90\x86\x11\xbe\xb2\x88\x68\xe1\xba\xa7\x31\xc7\xa2\xda\x07"),
 91				},
 92			}
 93		)
 94		header2 = tmtesting.NewMsgHeader(chainID, baseTime, apphash, 3,
 95			trustedHeight, valset, tendermint.NewValset(val1, val2), trustedValset, signatures)
 96	}
 97	return header1, header2
 98}
 99
100// Error:
101// subject and substitute client states differ on MaxClockDrift