mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
fix tests and format
This commit is contained in:
parent
aa3004b083
commit
a6ec55bb31
5 changed files with 50 additions and 40 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
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