605b0a96ae
* Add graphql server * Update Makefile * Update log_filters constraint * Add GetLogFilter to repo * Update travis (use Makefile, go fmt, go vet) * Add logFilter schema and resolvers * Add GetWatchedEvent to watched_events_repo * Add watchedEventLog schema and resolvers
100 lines
2.9 KiB
Go
100 lines
2.9 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/fakes"
|
|
"github.com/vulcanize/vulcanizedb/pkg/history"
|
|
"github.com/vulcanize/vulcanizedb/pkg/repositories/inmemory"
|
|
)
|
|
|
|
var _ = Describe("Populating blocks", func() {
|
|
|
|
It("fills in the only missing block (Number 1)", func() {
|
|
blocks := []core.Block{
|
|
{Number: 1},
|
|
{Number: 2},
|
|
}
|
|
blockchain := fakes.NewBlockchainWithBlocks(blocks)
|
|
repository := inmemory.NewInMemory()
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 2})
|
|
|
|
blocksAdded := history.PopulateMissingBlocks(blockchain, repository, 1)
|
|
_, err := repository.GetBlock(1)
|
|
|
|
Expect(blocksAdded).To(Equal(1))
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("fills in the three missing blocks (Numbers: 5,8,10)", func() {
|
|
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
|
{Number: 4},
|
|
{Number: 5},
|
|
{Number: 6},
|
|
{Number: 7},
|
|
{Number: 8},
|
|
{Number: 9},
|
|
{Number: 10},
|
|
{Number: 11},
|
|
{Number: 12},
|
|
{Number: 13},
|
|
})
|
|
repository := inmemory.NewInMemory()
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 1})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 2})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 3})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 6})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 7})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 9})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 11})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 12})
|
|
|
|
blocksAdded := history.PopulateMissingBlocks(blockchain, repository, 5)
|
|
|
|
Expect(blocksAdded).To(Equal(3))
|
|
Expect(repository.BlockCount()).To(Equal(11))
|
|
_, err := repository.GetBlock(4)
|
|
Expect(err).To(HaveOccurred())
|
|
_, err = repository.GetBlock(5)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
_, err = repository.GetBlock(8)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
_, err = repository.GetBlock(10)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
_, err = repository.GetBlock(13)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("returns the number of blocks created", func() {
|
|
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
|
{Number: 4},
|
|
{Number: 5},
|
|
{Number: 6},
|
|
})
|
|
repository := inmemory.NewInMemory()
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 3})
|
|
repository.CreateOrUpdateBlock(core.Block{Number: 6})
|
|
|
|
numberOfBlocksCreated := history.PopulateMissingBlocks(blockchain, repository, 3)
|
|
|
|
Expect(numberOfBlocksCreated).To(Equal(2))
|
|
})
|
|
|
|
It("updates the repository with a range of blocks w/in the range ", func() {
|
|
blockchain := fakes.NewBlockchainWithBlocks([]core.Block{
|
|
{Number: 1},
|
|
{Number: 2},
|
|
{Number: 3},
|
|
{Number: 4},
|
|
{Number: 5},
|
|
})
|
|
repository := inmemory.NewInMemory()
|
|
|
|
history.RetrieveAndUpdateBlocks(blockchain, repository, history.MakeRange(2, 5))
|
|
Expect(repository.BlockCount()).To(Equal(3))
|
|
Expect(repository.CreateOrUpdateBlockCallCount).To(Equal(3))
|
|
})
|
|
|
|
})
|