ipld-eth-server/pkg/history/header_validator_test.go
Rob Mulholand 1355271011 Add light sync command
- 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)
2018-07-18 16:34:12 -05:00

40 lines
1.2 KiB
Go

package history_test
import (
"github.com/ethereum/go-ethereum/common"
. "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("Header validator", func() {
It("replaces headers in the validation window that have changed", func() {
blockNumber := int64(10)
oldHash := common.HexToHash("0x0987654321").Hex()
oldHeader := core.Header{
BlockNumber: blockNumber,
Hash: oldHash,
}
inMemory := inmemory.NewInMemory()
headerRepository := inmemory.NewHeaderRepository(inMemory)
headerRepository.CreateOrUpdateHeader(oldHeader)
newHash := common.HexToHash("0x123456789").Hex()
newHeader := core.Header{
BlockNumber: blockNumber,
Hash: newHash,
}
headers := []core.Header{newHeader}
blockChain := fakes.NewBlockChainWithHeaders(headers)
validator := history.NewHeaderValidator(blockChain, headerRepository, 1)
validator.ValidateHeaders()
dbHeader, _ := headerRepository.GetHeader(blockNumber)
Expect(dbHeader.Hash).NotTo(Equal(oldHash))
Expect(dbHeader.Hash).To(Equal(newHash))
})
})