MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestClient_BackwardsVerification

Function TestClient_BackwardsVerification

light/client_test.go:783–887  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

781}
782
783func TestClient_BackwardsVerification(t *testing.T) {
784 {
785 trustHeader, _ := largeFullNode.LightBlock(ctx, 6)
786 c, err := light.NewClient(
787 ctx,
788 chainID,
789 light.TrustOptions{
790 Period: 4 * time.Minute,
791 Height: trustHeader.Height,
792 Hash: trustHeader.Hash(),
793 },
794 largeFullNode,
795 []provider.Provider{largeFullNode},
796 dbs.New(dbm.NewMemDB(), chainID),
797 light.Logger(log.TestingLogger()),
798 )
799 require.NoError(t, err)
800
801 // 1) verify before the trusted header using backwards => expect no error
802 h, err := c.VerifyLightBlockAtHeight(ctx, 5, bTime.Add(6*time.Minute))
803 require.NoError(t, err)
804 if assert.NotNil(t, h) {
805 assert.EqualValues(t, 5, h.Height)
806 }
807
808 // 2) untrusted header is expired but trusted header is not => expect no error
809 h, err = c.VerifyLightBlockAtHeight(ctx, 3, bTime.Add(8*time.Minute))
810 assert.NoError(t, err)
811 assert.NotNil(t, h)
812
813 // 3) already stored headers should return the header without error
814 h, err = c.VerifyLightBlockAtHeight(ctx, 5, bTime.Add(6*time.Minute))
815 assert.NoError(t, err)
816 assert.NotNil(t, h)
817
818 // 4a) First verify latest header
819 _, err = c.VerifyLightBlockAtHeight(ctx, 9, bTime.Add(9*time.Minute))
820 require.NoError(t, err)
821
822 // 4b) Verify backwards using bisection => expect no error
823 _, err = c.VerifyLightBlockAtHeight(ctx, 7, bTime.Add(9*time.Minute))
824 assert.NoError(t, err)
825 // shouldn't have verified this header in the process
826 _, err = c.TrustedLightBlock(8)
827 assert.Error(t, err)
828
829 // 5) Try bisection method, but closest header (at 7) has expired
830 // so expect error
831 _, err = c.VerifyLightBlockAtHeight(ctx, 8, bTime.Add(12*time.Minute))
832 assert.Error(t, err)
833
834 }
835 {
836 testCases := []struct {
837 provider provider.Provider
838 }{
839 {
840 // 7) provides incorrect height

Callers

nothing calls this directly

Calls 11

TrustedLightBlockMethod · 0.95
NewClientFunction · 0.92
LoggerFunction · 0.92
TestingLoggerFunction · 0.92
hashFunction · 0.85
GenSignedHeaderMethod · 0.80
LightBlockMethod · 0.65
HashMethod · 0.65
ErrorMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected