forked from cerc-io/ipld-eth-server
Consolidate test doubles
- Migrate various mocks of core namespaces to shared version in `fakes` pkg - Err on the side of making test doubles less sophisticated - Don't pull over mocks of namespaces that are only used in example code
This commit is contained in:
committed by
Ian Norden
parent
5fe6394406
commit
ba071ef13f
@@ -4,39 +4,29 @@ 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"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var _ = Describe("Blocks validator", func() {
|
||||
|
||||
It("calls create or update for all blocks within the window", func() {
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 4},
|
||||
{Number: 5},
|
||||
{Number: 6},
|
||||
{Number: 7},
|
||||
})
|
||||
inMemoryDB := inmemory.NewInMemory()
|
||||
blocksRepository := &inmemory.BlockRepository{InMemory: inMemoryDB}
|
||||
validator := history.NewBlockValidator(blockchain, blocksRepository, 2)
|
||||
blockChain := fakes.NewMockBlockChain()
|
||||
blockChain.SetLastBlock(big.NewInt(7))
|
||||
blocksRepository := fakes.NewMockBlockRepository()
|
||||
validator := history.NewBlockValidator(blockChain, blocksRepository, 2)
|
||||
|
||||
window := validator.ValidateBlocks()
|
||||
|
||||
Expect(window).To(Equal(history.ValidationWindow{LowerBound: 5, UpperBound: 7}))
|
||||
Expect(blocksRepository.BlockCount()).To(Equal(3))
|
||||
Expect(blocksRepository.CreateOrUpdateBlockCallCount).To(Equal(3))
|
||||
blocksRepository.AssertCreateOrUpdateBlockCallCountEquals(3)
|
||||
})
|
||||
|
||||
It("returns the number of largest block", func() {
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 1},
|
||||
{Number: 2},
|
||||
{Number: 3},
|
||||
})
|
||||
maxBlockNumber := blockchain.LastBlock()
|
||||
blockChain := fakes.NewMockBlockChain()
|
||||
blockChain.SetLastBlock(big.NewInt(3))
|
||||
maxBlockNumber := blockChain.LastBlock()
|
||||
|
||||
Expect(maxBlockNumber.Int64()).To(Equal(int64(3)))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user