Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2f_update_client_filetest.gno

1.61 Kb · 52 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4import (
 5	"errors"
 6	"time"
 7
 8	"gno.land/p/aib/ibc/lightclient"
 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// validateError implements ClientMessage in order to returns an error when
15// ValidateBasic() is invoked.
16type validateError struct{}
17
18func (validateError) ValidateBasic() error {
19	return errors.New("validate error")
20}
21
22func (validateError) ClientType() string {
23	return lightclient.Tendermint
24}
25
26// UpdateClient assert
27// Assert calls to clientMessage.ValidateBasic
28// NOTE: We don't want to test ValidateBasic() checks in filetest because it
29// has too many cases, hence ValidateBasic is tested in unittests and we only
30// ensure that the ValidateBasic() method are properly invoked.
31func main(cur realm) {
32	// CreateClient and RegisterCounterparty
33	var (
34		chainID        = "chain-id-2"
35		clientState    = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
36		apphash        = tmtesting.Hash("apphash")
37		trustedValset  = tmtesting.GenValset()
38		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
39	)
40	clientID := core.CreateClient(cross(cur), clientState, consensusState)
41	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
42
43	// Update clientID
44	println("clientMessage.ValidateBasic():",
45		// NOTE: panics in explicit cross realm can only be caught by revive.
46		revive(func() {
47			core.UpdateClient(cross(cur), clientID, validateError{})
48		}))
49}
50
51// Output:
52// clientMessage.ValidateBasic(): validate error