Merge branch 'master' of github.com:harmony-one/harmony into rj_branch

pull/211/head
Rongjian Lan 6 years ago
commit 986181b045
  1. 5
      api/services/syncing/syncing.go
  2. 40
      api/services/syncing/syncing_test.go

@ -30,6 +30,11 @@ type SyncPeerConfig struct {
blockHashes [][]byte blockHashes [][]byte
} }
// GetClient returns client pointer of downloader.Client
func (peerConfig *SyncPeerConfig) GetClient() *downloader.Client {
return peerConfig.client
}
// Log is the temporary log for syncing. // Log is the temporary log for syncing.
var Log = log.New() var Log = log.New()

@ -0,0 +1,40 @@
package syncing
import (
"testing"
"github.com/harmony-one/harmony/api/services/syncing/downloader"
"github.com/stretchr/testify/assert"
)
// Simple test for IncorrectResponse
func TestCreateTestSyncPeerConfig(t *testing.T) {
client := &downloader.Client{}
blockHashes := [][]byte{[]byte{}}
syncPeerConfig := CreateTestSyncPeerConfig(client, blockHashes)
assert.Equal(t, client, syncPeerConfig.GetClient(), "error")
}
// Simple test for IncorrectResponse
func TestCompareSyncPeerConfigByblockHashes(t *testing.T) {
client := &downloader.Client{}
blockHashes1 := [][]byte{[]byte{1, 2, 3}}
syncPeerConfig1 := CreateTestSyncPeerConfig(client, blockHashes1)
blockHashes2 := [][]byte{[]byte{1, 2, 4}}
syncPeerConfig2 := CreateTestSyncPeerConfig(client, blockHashes2)
// syncPeerConfig1 is less than syncPeerConfig2
assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), -1, "syncPeerConfig1 is less than syncPeerConfig2")
// syncPeerConfig1 is greater than syncPeerConfig2
blockHashes1[0][2] = 5
assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), 1, "syncPeerConfig1 is greater than syncPeerConfig2")
// syncPeerConfig1 is equal to syncPeerConfig2
blockHashes1[0][2] = 4
assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), 0, "syncPeerConfig1 is equal to syncPeerConfig2")
// syncPeerConfig1 is less than syncPeerConfig2
blockHashes1 = blockHashes1[:1]
assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), 0, "syncPeerConfig1 is less than syncPeerConfig2")
}
Loading…
Cancel
Save