z2e_update_client_filetest.gno
1.39 Kb · 45 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "testing"
6 "time"
7
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 on expired lightclient
14func main(cur realm) {
15 // CreateClient and RegisterCounterparty
16 var (
17 chainID = "chain-id-2"
18 clientState = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
19 apphash = tmtesting.Hash("apphash")
20 trustedValset = tmtesting.GenValset()
21 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
22 )
23 clientID := core.CreateClient(cross(cur), clientState, consensusState)
24 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
25
26 // Change block time to expire the lightclient
27 ctx := testing.GetContext()
28 ctx.Time = time.Now().Add(clientState.TrustingPeriod)
29 testing.SetContext(ctx)
30
31 // Update clientID
32 var (
33 newHeight = clientState.LatestHeight.RevisionHeight + 1
34 newTimestamp = consensusState.Timestamp.Add(time.Minute)
35 trustedHeight = clientState.LatestHeight
36 msgHeader = tmtesting.GenMsgHeader(
37 chainID, newTimestamp, apphash, newHeight, trustedHeight, trustedValset, trustedValset, trustedValset,
38 )
39 )
40
41 core.UpdateClient(cross(cur), clientID, msgHeader)
42}
43
44// Error:
45// cannot update client (07-tendermint-1) with status Expired