mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 15:33:47 +00:00
fix tests and format
This commit is contained in:
parent
aa3004b083
commit
a6ec55bb31
5 changed files with 50 additions and 40 deletions
|
|
@ -218,19 +218,19 @@ func New(checkpoint uint64, stateDb ethdb.Database, mux *event.TypeMux, chain Bl
|
||||||
lightchain = chain
|
lightchain = chain
|
||||||
}
|
}
|
||||||
dl := &Downloader{
|
dl := &Downloader{
|
||||||
stateDB: stateDb,
|
stateDB: stateDb,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
checkpoint: checkpoint,
|
checkpoint: checkpoint,
|
||||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
||||||
peers: newPeerSet(),
|
peers: newPeerSet(),
|
||||||
blockchain: chain,
|
blockchain: chain,
|
||||||
lightchain: lightchain,
|
lightchain: lightchain,
|
||||||
dropPeer: dropPeer,
|
dropPeer: dropPeer,
|
||||||
headerProcCh: make(chan *headerTask, 1),
|
headerProcCh: make(chan *headerTask, 1),
|
||||||
quitCh: make(chan struct{}),
|
quitCh: make(chan struct{}),
|
||||||
SnapSyncer: snap.NewSyncer(stateDb),
|
SnapSyncer: snap.NewSyncer(stateDb),
|
||||||
stateSyncStart: make(chan *stateSync),
|
stateSyncStart: make(chan *stateSync),
|
||||||
ChainValidator: whitelistService,
|
ChainValidator: whitelistService,
|
||||||
}
|
}
|
||||||
dl.skeleton = newSkeleton(stateDb, dl.peers, dropPeer, newBeaconBackfiller(dl, success))
|
dl.skeleton = newSkeleton(stateDb, dl.peers, dropPeer, newBeaconBackfiller(dl, success))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func newTester() *downloadTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: here we can inject a mock
|
// TODO: here we can inject a mock
|
||||||
tester.downloader = New(0, db, new(event.TypeMux), tester.chain, nil, tester.dropPeer, nil, whitelist.NewService())
|
tester.downloader = New(0, db, new(event.TypeMux), tester.chain, nil, tester.dropPeer, nil, whitelist.NewService(10))
|
||||||
return tester
|
return tester
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,17 @@ var (
|
||||||
|
|
||||||
// Checkpoint whitelist
|
// Checkpoint whitelist
|
||||||
type Service struct {
|
type Service struct {
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
checkpointWhitelist map[uint64]common.Hash // Checkpoint whitelist, populated by reaching out to heimdall
|
checkpointWhitelist map[uint64]common.Hash // Checkpoint whitelist, populated by reaching out to heimdall
|
||||||
checkpointOrder []uint64 // Checkpoint order, populated by reaching out to heimdall
|
checkpointOrder []uint64 // Checkpoint order, populated by reaching out to heimdall
|
||||||
maxCapacity uint
|
maxCapacity uint
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(maxCapacity uint) *Service {
|
func NewService(maxCapacity uint) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
checkpointWhitelist: make(map[uint64]common.Hash),
|
checkpointWhitelist: make(map[uint64]common.Hash),
|
||||||
checkpointOrder: []uint64{},
|
checkpointOrder: []uint64{},
|
||||||
maxCapacity: maxCapacity,
|
maxCapacity: maxCapacity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
32
eth/downloader/whitelist/service_test.go
Normal file
32
eth/downloader/whitelist/service_test.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package whitelist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"gotest.tools/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewMockService creates a new mock whitelist service
|
||||||
|
func NewMockService(maxCapacity uint) *Service {
|
||||||
|
return &Service{
|
||||||
|
checkpointWhitelist: make(map[uint64]common.Hash),
|
||||||
|
checkpointOrder: []uint64{},
|
||||||
|
maxCapacity: maxCapacity,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestWhitelistCheckpoint checks the checkpoint whitelist map queue mechanism
|
||||||
|
func TestWhitelistCheckpoint(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
s := NewMockService(10)
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
s.EnqueueCheckpointWhitelist(uint64(i), common.Hash{})
|
||||||
|
}
|
||||||
|
assert.Equal(t, len(s.GetCheckpointWhitelist()), 10, "expected 10 items in whitelist")
|
||||||
|
|
||||||
|
s.EnqueueCheckpointWhitelist(11, common.Hash{})
|
||||||
|
s.DequeueCheckpointWhitelist()
|
||||||
|
assert.Equal(t, len(s.GetCheckpointWhitelist()), 10, "expected 10 items in whitelist")
|
||||||
|
}
|
||||||
|
|
@ -39,7 +39,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"gotest.tools/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// testEthHandler is a mock event handler to listen for inbound network requests
|
// testEthHandler is a mock event handler to listen for inbound network requests
|
||||||
|
|
@ -747,24 +746,3 @@ func testBroadcastMalformedBlock(t *testing.T, protocol uint) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestWhitelistCheckpoint checks the checkpoint whitelist map queue mechanism
|
|
||||||
func TestWhitelistCheckpoint(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
testHandler := newTestHandler()
|
|
||||||
defer testHandler.close()
|
|
||||||
|
|
||||||
ethHandler := (*ethHandler)(testHandler.handler)
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
ethHandler.downloader.EnqueueCheckpointWhitelist(uint64(i), common.Hash{})
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, len(ethHandler.downloader.GetCheckpointWhitelist()), 10, "expected 10 items in whitelist")
|
|
||||||
|
|
||||||
ethHandler.downloader.EnqueueCheckpointWhitelist(11, common.Hash{})
|
|
||||||
ethHandler.downloader.DequeueCheckpointWhitelist()
|
|
||||||
|
|
||||||
assert.Equal(t, len(ethHandler.downloader.GetCheckpointWhitelist()), 10, "expected 10 items in whitelist")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue