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-07-20 16:37:46 +00:00
|
|
|
package fakes
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MockHeaderRepository struct {
|
2018-07-24 16:38:49 +00:00
|
|
|
createOrUpdateHeaderCallCount int
|
2018-07-26 21:15:24 +00:00
|
|
|
createOrUpdateHeaderErr error
|
2018-07-24 16:38:49 +00:00
|
|
|
createOrUpdateHeaderPassedBlockNumbers []int64
|
|
|
|
createOrUpdateHeaderReturnID int64
|
2019-01-28 22:52:47 +00:00
|
|
|
getHeaderError error
|
|
|
|
getHeaderReturnBlockHash string
|
2018-07-24 16:38:49 +00:00
|
|
|
missingBlockNumbers []int64
|
2018-12-14 11:11:48 +00:00
|
|
|
headerExists bool
|
2019-01-28 22:52:47 +00:00
|
|
|
GetHeaderPassedBlockNumber int64
|
2018-07-20 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockHeaderRepository() *MockHeaderRepository {
|
|
|
|
return &MockHeaderRepository{}
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:38:49 +00:00
|
|
|
func (repository *MockHeaderRepository) SetCreateOrUpdateHeaderReturnID(id int64) {
|
|
|
|
repository.createOrUpdateHeaderReturnID = id
|
|
|
|
}
|
|
|
|
|
2018-07-26 21:15:24 +00:00
|
|
|
func (repository *MockHeaderRepository) SetCreateOrUpdateHeaderReturnErr(err error) {
|
|
|
|
repository.createOrUpdateHeaderErr = err
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockHeaderRepository) SetMissingBlockNumbers(blockNumbers []int64) {
|
|
|
|
repository.missingBlockNumbers = blockNumbers
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *MockHeaderRepository) CreateOrUpdateHeader(header core.Header) (int64, error) {
|
2018-07-24 16:38:49 +00:00
|
|
|
repository.createOrUpdateHeaderCallCount++
|
|
|
|
repository.createOrUpdateHeaderPassedBlockNumbers = append(repository.createOrUpdateHeaderPassedBlockNumbers, header.BlockNumber)
|
2018-07-26 21:15:24 +00:00
|
|
|
return repository.createOrUpdateHeaderReturnID, repository.createOrUpdateHeaderErr
|
2018-07-20 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:52:47 +00:00
|
|
|
func (repository *MockHeaderRepository) GetHeader(blockNumber int64) (core.Header, error) {
|
|
|
|
repository.GetHeaderPassedBlockNumber = blockNumber
|
|
|
|
return core.Header{BlockNumber: blockNumber, Hash: repository.getHeaderReturnBlockHash}, repository.getHeaderError
|
2018-07-20 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 09:58:41 +00:00
|
|
|
func (repository *MockHeaderRepository) MissingBlockNumbers(startingBlockNumber, endingBlockNumber int64, nodeID string) ([]int64, error) {
|
|
|
|
return repository.missingBlockNumbers, nil
|
2018-07-20 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:52:47 +00:00
|
|
|
func (repository *MockHeaderRepository) SetGetHeaderError(err error) {
|
|
|
|
repository.getHeaderError = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *MockHeaderRepository) SetGetHeaderReturnBlockHash(hash string) {
|
|
|
|
repository.getHeaderReturnBlockHash = hash
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
func (repository *MockHeaderRepository) AssertCreateOrUpdateHeaderCallCountAndPassedBlockNumbers(times int, blockNumbers []int64) {
|
2018-07-24 16:38:49 +00:00
|
|
|
Expect(repository.createOrUpdateHeaderCallCount).To(Equal(times))
|
|
|
|
Expect(repository.createOrUpdateHeaderPassedBlockNumbers).To(Equal(blockNumbers))
|
2018-07-20 16:37:46 +00:00
|
|
|
}
|