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
|
|
|
})
|
|
|
|
|
|
|
|
Describe("When 1 missing header", func() {
|
|
|
|
|
|
|
|
It("returns number of headers added", 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
|
|
|
|
|
|
|
headersAdded := history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
|
|
|
|
|
|
|
Expect(headersAdded).To(Equal(1))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
headerRepository.AssertCreateOrUpdateHeaderCallCountAndPassedBlockNumbers(1, []int64{2})
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
})
|