2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-05-02 16:17:02 +00:00
|
|
|
package fakes
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MockBlockRepository struct {
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockCallCount int
|
2018-05-07 15:41:02 +00:00
|
|
|
createOrUpdateBlockCalled bool
|
|
|
|
createOrUpdateBlockPassedBlock core.Block
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockPassedBlockNumbers []int64
|
2018-05-07 15:41:02 +00:00
|
|
|
createOrUpdateBlockReturnErr error
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockReturnInt int64
|
2018-05-07 15:41:02 +00:00
|
|
|
missingBlockNumbersCalled bool
|
|
|
|
missingBlockNumbersPassedEndingBlockNumber int64
|
|
|
|
missingBlockNumbersPassedNodeId string
|
2018-07-20 16:37:46 +00:00
|
|
|
missingBlockNumbersPassedStartingBlockNumber int64
|
2018-05-07 15:41:02 +00:00
|
|
|
missingBlockNumbersReturnArray []int64
|
|
|
|
setBlockStatusCalled bool
|
|
|
|
setBlockStatusPassedChainHead int64
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockBlockRepository() *MockBlockRepository {
|
|
|
|
return &MockBlockRepository{
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockCallCount: 0,
|
2018-05-07 15:41:02 +00:00
|
|
|
createOrUpdateBlockCalled: false,
|
|
|
|
createOrUpdateBlockPassedBlock: core.Block{},
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockPassedBlockNumbers: nil,
|
2018-05-07 15:41:02 +00:00
|
|
|
createOrUpdateBlockReturnErr: nil,
|
2018-07-20 16:37:46 +00:00
|
|
|
createOrUpdateBlockReturnInt: 0,
|
2018-05-07 15:41:02 +00:00
|
|
|
missingBlockNumbersCalled: false,
|
|
|
|
missingBlockNumbersPassedEndingBlockNumber: 0,
|
|
|
|
missingBlockNumbersPassedNodeId: "",
|
2018-07-20 16:37:46 +00:00
|
|
|
missingBlockNumbersPassedStartingBlockNumber: 0,
|
2018-05-07 15:41:02 +00:00
|
|
|
missingBlockNumbersReturnArray: nil,
|
|
|
|
setBlockStatusCalled: false,
|
|
|
|
setBlockStatusPassedChainHead: 0,
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) SetCreateOrUpdateBlockReturnVals(i int64, err error) {
|
|
|
|
repository.createOrUpdateBlockReturnInt = i
|
|
|
|
repository.createOrUpdateBlockReturnErr = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *MockBlockRepository) SetMissingBlockNumbersReturnArray(returnArray []int64) {
|
|
|
|
repository.missingBlockNumbersReturnArray = returnArray
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *MockBlockRepository) CreateOrUpdateBlock(block core.Block) (int64, error) {
|
|
|
|
repository.createOrUpdateBlockCallCount++
|
|
|
|
repository.createOrUpdateBlockCalled = true
|
|
|
|
repository.createOrUpdateBlockPassedBlock = block
|
|
|
|
repository.createOrUpdateBlockPassedBlockNumbers = append(repository.createOrUpdateBlockPassedBlockNumbers, block.Number)
|
|
|
|
return repository.createOrUpdateBlockReturnInt, repository.createOrUpdateBlockReturnErr
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) GetBlock(blockNumber int64) (core.Block, error) {
|
|
|
|
return core.Block{Number: blockNumber}, nil
|
2018-05-07 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) MissingBlockNumbers(startingBlockNumber int64, endingBlockNumber int64, nodeId string) []int64 {
|
|
|
|
repository.missingBlockNumbersCalled = true
|
|
|
|
repository.missingBlockNumbersPassedStartingBlockNumber = startingBlockNumber
|
|
|
|
repository.missingBlockNumbersPassedEndingBlockNumber = endingBlockNumber
|
|
|
|
repository.missingBlockNumbersPassedNodeId = nodeId
|
|
|
|
return repository.missingBlockNumbersReturnArray
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 15:04:12 +00:00
|
|
|
func (repository *MockBlockRepository) SetBlocksStatus(chainHead int64) error {
|
2018-07-20 16:37:46 +00:00
|
|
|
repository.setBlockStatusCalled = true
|
|
|
|
repository.setBlockStatusPassedChainHead = chainHead
|
2019-02-14 15:04:12 +00:00
|
|
|
return nil
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCallCountEquals(times int) {
|
|
|
|
Expect(repository.createOrUpdateBlockCallCount).To(Equal(times))
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(times int, blockNumbers []int64) {
|
|
|
|
Expect(repository.createOrUpdateBlockCallCount).To(Equal(times))
|
|
|
|
Expect(repository.createOrUpdateBlockPassedBlockNumbers).To(Equal(blockNumbers))
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) AssertCreateOrUpdateBlockCalledWith(block core.Block) {
|
|
|
|
Expect(repository.createOrUpdateBlockCalled).To(BeTrue())
|
|
|
|
Expect(repository.createOrUpdateBlockPassedBlock).To(Equal(block))
|
2018-05-02 16:17:02 +00:00
|
|
|
}
|
2018-05-07 15:41:02 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) AssertMissingBlockNumbersCalledWith(startingBlockNumber int64, endingBlockNumber int64, nodeId string) {
|
|
|
|
Expect(repository.missingBlockNumbersCalled).To(BeTrue())
|
|
|
|
Expect(repository.missingBlockNumbersPassedStartingBlockNumber).To(Equal(startingBlockNumber))
|
|
|
|
Expect(repository.missingBlockNumbersPassedEndingBlockNumber).To(Equal(endingBlockNumber))
|
|
|
|
Expect(repository.missingBlockNumbersPassedNodeId).To(Equal(nodeId))
|
2018-05-07 15:41:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockBlockRepository) AssertSetBlockStatusCalledWith(chainHead int64) {
|
|
|
|
Expect(repository.setBlockStatusCalled).To(BeTrue())
|
|
|
|
Expect(repository.setBlockStatusPassedChainHead).To(Equal(chainHead))
|
2018-05-07 15:41:02 +00:00
|
|
|
}
|