2018-07-17 21:23:07 +00:00
|
|
|
package history_test
|
|
|
|
|
|
|
|
import (
|
2019-01-11 09:58:41 +00:00
|
|
|
"errors"
|
2018-07-17 21:23:07 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
2019-01-11 09:58:41 +00:00
|
|
|
. "github.com/onsi/gomega"
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/history"
|
2018-07-20 16:37:46 +00:00
|
|
|
"math/big"
|
2018-07-17 21:23:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Header validator", func() {
|
2019-01-11 09:58:41 +00:00
|
|
|
var (
|
|
|
|
headerRepository *fakes.MockHeaderRepository
|
|
|
|
blockChain *fakes.MockBlockChain
|
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
headerRepository = fakes.NewMockHeaderRepository()
|
|
|
|
blockChain = fakes.NewMockBlockChain()
|
|
|
|
})
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
It("attempts to create every header in the validation window", func() {
|
|
|
|
headerRepository.SetMissingBlockNumbers([]int64{})
|
|
|
|
blockChain.SetLastBlock(big.NewInt(3))
|
2018-08-14 21:59:41 +00:00
|
|
|
validator := history.NewHeaderValidator(blockChain, headerRepository, 2)
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2019-01-11 09:58:41 +00:00
|
|
|
_, err := validator.ValidateHeaders()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
headerRepository.AssertCreateOrUpdateHeaderCallCountAndPassedBlockNumbers(3, []int64{1, 2, 3})
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
2019-01-11 09:58:41 +00:00
|
|
|
|
|
|
|
It("propagates header repository errors", func() {
|
|
|
|
blockChain.SetLastBlock(big.NewInt(3))
|
|
|
|
headerRepositoryError := errors.New("CreateOrUpdate")
|
|
|
|
headerRepository.SetCreateOrUpdateHeaderReturnErr(headerRepositoryError)
|
|
|
|
validator := history.NewHeaderValidator(blockChain, headerRepository, 2)
|
|
|
|
|
|
|
|
_, err := validator.ValidateHeaders()
|
|
|
|
Expect(err).To(MatchError(headerRepositoryError))
|
|
|
|
})
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|