@ -28,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
@ -36,22 +35,15 @@ import (
func TestULCSyncWithOnePeer ( t * testing . T ) {
f := newFullPeerPair ( t , 1 , 4 )
ulcConfig := & eth . ULCConfig {
MinTrustedFraction : 100 ,
TrustedServers : [ ] string { f . Node . String ( ) } ,
}
l := newLightPeer ( t , ulcConfig )
l := newLightPeer ( t , [ ] string { f . Node . String ( ) } , 100 )
if reflect . DeepEqual ( f . PM . blockchain . CurrentHeader ( ) . Hash ( ) , l . PM . blockchain . CurrentHeader ( ) . Hash ( ) ) {
t . Fatal ( "blocks are equal" )
}
_ , _ , err := connectPeers ( f , l , 2 )
if err != nil {
t . Fatal ( err )
}
l . PM . fetcher . lock . Lock ( )
l . PM . fetcher . nextRequest ( )
l . PM . fetcher . lock . Unlock ( )
@ -63,24 +55,17 @@ func TestULCSyncWithOnePeer(t *testing.T) {
func TestULCReceiveAnnounce ( t * testing . T ) {
f := newFullPeerPair ( t , 1 , 4 )
ulcConfig := & eth . ULCConfig {
MinTrustedFraction : 100 ,
TrustedServers : [ ] string { f . Node . String ( ) } ,
}
l := newLightPeer ( t , ulcConfig )
l := newLightPeer ( t , [ ] string { f . Node . String ( ) } , 100 )
fPeer , lPeer , err := connectPeers ( f , l , 2 )
if err != nil {
t . Fatal ( err )
}
l . PM . synchronise ( fPeer )
//check that the sync is finished correctly
if ! reflect . DeepEqual ( f . PM . blockchain . CurrentHeader ( ) . Hash ( ) , l . PM . blockchain . CurrentHeader ( ) . Hash ( ) ) {
t . Fatal ( "sync doesn't work" )
}
l . PM . peers . lock . Lock ( )
if len ( l . PM . peers . peers ) == 0 {
t . Fatal ( "peer list should not be empty" )
@ -101,16 +86,7 @@ func TestULCReceiveAnnounce(t *testing.T) {
func TestULCShouldNotSyncWithTwoPeersOneHaveEmptyChain ( t * testing . T ) {
f1 := newFullPeerPair ( t , 1 , 4 )
f2 := newFullPeerPair ( t , 2 , 0 )
ulcConf := & ulc { minTrustedFraction : 100 , trustedKeys : make ( map [ string ] struct { } ) }
ulcConf . trustedKeys [ f1 . Node . ID ( ) . String ( ) ] = struct { } { }
ulcConf . trustedKeys [ f2 . Node . ID ( ) . String ( ) ] = struct { } { }
ulcConfig := & eth . ULCConfig {
MinTrustedFraction : 100 ,
TrustedServers : [ ] string { f1 . Node . String ( ) , f2 . Node . String ( ) } ,
}
l := newLightPeer ( t , ulcConfig )
l . PM . ulc . minTrustedFraction = 100
l := newLightPeer ( t , [ ] string { f1 . Node . String ( ) , f2 . Node . String ( ) } , 100 )
_ , _ , err := connectPeers ( f1 , l , 2 )
if err != nil {
t . Fatal ( err )
@ -119,7 +95,6 @@ func TestULCShouldNotSyncWithTwoPeersOneHaveEmptyChain(t *testing.T) {
if err != nil {
t . Fatal ( err )
}
l . PM . fetcher . lock . Lock ( )
l . PM . fetcher . nextRequest ( )
l . PM . fetcher . lock . Unlock ( )
@ -134,27 +109,19 @@ func TestULCShouldNotSyncWithThreePeersOneHaveEmptyChain(t *testing.T) {
f2 := newFullPeerPair ( t , 2 , 4 )
f3 := newFullPeerPair ( t , 3 , 0 )
ulcConfig := & eth . ULCConfig {
MinTrustedFraction : 60 ,
TrustedServers : [ ] string { f1 . Node . String ( ) , f2 . Node . String ( ) , f3 . Node . String ( ) } ,
}
l := newLightPeer ( t , ulcConfig )
l := newLightPeer ( t , [ ] string { f1 . Node . String ( ) , f2 . Node . String ( ) , f3 . Node . String ( ) } , 60 )
_ , _ , err := connectPeers ( f1 , l , 2 )
if err != nil {
t . Fatal ( err )
}
_ , _ , err = connectPeers ( f2 , l , 2 )
if err != nil {
t . Fatal ( err )
}
_ , _ , err = connectPeers ( f3 , l , 2 )
if err != nil {
t . Fatal ( err )
}
l . PM . fetcher . lock . Lock ( )
l . PM . fetcher . nextRequest ( )
l . PM . fetcher . lock . Unlock ( )
@ -213,7 +180,7 @@ func connectPeers(full, light pairPeer, version int) (*peer, *peer, error) {
func newFullPeerPair ( t * testing . T , index int , numberOfblocks int ) pairPeer {
db := rawdb . NewMemoryDatabase ( )
pmFull , _ := newTestProtocolManagerMust ( t , false , numberOfblocks , nil , nil , nil , db , nil )
pmFull , _ := newTestProtocolManagerMust ( t , false , numberOfblocks , nil , nil , nil , db , nil , 0 )
peerPairFull := pairPeer {
Name : "full node" ,
@ -229,7 +196,7 @@ func newFullPeerPair(t *testing.T, index int, numberOfblocks int) pairPeer {
}
// newLightPeer creates node with light sync mode
func newLightPeer ( t * testing . T , ulcConfig * eth . ULCConfig ) pairPeer {
func newLightPeer ( t * testing . T , ulcServers [ ] string , ulcFraction int ) pairPeer {
peers := newPeerSet ( )
dist := newRequestDistributor ( peers , make ( chan struct { } ) , & mclock . System { } )
rm := newRetrieveManager ( peers , dist , nil )
@ -237,12 +204,11 @@ func newLightPeer(t *testing.T, ulcConfig *eth.ULCConfig) pairPeer {
odr := NewLesOdr ( ldb , light . DefaultClientIndexerConfig , rm )
pmLight , _ := newTestProtocolManagerMust ( t , true , 0 , odr , nil , peers , ldb , ulcConfig )
pmLight , _ := newTestProtocolManagerMust ( t , true , 0 , odr , nil , peers , ldb , ulcServers , ulcFraction )
peerPairLight := pairPeer {
Name : "ulc node" ,
PM : pmLight ,
}
key , err := crypto . GenerateKey ( )
if err != nil {
t . Fatal ( "generate key err:" , err )