Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2k_update_client_filetest.gno

1.26 Kb · 39 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4import (
 5	"time"
 6
 7	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 8	"gno.land/p/aib/ibc/types"
 9	"gno.land/r/aib/ibc/core"
10)
11
12// UpdateClient height older than trusted height
13func main(cur realm) {
14	// CreateClient and RegisterCounterparty
15	var (
16		chainID        = "chain-id-2"
17		clientState    = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
18		apphash        = tmtesting.Hash("apphash")
19		trustedValset  = tmtesting.GenValset()
20		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
21	)
22	clientID := core.CreateClient(cross(cur), clientState, consensusState)
23	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
24
25	// Update clientID with height older than trusted height
26	var (
27		newHeight     = clientState.LatestHeight.RevisionHeight - 1
28		newTimestamp  = consensusState.Timestamp.Add(time.Minute)
29		trustedHeight = clientState.LatestHeight
30		msgHeader     = tmtesting.GenMsgHeader(
31			chainID, newTimestamp, apphash, newHeight, trustedHeight, trustedValset, trustedValset, trustedValset,
32		)
33	)
34
35	core.UpdateClient(cross(cur), clientID, msgHeader)
36}
37
38// Error:
39// trustedHeight 2/2 must be less than header height 2/1