forked from cerc-io/ipld-eth-server
05186634bd
- Only syncs block headers (excludes block bodies, transactions, receipts, and logs) - Modifies validation window to include the most recent block - Isolates validation window to the variable defined in the cmd directory (blocks have a separate variable defined in the block_repository for determining when to set a block as final)
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package history_test
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/inmemory"
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
|
"github.com/vulcanize/vulcanizedb/pkg/history"
|
|
)
|
|
|
|
var _ = Describe("Populating headers", func() {
|
|
|
|
var inMemory *inmemory.InMemory
|
|
var headerRepository *inmemory.HeaderRepository
|
|
|
|
BeforeEach(func() {
|
|
inMemory = inmemory.NewInMemory()
|
|
headerRepository = inmemory.NewHeaderRepository(inMemory)
|
|
})
|
|
|
|
Describe("When 1 missing header", func() {
|
|
|
|
It("returns number of headers added", func() {
|
|
headers := []core.Header{
|
|
{BlockNumber: 1},
|
|
{BlockNumber: 2},
|
|
}
|
|
blockChain := fakes.NewBlockChainWithHeaders(headers)
|
|
headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: 2})
|
|
|
|
headersAdded := history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
|
|
|
Expect(headersAdded).To(Equal(1))
|
|
})
|
|
})
|
|
|
|
It("adds missing headers to the db", func() {
|
|
headers := []core.Header{
|
|
{BlockNumber: 1},
|
|
{BlockNumber: 2},
|
|
}
|
|
blockChain := fakes.NewBlockChainWithHeaders(headers)
|
|
dbHeader, _ := headerRepository.GetHeader(1)
|
|
Expect(dbHeader.BlockNumber).To(BeZero())
|
|
|
|
history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
|
|
|
dbHeader, _ = headerRepository.GetHeader(1)
|
|
Expect(dbHeader.BlockNumber).To(Equal(int64(1)))
|
|
})
|
|
})
|