forked from cerc-io/ipld-eth-server
Use transformer factory for Drip drip
This commit is contained in:
parent
f3a82e6ba1
commit
1b680d2a4b
@ -16,10 +16,11 @@ package drip_drip
|
||||
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var DripDripConfig = shared.TransformerConfig{
|
||||
var DripDripConfig = shared.SingleTransformerConfig{
|
||||
TransformerName: shared.DripDripLabel,
|
||||
ContractAddresses: []string{shared.DripContractAddress},
|
||||
ContractAbi: shared.DripABI,
|
||||
Topics: []string{shared.DripDripSignature},
|
||||
Topic: shared.DripDripSignature,
|
||||
StartingBlockNumber: 0,
|
||||
EndingBlockNumber: 10000000,
|
||||
}
|
||||
|
@ -21,14 +21,10 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
type Converter interface {
|
||||
ToModels(ethLogs []types.Log) ([]DripDripModel, error)
|
||||
}
|
||||
|
||||
type DripDripConverter struct{}
|
||||
|
||||
func (DripDripConverter) ToModels(ethLogs []types.Log) ([]DripDripModel, error) {
|
||||
var models []DripDripModel
|
||||
func (DripDripConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
err := verifyLog(ethLog)
|
||||
if err != nil {
|
||||
|
@ -39,6 +39,6 @@ var _ = Describe("Drip drip converter", func() {
|
||||
model, err := converter.ToModels([]types.Log{test_data.EthDripDripLog})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(model).To(Equal([]drip_drip.DripDripModel{test_data.DripDripModel}))
|
||||
Expect(model).To(Equal([]interface{}{test_data.DripDripModel}))
|
||||
})
|
||||
})
|
||||
|
@ -15,34 +15,31 @@
|
||||
package drip_drip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(headerID int64, models []DripDripModel) error
|
||||
MarkHeaderChecked(headerID int64) error
|
||||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
|
||||
}
|
||||
|
||||
type DripDripRepository struct {
|
||||
db *postgres.DB
|
||||
}
|
||||
|
||||
func NewDripDripRepository(db *postgres.DB) DripDripRepository {
|
||||
return DripDripRepository{db: db}
|
||||
}
|
||||
|
||||
func (repository DripDripRepository) Create(headerID int64, models []DripDripModel) error {
|
||||
func (repository DripDripRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, model := range models {
|
||||
dripDrip, ok := model.(DripDripModel)
|
||||
if !ok {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("model of type %T, not %T", model, DripDripModel{})
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5)`,
|
||||
headerID, model.Ilk, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
headerID, dripDrip.Ilk, dripDrip.LogIndex, dripDrip.TransactionIndex, dripDrip.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
@ -84,3 +81,7 @@ func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingB
|
||||
)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (repository *DripDripRepository) SetDB(db *postgres.DB) {
|
||||
repository.db = db
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package drip_drip_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"math/rand"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -33,7 +34,7 @@ import (
|
||||
var _ = Describe("Drip drip repository", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
dripDripRepository drip_drip.Repository
|
||||
dripDripRepository drip_drip.DripDripRepository
|
||||
err error
|
||||
headerRepository datastore.HeaderRepository
|
||||
)
|
||||
@ -42,7 +43,8 @@ var _ = Describe("Drip drip repository", func() {
|
||||
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
dripDripRepository = drip_drip.NewDripDripRepository(db)
|
||||
dripDripRepository = drip_drip.DripDripRepository{}
|
||||
dripDripRepository.SetDB(db)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -52,11 +54,12 @@ var _ = Describe("Drip drip repository", func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripDripRepository.Create(headerID, []drip_drip.DripDripModel{test_data.DripDripModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("adds a drip drip event", func() {
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var dbDripDrip drip_drip.DripDripModel
|
||||
err = db.Get(&dbDripDrip, `SELECT ilk, log_idx, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -67,6 +70,22 @@ var _ = Describe("Drip drip repository", func() {
|
||||
})
|
||||
|
||||
It("marks header as checked for logs", func() {
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT drip_drip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(headerChecked).To(BeTrue())
|
||||
})
|
||||
|
||||
It("updates the header to checked if checked headers row already exists", func() {
|
||||
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT drip_drip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -74,13 +93,19 @@ var _ = Describe("Drip drip repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate drip drip events", func() {
|
||||
err = dripDripRepository.Create(headerID, []drip_drip.DripDripModel{test_data.DripDripModel})
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
})
|
||||
|
||||
It("removes drip drip if corresponding header is deleted", func() {
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -89,6 +114,12 @@ var _ = Describe("Drip drip repository", func() {
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||
})
|
||||
|
||||
It("returns an error if model is of wrong type", func() {
|
||||
err = dripDripRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("model of type"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("MarkHeaderChecked", func() {
|
||||
@ -129,7 +160,7 @@ var _ = Describe("Drip drip repository", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
startingBlock = GinkgoRandomSeed()
|
||||
startingBlock = rand.Int63()
|
||||
dripDripBlock = startingBlock + 1
|
||||
endingBlock = startingBlock + 2
|
||||
|
||||
@ -178,7 +209,8 @@ var _ = Describe("Drip drip repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
dripDripRepositoryTwo := drip_drip.NewDripDripRepository(dbTwo)
|
||||
dripDripRepositoryTwo := drip_drip.DripDripRepository{}
|
||||
dripDripRepositoryTwo.SetDB(dbTwo)
|
||||
|
||||
nodeOneMissingHeaders, err := dripDripRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
@ -1,78 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package drip_drip
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type DripDripTransformerInitializer struct {
|
||||
Config shared.TransformerConfig
|
||||
}
|
||||
|
||||
func (initializer DripDripTransformerInitializer) NewDripDripTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
|
||||
converter := DripDripConverter{}
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
repository := NewDripDripRepository(db)
|
||||
return DripDripTransformer{
|
||||
Config: initializer.Config,
|
||||
Converter: converter,
|
||||
Fetcher: fetcher,
|
||||
Repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
type DripDripTransformer struct {
|
||||
Config shared.TransformerConfig
|
||||
Converter Converter
|
||||
Fetcher shared.LogFetcher
|
||||
Repository Repository
|
||||
}
|
||||
|
||||
func (transformer DripDripTransformer) Execute() error {
|
||||
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("Fetching drip drip event logs for %d headers \n", len(missingHeaders))
|
||||
for _, header := range missingHeaders {
|
||||
topics := [][]common.Hash{{common.HexToHash(shared.DripDripSignature)}}
|
||||
matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topics, header.BlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(matchingLogs) < 1 {
|
||||
err = transformer.Repository.MarkHeaderChecked(header.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
models, err := transformer.Converter.ToModels(matchingLogs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = transformer.Repository.Create(header.Id, models)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -19,6 +19,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"math/rand"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
@ -26,19 +28,39 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
|
||||
drip_drip_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/drip_drip"
|
||||
)
|
||||
|
||||
var _ = Describe("Drip drip transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Config: drip_drip.DripDripConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &drip_drip_mocks.MockDripDripConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var (
|
||||
config = drip_drip.DripDripConfig
|
||||
converter mocks.MockLogNoteConverter
|
||||
repository mocks.MockRepository
|
||||
fetcher mocks.MockLogFetcher
|
||||
transformer shared.Transformer
|
||||
headerOne core.Header
|
||||
headerTwo core.Header
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
converter = mocks.MockLogNoteConverter{}
|
||||
repository = mocks.MockRepository{}
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
|
||||
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
|
||||
transformer = factories.LogNoteTransformer{
|
||||
Config: config,
|
||||
Fetcher: &fetcher,
|
||||
Converter: &converter,
|
||||
Repository: &repository,
|
||||
}.NewLogNoteTransformer(nil, nil)
|
||||
})
|
||||
|
||||
It("sets the blockchain and database", func() {
|
||||
Expect(fetcher.SetBcCalled).To(BeTrue())
|
||||
Expect(repository.SetDbCalled).To(BeTrue())
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -47,13 +69,7 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &drip_drip_mocks.MockDripDripConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeadersError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -62,34 +78,19 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Config: drip_drip.DripDripConfig,
|
||||
Fetcher: fetcher,
|
||||
Converter: &drip_drip_mocks.MockDripDripConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_drip.DripDripConfig.ContractAddresses, drip_drip.DripDripConfig.ContractAddresses}))
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripDripSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &drip_drip_mocks.MockDripDripConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -98,34 +99,17 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
mockRepository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
headerID := int64(123)
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
||||
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||
})
|
||||
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
mockConverter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
mockRepository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -134,16 +118,8 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -152,17 +128,9 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -171,37 +139,21 @@ var _ = Describe("Drip drip transformer", func() {
|
||||
})
|
||||
|
||||
It("persists drip drip model", func() {
|
||||
converter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
converter.SetReturnModels([]interface{}{test_data.DripDripModel})
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]drip_drip.DripDripModel{test_data.DripDripModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.DripDripModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &drip_drip_mocks.MockDripDripConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
|
||||
repository := &drip_drip_mocks.MockDripDripRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := drip_drip.DripDripTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
@ -17,6 +17,8 @@ package integration_tests
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
@ -40,8 +42,14 @@ var _ = Describe("DripDrip Transformer", func() {
|
||||
err = persistHeader(db, blockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
initializer := drip_drip.DripDripTransformerInitializer{Config: config}
|
||||
transformer := initializer.NewDripDripTransformer(db, blockchain)
|
||||
initializer := factories.LogNoteTransformer{
|
||||
Config: drip_drip.DripDripConfig,
|
||||
Converter: &drip_drip.DripDripConverter{},
|
||||
Repository: &drip_drip.DripDripRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}
|
||||
transformer := initializer.NewLogNoteTransformer(db, blockchain)
|
||||
|
||||
err = transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package drip_drip
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
)
|
||||
|
||||
type MockDripDripConverter struct {
|
||||
Err error
|
||||
PassedLogs []types.Log
|
||||
}
|
||||
|
||||
func (converter *MockDripDripConverter) ToModels(ethLogs []types.Log) ([]drip_drip.DripDripModel, error) {
|
||||
converter.PassedLogs = ethLogs
|
||||
return []drip_drip.DripDripModel{test_data.DripDripModel}, converter.Err
|
||||
}
|
||||
|
||||
func (converter *MockDripDripConverter) SetConverterError(e error) {
|
||||
converter.Err = e
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package drip_drip
|
||||
|
||||
import (
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip"
|
||||
)
|
||||
|
||||
type MockDripDripRepository struct {
|
||||
createErr error
|
||||
markHeaderCheckedErr error
|
||||
markHeaderCheckedPassedHeaderID int64
|
||||
missingHeaders []core.Header
|
||||
missingHeadersErr error
|
||||
PassedStartingBlockNumber int64
|
||||
PassedEndingBlockNumber int64
|
||||
PassedHeaderID int64
|
||||
PassedModels []drip_drip.DripDripModel
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) Create(headerID int64, models []drip_drip.DripDripModel) error {
|
||||
repository.PassedHeaderID = headerID
|
||||
repository.PassedModels = models
|
||||
return repository.createErr
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) MarkHeaderChecked(headerID int64) error {
|
||||
repository.markHeaderCheckedPassedHeaderID = headerID
|
||||
return repository.markHeaderCheckedErr
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
repository.PassedStartingBlockNumber = startingBlockNumber
|
||||
repository.PassedEndingBlockNumber = endingBlockNumber
|
||||
return repository.missingHeaders, repository.missingHeadersErr
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) SetMarkHeaderCheckedErr(err error) {
|
||||
repository.markHeaderCheckedErr = err
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) SetMissingHeadersErr(e error) {
|
||||
repository.missingHeadersErr = e
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) SetMissingHeaders(headers []core.Header) {
|
||||
repository.missingHeaders = headers
|
||||
}
|
||||
|
||||
func (repository *MockDripDripRepository) SetCreateError(e error) {
|
||||
repository.createErr = e
|
||||
}
|
||||
func (repository *MockDripDripRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||
}
|
@ -83,14 +83,19 @@ var (
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewLogNoteTransformer
|
||||
|
||||
DentTransformerInitializer = factories.Transformer{
|
||||
DentTransformerInitializer = factories.LogNoteTransformer{
|
||||
Config: dent.DentConfig,
|
||||
Converter: &dent.DentConverter{},
|
||||
Repository: &dent.DentRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
}.NewLogNoteTransformer
|
||||
|
||||
DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer
|
||||
DripDripTransformerInitializer = factories.LogNoteTransformer{
|
||||
Config: drip_drip.DripDripConfig,
|
||||
Converter: &drip_drip.DripDripConverter{},
|
||||
Repository: &drip_drip.DripDripRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewLogNoteTransformer
|
||||
|
||||
DripFileIlkTransformerInitializer = factories.LogNoteTransformer{
|
||||
Config: ilk2.DripFileIlkConfig,
|
||||
|
Loading…
Reference in New Issue
Block a user