mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +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
|
||||
}
|
||||
dl := &Downloader{
|
||||
stateDB: stateDb,
|
||||
mux: mux,
|
||||
checkpoint: checkpoint,
|
||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
||||
peers: newPeerSet(),
|
||||
blockchain: chain,
|
||||
lightchain: lightchain,
|
||||
dropPeer: dropPeer,
|
||||
headerProcCh: make(chan *headerTask, 1),
|
||||
quitCh: make(chan struct{}),
|
||||
SnapSyncer: snap.NewSyncer(stateDb),
|
||||
stateSyncStart: make(chan *stateSync),
|
||||
ChainValidator: whitelistService,
|
||||
stateDB: stateDb,
|
||||
mux: mux,
|
||||
checkpoint: checkpoint,
|
||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
||||
peers: newPeerSet(),
|
||||
blockchain: chain,
|
||||
lightchain: lightchain,
|
||||
dropPeer: dropPeer,
|
||||
headerProcCh: make(chan *headerTask, 1),
|
||||
quitCh: make(chan struct{}),
|
||||
SnapSyncer: snap.NewSyncer(stateDb),
|
||||
stateSyncStart: make(chan *stateSync),
|
||||
ChainValidator: whitelistService,
|
||||
}
|
||||
dl.skeleton = newSkeleton(stateDb, dl.peers, dropPeer, newBeaconBackfiller(dl, success))
|
||||
|
||||
|
|
@ -792,7 +792,7 @@ func (d *Downloader) getFetchHeadersByNumber(p *peerConnection) func(number uint
|
|||
// the head links match), we do a binary search to find the common ancestor.
|
||||
func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) (uint64, error) {
|
||||
// Check the validity of chain to be downloaded
|
||||
// TODO: we can use a mock and
|
||||
// TODO: we can use a mock and
|
||||
if _, err := d.IsValidChain(remoteHeader, d.getFetchHeadersByNumber(p)); errors.Is(err, whitelist.ErrCheckpointMismatch) {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func newTester() *downloadTester {
|
|||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@ var (
|
|||
|
||||
// Checkpoint whitelist
|
||||
type Service struct {
|
||||
m sync.RWMutex
|
||||
m sync.RWMutex
|
||||
checkpointWhitelist map[uint64]common.Hash // Checkpoint whitelist, 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 {
|
||||
return &Service{
|
||||
checkpointWhitelist: make(map[uint64]common.Hash),
|
||||
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/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
// 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