Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2r_update_client_filetest.gno

6.16 Kb · 125 lines
  1// PKGPATH: gno.land/r/aib/main
  2package main
  3
  4import (
  5	"testing"
  6	"time"
  7
  8	"gno.land/p/aib/ibc/lightclient/tendermint"
  9	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 10	"gno.land/p/aib/ibc/types"
 11	"gno.land/r/aib/ibc/core"
 12)
 13
 14// UpdateClient fails bc trusted header time > now+trustingPeriod
 15func main(cur realm) {
 16	// CreateClient and RegisterCounterparty
 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		// priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
 23		val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
 24			"VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 25		// priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 26		val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
 27			"NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 28		trustedValset  = tendermint.NewValset(val1, val2)
 29		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
 30	)
 31	clientID := core.CreateClient(cross(cur), clientState, consensusState)
 32	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
 33
 34	// Increase block time
 35	ctx := testing.GetContext()
 36	ctx.Time = time.Now().Add(clientState.TrustingPeriod / 2)
 37	testing.SetContext(ctx)
 38
 39	// Update clientID
 40	// NOTE code generated by:
 41	// go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-3 -chainid=atomone-1 -header-time-shift=30 -height=3 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 42	{
 43		var (
 44			apphash         = tmtesting.Hash("apphash-3")
 45			valset          = tendermint.NewValset(val1, val2)
 46			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 47			newHeight       = uint64(3)
 48			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(30))
 49			nextValset      = tendermint.NewValset(val1, val2)
 50			trustedHeight   = clientState.LatestHeight
 51
 52			signatures = []tendermint.CommitSig{
 53				{
 54					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 55					ValidatorAddress: valset.Validators[0].Address,
 56					Timestamp:        commitTimestamp,
 57					Signature:        []byte("\x6e\x67\x16\x43\xb9\x51\x74\x78\x24\x83\x57\x8d\x62\x42\x97\x6c\xc7\x41\xcf\x1e\x92\x33\x53\x34\x8f\xe9\xa2\xb5\x76\x6a\xad\xa9\x01\x1f\x90\xd5\x31\x1f\x09\x97\xc2\x90\x90\x2c\x48\x99\x37\x54\x38\xb5\x50\xee\xc0\x99\xaf\x0f\x68\xae\x2b\x17\x21\x59\x3e\x08"),
 58				},
 59				{
 60					BlockIDFlag:      tendermint.BlockIDFlagCommit,
 61					ValidatorAddress: valset.Validators[1].Address,
 62					Timestamp:        commitTimestamp,
 63					Signature:        []byte("\x43\x20\x1c\xa1\xec\x64\xb4\xe8\x3c\xcb\x66\x80\x7c\x7e\x5b\x31\xdd\x85\x16\xad\x32\x0b\x45\x3a\xf7\xbb\x65\x03\xd8\xcd\x9c\x7b\xdd\x76\x65\xa2\xbb\x45\xe9\x72\x96\x99\x2d\x35\x71\x62\x3c\x0a\x2f\x87\x77\xd2\x60\xb8\x77\xe8\x06\x0d\x24\x96\xae\x5b\xc1\x0f"),
 64				},
 65			}
 66
 67			msgHeader = tmtesting.NewMsgHeader(
 68				chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
 69				nextValset, trustedValset, signatures,
 70			)
 71		)
 72		core.UpdateClient(cross(cur), clientID, msgHeader)
 73	}
 74	// Increase block time again, now the initial trusted header is expired.
 75	ctx.Time = time.Now().Add(clientState.TrustingPeriod / 2)
 76	testing.SetContext(ctx)
 77
 78	// Perform an other update which references the initial trusted height which
 79	// is now older than TrustingPeriod.
 80	// NOTE we need to reference a height that is not the latest height to
 81	// trigger this error, otherwise we would get an other error: the client
 82	// expired error.
 83
 84	// NOTE code generated by:
 85	// go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-4 -chainid=atomone-1 -header-time-shift=60 -height=4 -new-validators=0 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 86	{
 87		var (
 88			apphash = tmtesting.Hash("apphash-4")
 89			// priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
 90			val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=", "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 10)
 91			// priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 92			val2            = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=", "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 10)
 93			valset          = tendermint.NewValset(val1, val2)
 94			commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 95			newHeight       = uint64(4)
 96			newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(60))
 97			nextValset      = tendermint.NewValset(val1, val2)
 98			trustedHeight   = clientState.LatestHeight
 99
100			signatures = []tendermint.CommitSig{
101				{
102					BlockIDFlag:      tendermint.BlockIDFlagCommit,
103					ValidatorAddress: valset.Validators[0].Address,
104					Timestamp:        commitTimestamp,
105					Signature:        []byte("\x62\x9a\x39\xdd\x10\x62\x30\xd9\x3e\xd1\x34\xe6\x12\x9a\x58\x68\x19\xbb\x2d\x9c\xe1\x84\xbf\xab\x91\x0f\xf9\xfa\x6e\xa7\xe9\x30\xde\x2e\xde\xd3\xed\x5e\xf4\x7a\xf3\xae\xfb\x7c\x0f\xc1\xb2\x9d\x06\xa3\x05\x62\x2f\x06\xdb\x68\x0c\xc3\xd3\xfc\xed\x94\x42\x05"),
106				},
107				{
108					BlockIDFlag:      tendermint.BlockIDFlagCommit,
109					ValidatorAddress: valset.Validators[1].Address,
110					Timestamp:        commitTimestamp,
111					Signature:        []byte("\x35\x6b\x6a\xbd\xf5\x14\x9c\xad\xd1\xef\xd6\x37\x97\xb8\x0b\x92\x4b\x48\xd5\x11\x50\xb4\xd0\x0e\x6e\xac\x9d\x98\x1c\xb3\x9e\x71\x6c\x73\x28\x72\x75\x62\xb6\x5a\x15\x60\x71\x6b\x75\x55\x02\x5d\xd9\xd7\xcc\xc1\x05\xef\xf5\xfe\x95\x5f\xbc\x89\x93\x70\x64\x04"),
112				},
113			}
114
115			msgHeader = tmtesting.NewMsgHeader(
116				chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
117				nextValset, trustedValset, signatures,
118			)
119		)
120		core.UpdateClient(cross(cur), clientID, msgHeader)
121	}
122}
123
124// Error:
125// header 2 has expired at 2009-02-14 00:31:30 +0000 UTC (now: 2009-02-14 00:31:30 +0000 UTC)