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