forked from cerc-io/ipld-eth-server
Add tests for pkg/geth/blockchain
- inject dependencies instead of initializing them in the constructor
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
var _ = Describe("Blocks validator", func() {
|
||||
|
||||
It("calls create or update for all blocks within the window", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 4},
|
||||
{Number: 5},
|
||||
{Number: 6},
|
||||
@@ -31,7 +31,7 @@ var _ = Describe("Blocks validator", func() {
|
||||
})
|
||||
|
||||
It("returns the number of largest block", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 1},
|
||||
{Number: 2},
|
||||
{Number: 3},
|
||||
|
||||
@@ -27,7 +27,7 @@ var _ = Describe("Header validator", func() {
|
||||
Hash: newHash,
|
||||
}
|
||||
headers := []core.Header{newHeader}
|
||||
blockChain := fakes.NewBlockChainWithHeaders(headers)
|
||||
blockChain := fakes.NewMockBlockChainWithHeaders(headers)
|
||||
validator := history.NewHeaderValidator(blockChain, headerRepository, 1)
|
||||
|
||||
validator.ValidateHeaders()
|
||||
|
||||
@@ -25,7 +25,7 @@ var _ = Describe("Populating blocks", func() {
|
||||
{Number: 1},
|
||||
{Number: 2},
|
||||
}
|
||||
blockchain := fakes.NewBlockchainWithBlocks(blocks)
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks(blocks)
|
||||
|
||||
blockRepository.CreateOrUpdateBlock(core.Block{Number: 2})
|
||||
|
||||
@@ -37,7 +37,7 @@ var _ = Describe("Populating blocks", func() {
|
||||
})
|
||||
|
||||
It("fills in the three missing blocks (Numbers: 5,8,10)", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 4},
|
||||
{Number: 5},
|
||||
{Number: 6},
|
||||
@@ -76,7 +76,7 @@ var _ = Describe("Populating blocks", func() {
|
||||
})
|
||||
|
||||
It("returns the number of blocks created", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 4},
|
||||
{Number: 5},
|
||||
{Number: 6},
|
||||
@@ -90,7 +90,7 @@ var _ = Describe("Populating blocks", func() {
|
||||
})
|
||||
|
||||
It("updates the repository with a range of blocks w/in the range ", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 1},
|
||||
{Number: 2},
|
||||
{Number: 3},
|
||||
@@ -104,7 +104,7 @@ var _ = Describe("Populating blocks", func() {
|
||||
})
|
||||
|
||||
It("does not call repository create block when there is an error", func() {
|
||||
blockchain := fakes.NewBlockchain(errors.New("error getting block"))
|
||||
blockchain := fakes.NewMockBlockChain(errors.New("error getting block"))
|
||||
blocks := history.MakeRange(1, 10)
|
||||
history.RetrieveAndUpdateBlocks(blockchain, blockRepository, blocks)
|
||||
Expect(blockRepository.BlockCount()).To(Equal(0))
|
||||
|
||||
@@ -26,7 +26,7 @@ var _ = Describe("Populating headers", func() {
|
||||
{BlockNumber: 1},
|
||||
{BlockNumber: 2},
|
||||
}
|
||||
blockChain := fakes.NewBlockChainWithHeaders(headers)
|
||||
blockChain := fakes.NewMockBlockChainWithHeaders(headers)
|
||||
headerRepository.CreateOrUpdateHeader(core.Header{BlockNumber: 2})
|
||||
|
||||
headersAdded := history.PopulateMissingHeaders(blockChain, headerRepository, 1)
|
||||
@@ -40,7 +40,7 @@ var _ = Describe("Populating headers", func() {
|
||||
{BlockNumber: 1},
|
||||
{BlockNumber: 2},
|
||||
}
|
||||
blockChain := fakes.NewBlockChainWithHeaders(headers)
|
||||
blockChain := fakes.NewMockBlockChainWithHeaders(headers)
|
||||
dbHeader, _ := headerRepository.GetHeader(1)
|
||||
Expect(dbHeader.BlockNumber).To(BeZero())
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
var _ = Describe("", func() {
|
||||
It("creates a ValidationWindow equal to (HEAD-windowSize, HEAD)", func() {
|
||||
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
||||
blockchain := fakes.NewMockBlockChainWithBlocks([]core.Block{
|
||||
{Number: 1},
|
||||
{Number: 2},
|
||||
{Number: 3},
|
||||
|
||||
Reference in New Issue
Block a user