|
|
@ -209,6 +209,8 @@ func TestClient_SequentialVerification(t *testing.T) { |
|
|
|
for _, tc := range testCases { |
|
|
|
testCase := tc |
|
|
|
t.Run(testCase.name, func(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockNode := mockNodeFromHeadersAndVals(testCase.otherHeaders, testCase.vals) |
|
|
|
mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) |
|
|
|
c, err := light.NewClient( |
|
|
@ -219,7 +221,7 @@ func TestClient_SequentialVerification(t *testing.T) { |
|
|
|
[]provider.Provider{mockNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.SequentialVerification(), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
|
|
|
|
if testCase.initErr { |
|
|
@ -329,6 +331,8 @@ func TestClient_SkippingVerification(t *testing.T) { |
|
|
|
for _, tc := range testCases { |
|
|
|
tc := tc |
|
|
|
t.Run(tc.name, func(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockNode := mockNodeFromHeadersAndVals(tc.otherHeaders, tc.vals) |
|
|
|
mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) |
|
|
|
c, err := light.NewClient( |
|
|
@ -339,7 +343,7 @@ func TestClient_SkippingVerification(t *testing.T) { |
|
|
|
[]provider.Provider{mockNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.SkippingVerification(light.DefaultTrustLevel), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
if tc.initErr { |
|
|
|
require.Error(t, err) |
|
|
@ -436,6 +440,8 @@ func TestClientBisectionBetweenTrustedHeaders(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestClient_Cleanup(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockFullNode := &provider_mocks.Provider{} |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) |
|
|
|
c, err := light.NewClient( |
|
|
@ -445,7 +451,7 @@ func TestClient_Cleanup(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
_, err = c.TrustedLightBlock(1) |
|
|
@ -465,6 +471,8 @@ func TestClient_Cleanup(t *testing.T) { |
|
|
|
func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) { |
|
|
|
// 1. options.Hash == trustedHeader.Hash
|
|
|
|
t.Run("hashes should match", func(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockNode := &provider_mocks.Provider{} |
|
|
|
trustedStore := dbs.New(dbm.NewMemDB()) |
|
|
|
err := trustedStore.SaveLightBlock(l1) |
|
|
@ -477,7 +485,7 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) { |
|
|
|
mockNode, |
|
|
|
[]provider.Provider{mockNode}, |
|
|
|
trustedStore, |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -495,6 +503,8 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) { |
|
|
|
err := trustedStore.SaveLightBlock(l1) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
// header1 != h1
|
|
|
|
header1 := keys.GenSignedHeader(chainID, 1, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
@ -511,7 +521,7 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) { |
|
|
|
mockNode, |
|
|
|
[]provider.Provider{mockNode}, |
|
|
|
trustedStore, |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -531,6 +541,9 @@ func TestClient_Update(t *testing.T) { |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(0)).Return(l3, nil) |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(3)).Return(l3, nil) |
|
|
|
|
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
c, err := light.NewClient( |
|
|
|
ctx, |
|
|
|
chainID, |
|
|
@ -538,7 +551,7 @@ func TestClient_Update(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -553,6 +566,8 @@ func TestClient_Update(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestClient_Concurrency(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockFullNode := &provider_mocks.Provider{} |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(2)).Return(l2, nil) |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) |
|
|
@ -563,7 +578,7 @@ func TestClient_Concurrency(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -602,6 +617,8 @@ func TestClient_AddProviders(t *testing.T) { |
|
|
|
1: h1, |
|
|
|
2: h2, |
|
|
|
}, valSet) |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
c, err := light.NewClient( |
|
|
|
ctx, |
|
|
|
chainID, |
|
|
@ -609,7 +626,7 @@ func TestClient_AddProviders(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -638,6 +655,9 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) { |
|
|
|
|
|
|
|
mockDeadNode := &provider_mocks.Provider{} |
|
|
|
mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrNoResponse) |
|
|
|
|
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
c, err := light.NewClient( |
|
|
|
ctx, |
|
|
|
chainID, |
|
|
@ -645,7 +665,7 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) { |
|
|
|
mockDeadNode, |
|
|
|
[]provider.Provider{mockDeadNode, mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
@ -666,6 +686,8 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T) |
|
|
|
mockFullNode := &provider_mocks.Provider{} |
|
|
|
mockFullNode.On("LightBlock", mock.Anything, mock.Anything).Return(l1, nil) |
|
|
|
|
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
mockDeadNode := &provider_mocks.Provider{} |
|
|
|
mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) |
|
|
|
c, err := light.NewClient( |
|
|
@ -675,7 +697,7 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T) |
|
|
|
mockDeadNode, |
|
|
|
[]provider.Provider{mockDeadNode, mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
_, err = c.Update(ctx, bTime.Add(2*time.Hour)) |
|
|
@ -689,6 +711,8 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T) |
|
|
|
} |
|
|
|
|
|
|
|
func TestClient_BackwardsVerification(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
{ |
|
|
|
headers, vals, _ := genLightBlocksWithKeys(chainID, 9, 3, 0, bTime) |
|
|
|
delete(headers, 1) |
|
|
@ -709,7 +733,7 @@ func TestClient_BackwardsVerification(t *testing.T) { |
|
|
|
mockLargeFullNode, |
|
|
|
[]provider.Provider{mockLargeFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -768,7 +792,7 @@ func TestClient_BackwardsVerification(t *testing.T) { |
|
|
|
mockNode, |
|
|
|
[]provider.Provider{mockNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
@ -802,6 +826,8 @@ func TestClient_NewClientFromTrustedStore(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
// different headers hash then primary plus less than 1/3 signed (no fork)
|
|
|
|
headers1 := map[int64]*types.SignedHeader{ |
|
|
|
1: h1, |
|
|
@ -840,7 +866,7 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockBadNode1, mockBadNode2}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
// witness should have behaved properly -> no error
|
|
|
|
require.NoError(t, err) |
|
|
@ -865,6 +891,8 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestClient_TrustedValidatorSet(t *testing.T) { |
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
differentVals, _ := factory.RandValidatorSet(10, 100) |
|
|
|
mockBadValSetNode := mockNodeFromHeadersAndVals( |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
@ -896,7 +924,7 @@ func TestClient_TrustedValidatorSet(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockBadValSetNode, mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.Equal(t, 2, len(c.Witnesses())) |
|
|
@ -921,6 +949,8 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) { |
|
|
|
0: vals, |
|
|
|
}) |
|
|
|
|
|
|
|
logger := log.NewTestingLogger(t) |
|
|
|
|
|
|
|
c, err := light.NewClient( |
|
|
|
ctx, |
|
|
|
chainID, |
|
|
@ -928,7 +958,7 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) { |
|
|
|
mockFullNode, |
|
|
|
[]provider.Provider{mockFullNode}, |
|
|
|
dbs.New(dbm.NewMemDB()), |
|
|
|
light.Logger(log.TestingLogger()), |
|
|
|
light.Logger(logger), |
|
|
|
light.PruningSize(1), |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|