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-17 21:23:07 +00:00
|
|
|
package history_test
|
|
|
|
|
|
|
|
import (
|
2019-01-11 09:58:41 +00:00
|
|
|
"errors"
|
2019-01-23 06:37:26 +00:00
|
|
|
"math/big"
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
2019-01-11 09:58:41 +00:00
|
|
|
. "github.com/onsi/gomega"
|
2019-01-23 06:37:26 +00:00
|
|
|
|
2020-01-29 19:00:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/fakes"
|
2020-01-30 22:35:31 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/history"
|
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
|
|
|
})
|