Search Apps Documentation Source Content File Folder Download Copy Actions Download

z1i_create_client_filetest.gno

1.60 Kb · 53 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	"gno.land/p/aib/ibc/lightclient/tendermint/testing"
10	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
11	"gno.land/p/aib/ibc/types"
12	"gno.land/r/aib/ibc/core"
13)
14
15// validateError implements ClientState or ConsensusState in order to returns
16// an error when ValidateBasic() is invoked.
17type validateError struct{}
18
19func (validateError) ValidateBasic() error {
20	return errors.New("validate error")
21}
22
23func (validateError) ClientType() string {
24	return lightclient.Tendermint
25}
26
27// Assert calls to clientState.ValidateBasic and consensusState.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	var (
33		chainID        = "chain-id-2"
34		clientState    = testing.NewClientState(chainID, types.NewHeight(2, 2))
35		apphash        = tmtesting.Hash("apphash")
36		trustedValset  = testing.GenValset()
37		consensusState = testing.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
38	)
39
40	println("clientState.ValidateBasic:",
41		// NOTE: panics in explicit cross realm can only be caught by revive.
42		revive(func() {
43			core.CreateClient(cross(cur), validateError{}, consensusState)
44		}))
45	println("consensusState.ValidateBasic:",
46		revive(func() {
47			core.CreateClient(cross(cur), clientState, validateError{})
48		}))
49}
50
51// Output:
52// clientState.ValidateBasic: validate error
53// consensusState.ValidateBasic: validate error