2018-07-17 21:23:07 +00:00
|
|
|
package history_test
|
|
|
|
|
|
|
|
import (
|
2018-07-20 16:37:46 +00:00
|
|
|
"math/big"
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-07-20 16:37:46 +00:00
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/history"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Populating headers", func() {
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
var headerRepository *fakes.MockHeaderRepository
|
2018-07-17 21:23:07 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
headerRepository = fakes.NewMockHeaderRepository()
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
|
2018-07-24 16:38:49 +00:00
|
|
|
It("returns number of headers added", func() {
|
|
|
|
blockChain := fakes.NewMockBlockChain()
|
|
|
|
blockChain.SetLastBlock(big.NewInt(2))
|
|
|
|
headerRepository.SetMissingBlockNumbers([]int64{2})
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-08-14 21:59:41 +00:00
|
|
|
headersAdded, err := history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-07-24 16:38:49 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(headersAdded).To(Equal(1))
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("adds missing headers to the db", func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain := fakes.NewMockBlockChain()
|
|
|
|
blockChain.SetLastBlock(big.NewInt(2))
|
|
|
|
headerRepository.SetMissingBlockNumbers([]int64{2})
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-08-14 21:59:41 +00:00
|
|
|
_, err := history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-07-24 16:38:49 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-20 16:37:46 +00:00
|
|
|
headerRepository.AssertCreateOrUpdateHeaderCallCountAndPassedBlockNumbers(1, []int64{2})
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
})
|