Get head block number
- Allows us to refuse to sync past current head - Creates the opportunity to add a flag for syncing all blocks
This commit is contained in:
@@ -18,6 +18,8 @@ type MockEthereumDatabase struct {
|
||||
getBlockReceiptsPassedHash []byte
|
||||
getBlockReceiptsPassedNumber int64
|
||||
getBlockReceiptsReturnReceipts types.Receipts
|
||||
getHeadBlockNumberCalled bool
|
||||
getHeadBlockNumberReturnVal int64
|
||||
}
|
||||
|
||||
func NewMockEthereumDatabase() *MockEthereumDatabase {
|
||||
@@ -33,6 +35,8 @@ func NewMockEthereumDatabase() *MockEthereumDatabase {
|
||||
getBlockReceiptsPassedHash: nil,
|
||||
getBlockReceiptsPassedNumber: 0,
|
||||
getBlockReceiptsReturnReceipts: nil,
|
||||
getHeadBlockNumberCalled: false,
|
||||
getHeadBlockNumberReturnVal: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +72,11 @@ func (med *MockEthereumDatabase) GetBlockReceipts(blockHash []byte, blockNumber
|
||||
return med.getBlockReceiptsReturnReceipts
|
||||
}
|
||||
|
||||
func (med *MockEthereumDatabase) GetHeadBlockNumber() int64 {
|
||||
med.getHeadBlockNumberCalled = true
|
||||
return med.getHeadBlockNumberReturnVal
|
||||
}
|
||||
|
||||
func (med *MockEthereumDatabase) AssertGetBlockCalledWith(hash []byte, blockNumber int64) {
|
||||
Expect(med.getBlockCalled).To(BeTrue())
|
||||
Expect(med.getBlockPassedHash).To(Equal(hash))
|
||||
|
||||
@@ -8,32 +8,42 @@ import (
|
||||
|
||||
type MockLevelDatabaseReader struct {
|
||||
getBlockCalled bool
|
||||
getBlockReceiptsCalled bool
|
||||
getCanonicalHashCalled bool
|
||||
passedHash common.Hash
|
||||
getCanonicalHashPassedNumber uint64
|
||||
getBlockNumberCalled bool
|
||||
getBlockNumberPassedHash common.Hash
|
||||
getBlockPassedHash common.Hash
|
||||
getBlockPassedNumber uint64
|
||||
getBlockReceiptsCalled bool
|
||||
getBlockReceiptsPassedHash common.Hash
|
||||
getBlockReceiptsPassedNumber uint64
|
||||
getCanonicalHashCalled bool
|
||||
getCanonicalHashPassedNumber uint64
|
||||
getCanonicalHashReturnHash common.Hash
|
||||
getHeadBlockHashCalled bool
|
||||
getHeadBlockHashReturnHash common.Hash
|
||||
passedHash common.Hash
|
||||
returnBlock *types.Block
|
||||
returnHash common.Hash
|
||||
returnBlockNumber uint64
|
||||
returnReceipts types.Receipts
|
||||
}
|
||||
|
||||
func NewMockLevelDatabaseReader() *MockLevelDatabaseReader {
|
||||
return &MockLevelDatabaseReader{
|
||||
getBlockCalled: false,
|
||||
getBlockReceiptsCalled: false,
|
||||
getCanonicalHashCalled: false,
|
||||
passedHash: common.Hash{},
|
||||
getCanonicalHashPassedNumber: 0,
|
||||
getBlockNumberCalled: false,
|
||||
getBlockNumberPassedHash: common.Hash{},
|
||||
getBlockPassedHash: common.Hash{},
|
||||
getBlockPassedNumber: 0,
|
||||
getBlockReceiptsCalled: false,
|
||||
getBlockReceiptsPassedHash: common.Hash{},
|
||||
getBlockReceiptsPassedNumber: 0,
|
||||
getCanonicalHashCalled: false,
|
||||
getCanonicalHashPassedNumber: 0,
|
||||
getCanonicalHashReturnHash: common.Hash{},
|
||||
getHeadBlockHashCalled: false,
|
||||
getHeadBlockHashReturnHash: common.Hash{},
|
||||
passedHash: common.Hash{},
|
||||
returnBlock: nil,
|
||||
returnHash: common.Hash{},
|
||||
returnBlockNumber: 0,
|
||||
returnReceipts: nil,
|
||||
}
|
||||
}
|
||||
@@ -42,20 +52,22 @@ func (mldr *MockLevelDatabaseReader) SetReturnBlock(block *types.Block) {
|
||||
mldr.returnBlock = block
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) SetReturnHash(hash common.Hash) {
|
||||
mldr.returnHash = hash
|
||||
func (mldr *MockLevelDatabaseReader) SetReturnBlockNumber(n uint64) {
|
||||
mldr.returnBlockNumber = n
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) SetGetCanonicalHashReturnHash(hash common.Hash) {
|
||||
mldr.getCanonicalHashReturnHash = hash
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) SetHeadBlockHashReturnHash(hash common.Hash) {
|
||||
mldr.getHeadBlockHashReturnHash = hash
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) SetReturnReceipts(receipts types.Receipts) {
|
||||
mldr.returnReceipts = receipts
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) GetCanonicalHash(number uint64) common.Hash {
|
||||
mldr.getCanonicalHashCalled = true
|
||||
mldr.getCanonicalHashPassedNumber = number
|
||||
return mldr.returnHash
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) GetBlock(hash common.Hash, number uint64) *types.Block {
|
||||
mldr.getBlockCalled = true
|
||||
mldr.getBlockPassedHash = hash
|
||||
@@ -70,9 +82,21 @@ func (mldr *MockLevelDatabaseReader) GetBlockReceipts(hash common.Hash, number u
|
||||
return mldr.returnReceipts
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetCanonicalHashCalledWith(number uint64) {
|
||||
Expect(mldr.getCanonicalHashCalled).To(BeTrue())
|
||||
Expect(mldr.getCanonicalHashPassedNumber).To(Equal(number))
|
||||
func (mldr *MockLevelDatabaseReader) GetBlockNumber(hash common.Hash) uint64 {
|
||||
mldr.getBlockNumberCalled = true
|
||||
mldr.getBlockNumberPassedHash = hash
|
||||
return mldr.returnBlockNumber
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) GetCanonicalHash(number uint64) common.Hash {
|
||||
mldr.getCanonicalHashCalled = true
|
||||
mldr.getCanonicalHashPassedNumber = number
|
||||
return mldr.getCanonicalHashReturnHash
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) GetHeadBlockHash() common.Hash {
|
||||
mldr.getHeadBlockHashCalled = true
|
||||
return mldr.getHeadBlockHashReturnHash
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetBlockCalledWith(hash common.Hash, number uint64) {
|
||||
@@ -81,8 +105,22 @@ func (mldr *MockLevelDatabaseReader) AssertGetBlockCalledWith(hash common.Hash,
|
||||
Expect(mldr.getBlockPassedNumber).To(Equal(number))
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetBlockNumberCalledWith(hash common.Hash) {
|
||||
Expect(mldr.getBlockNumberCalled).To(BeTrue())
|
||||
Expect(mldr.getBlockNumberPassedHash).To(Equal(hash))
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetBlockReceiptsCalledWith(hash common.Hash, number uint64) {
|
||||
Expect(mldr.getBlockReceiptsCalled).To(BeTrue())
|
||||
Expect(mldr.getBlockReceiptsPassedHash).To(Equal(hash))
|
||||
Expect(mldr.getBlockReceiptsPassedNumber).To(Equal(number))
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetCanonicalHashCalledWith(number uint64) {
|
||||
Expect(mldr.getCanonicalHashCalled).To(BeTrue())
|
||||
Expect(mldr.getCanonicalHashPassedNumber).To(Equal(number))
|
||||
}
|
||||
|
||||
func (mldr *MockLevelDatabaseReader) AssertGetHeadBlockHashCalled() {
|
||||
Expect(mldr.getHeadBlockHashCalled).To(BeTrue())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user