Search Apps Documentation Source Content File Folder Download Copy Actions Download

z9e_recover_client_filetest.gno

5.01 Kb · 102 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 client is not Active (Frozen here).
 14// Both subject and substitute are created with the same initial state, then
 15// frozen via the same misbehaviour message.
 16func main(cur realm) {
 17	core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 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		val1        = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
 24			"VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
 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	subjectID := core.CreateClient(cross(cur), clientState, consensusState)
 31	substituteID := core.CreateClient(cross(cur), clientState, consensusState)
 32
 33	misbehaviour := buildMisbehaviour(chainID, clientState.LatestHeight, trustedValset, consensusState.Timestamp)
 34	core.UpdateClient(cross(cur), subjectID, misbehaviour)
 35	core.UpdateClient(cross(cur), substituteID, misbehaviour)
 36
 37	core.RecoverClient(cross(cur), subjectID, substituteID)
 38}
 39
 40func buildMisbehaviour(chainID string, trustedHeight types.Height,
 41	trustedValset *tendermint.ValidatorSet, baseTime time.Time,
 42) *tendermint.Misbehaviour {
 43	var header1, header2 *tendermint.MsgHeader
 44	{
 45		var (
 46			apphash         = tmtesting.Hash("apphash-4")
 47			val1            = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 48			val2            = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 49			valset          = tendermint.NewValset(val1, val2)
 50			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 51			newHeight       = uint64(4)
 52			nextValset      = tendermint.NewValset(val1, val2)
 53			signatures      = []tendermint.CommitSig{
 54				{
 55					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 56					ValidatorAddress: valset.Validators[0].Address,
 57					Timestamp:        commitTimestamp,
 58					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"),
 59				},
 60				{
 61					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 62					ValidatorAddress: valset.Validators[1].Address,
 63					Timestamp:        commitTimestamp,
 64					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"),
 65				},
 66			}
 67		)
 68		header1 = tmtesting.NewMsgHeader(chainID, baseTime, apphash, newHeight,
 69			trustedHeight, valset, nextValset, trustedValset, signatures)
 70	}
 71	{
 72		var (
 73			apphash         = tmtesting.Hash("apphash-3")
 74			val1            = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 75			val2            = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 76			valset          = tendermint.NewValset(val1, val2)
 77			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 78			newHeight       = uint64(3)
 79			nextValset      = tendermint.NewValset(val1, val2)
 80			signatures      = []tendermint.CommitSig{
 81				{
 82					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 83					ValidatorAddress: valset.Validators[0].Address,
 84					Timestamp:        commitTimestamp,
 85					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"),
 86				},
 87				{
 88					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 89					ValidatorAddress: valset.Validators[1].Address,
 90					Timestamp:        commitTimestamp,
 91					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"),
 92				},
 93			}
 94		)
 95		header2 = tmtesting.NewMsgHeader(chainID, baseTime, apphash, newHeight,
 96			trustedHeight, valset, nextValset, trustedValset, signatures)
 97	}
 98	return &tendermint.Misbehaviour{Header1: header1, Header2: header2}
 99}
100
101// Error:
102// substitute client 07-tendermint-2 must be Active, got Frozen