Use transformer factory for Drip drip

This commit is contained in:
Rob Mulholand 2018-10-26 13:31:40 -05:00
parent f3a82e6ba1
commit 1b680d2a4b
11 changed files with 123 additions and 311 deletions

View File

@ -16,10 +16,11 @@ package drip_drip
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var DripDripConfig = shared.TransformerConfig{ var DripDripConfig = shared.SingleTransformerConfig{
TransformerName: shared.DripDripLabel,
ContractAddresses: []string{shared.DripContractAddress}, ContractAddresses: []string{shared.DripContractAddress},
ContractAbi: shared.DripABI, ContractAbi: shared.DripABI,
Topics: []string{shared.DripDripSignature}, Topic: shared.DripDripSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -21,14 +21,10 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
) )
type Converter interface {
ToModels(ethLogs []types.Log) ([]DripDripModel, error)
}
type DripDripConverter struct{} type DripDripConverter struct{}
func (DripDripConverter) ToModels(ethLogs []types.Log) ([]DripDripModel, error) { func (DripDripConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
var models []DripDripModel var models []interface{}
for _, ethLog := range ethLogs { for _, ethLog := range ethLogs {
err := verifyLog(ethLog) err := verifyLog(ethLog)
if err != nil { if err != nil {

View File

@ -39,6 +39,6 @@ var _ = Describe("Drip drip converter", func() {
model, err := converter.ToModels([]types.Log{test_data.EthDripDripLog}) model, err := converter.ToModels([]types.Log{test_data.EthDripDripLog})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(model).To(Equal([]drip_drip.DripDripModel{test_data.DripDripModel})) Expect(model).To(Equal([]interface{}{test_data.DripDripModel}))
}) })
}) })

View File

@ -15,34 +15,31 @@
package drip_drip package drip_drip
import ( import (
"fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "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 { type DripDripRepository struct {
db *postgres.DB db *postgres.DB
} }
func NewDripDripRepository(db *postgres.DB) DripDripRepository { func (repository DripDripRepository) Create(headerID int64, models []interface{}) error {
return DripDripRepository{db: db}
}
func (repository DripDripRepository) Create(headerID int64, models []DripDripModel) error {
tx, err := repository.db.Begin() tx, err := repository.db.Begin()
if err != nil { if err != nil {
return err return err
} }
for _, model := range models { 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( _, err = tx.Exec(
`INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log) `INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5)`, 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 { if err != nil {
tx.Rollback() tx.Rollback()
@ -84,3 +81,7 @@ func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingB
) )
return result, err return result, err
} }
func (repository *DripDripRepository) SetDB(db *postgres.DB) {
repository.db = db
}

View File

@ -16,6 +16,7 @@ package drip_drip_test
import ( import (
"database/sql" "database/sql"
"math/rand"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -33,7 +34,7 @@ import (
var _ = Describe("Drip drip repository", func() { var _ = Describe("Drip drip repository", func() {
var ( var (
db *postgres.DB db *postgres.DB
dripDripRepository drip_drip.Repository dripDripRepository drip_drip.DripDripRepository
err error err error
headerRepository datastore.HeaderRepository headerRepository datastore.HeaderRepository
) )
@ -42,7 +43,8 @@ var _ = Describe("Drip drip repository", func() {
db = test_config.NewTestDB(test_config.NewTestNode()) db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
dripDripRepository = drip_drip.NewDripDripRepository(db) dripDripRepository = drip_drip.DripDripRepository{}
dripDripRepository.SetDB(db)
}) })
Describe("Create", func() { Describe("Create", func() {
@ -52,11 +54,12 @@ var _ = Describe("Drip drip repository", func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred()) 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() { It("adds a drip drip event", func() {
err = dripDripRepository.Create(headerID, []interface{}{test_data.DripDripModel})
Expect(err).NotTo(HaveOccurred())
var dbDripDrip drip_drip.DripDripModel 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) 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()) Expect(err).NotTo(HaveOccurred())
@ -67,6 +70,22 @@ var _ = Describe("Drip drip repository", func() {
}) })
It("marks header as checked for logs", 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 var headerChecked bool
err = db.Get(&headerChecked, `SELECT drip_drip_checked FROM public.checked_headers WHERE header_id = $1`, headerID) err = db.Get(&headerChecked, `SELECT drip_drip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -74,13 +93,19 @@ var _ = Describe("Drip drip repository", func() {
}) })
It("does not duplicate drip drip events", 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).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
}) })
It("removes drip drip if corresponding header is deleted", func() { 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) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -89,6 +114,12 @@ var _ = Describe("Drip drip repository", func() {
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows)) 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() { Describe("MarkHeaderChecked", func() {
@ -129,7 +160,7 @@ var _ = Describe("Drip drip repository", func() {
) )
BeforeEach(func() { BeforeEach(func() {
startingBlock = GinkgoRandomSeed() startingBlock = rand.Int63()
dripDripBlock = startingBlock + 1 dripDripBlock = startingBlock + 1
endingBlock = startingBlock + 2 endingBlock = startingBlock + 2
@ -178,7 +209,8 @@ var _ = Describe("Drip drip repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) 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]) nodeOneMissingHeaders, err := dripDripRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -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
}

View File

@ -19,6 +19,8 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"math/rand"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
@ -26,19 +28,39 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "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() { var _ = Describe("Drip drip transformer", func() {
It("gets missing headers for block numbers specified in config", func() { var (
repository := &drip_drip_mocks.MockDripDripRepository{} config = drip_drip.DripDripConfig
transformer := drip_drip.DripDripTransformer{ converter mocks.MockLogNoteConverter
Config: drip_drip.DripDripConfig, repository mocks.MockRepository
Fetcher: &mocks.MockLogFetcher{}, fetcher mocks.MockLogFetcher
Converter: &drip_drip_mocks.MockDripDripConverter{}, transformer shared.Transformer
Repository: repository, 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() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) 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() { It("returns error if repository returns error for missing headers", func() {
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeadersError(fakes.FakeError)
repository.SetMissingHeadersErr(fakes.FakeError)
transformer := drip_drip.DripDripTransformer{
Fetcher: &mocks.MockLogFetcher{},
Converter: &drip_drip_mocks.MockDripDripConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -62,34 +78,19 @@ var _ = Describe("Drip drip transformer", func() {
}) })
It("fetches logs for missing headers", func() { It("fetches logs for missing headers", func() {
fetcher := &mocks.MockLogFetcher{} repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
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,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_drip.DripDripConfig.ContractAddresses, drip_drip.DripDripConfig.ContractAddresses})) Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripDripSignature)}})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripDripSignature)}}))
}) })
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetcherError(fakes.FakeError) fetcher.SetFetcherError(fakes.FakeError)
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := drip_drip.DripDripTransformer{
Fetcher: fetcher,
Converter: &drip_drip_mocks.MockDripDripConverter{},
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -98,34 +99,17 @@ var _ = Describe("Drip drip transformer", func() {
}) })
It("marks header checked if no logs returned", func() { It("marks header checked if no logs returned", func() {
mockConverter := &drip_drip_mocks.MockDripDripConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
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,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID) repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
}) })
It("returns error if marking header checked returns err", func() { It("returns error if marking header checked returns err", func() {
mockConverter := &drip_drip_mocks.MockDripDripConverter{} repository.SetMissingHeaders([]core.Header{headerOne})
mockRepository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMarkHeaderCheckedError(fakes.FakeError)
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
mockFetcher := &mocks.MockLogFetcher{}
transformer := drip_drip.DripDripTransformer{
Converter: mockConverter,
Fetcher: mockFetcher,
Repository: mockRepository,
}
err := transformer.Execute() err := transformer.Execute()
@ -134,16 +118,8 @@ var _ = Describe("Drip drip transformer", func() {
}) })
It("converts matching logs", func() { It("converts matching logs", func() {
converter := &drip_drip_mocks.MockDripDripConverter{}
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := drip_drip.DripDripTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -152,17 +128,9 @@ var _ = Describe("Drip drip transformer", func() {
}) })
It("returns error if converter returns error", func() { It("returns error if converter returns error", func() {
converter := &drip_drip_mocks.MockDripDripConverter{}
converter.SetConverterError(fakes.FakeError) converter.SetConverterError(fakes.FakeError)
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
transformer := drip_drip.DripDripTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
@ -171,37 +139,21 @@ var _ = Describe("Drip drip transformer", func() {
}) })
It("persists drip drip model", func() { It("persists drip drip model", func() {
converter := &drip_drip_mocks.MockDripDripConverter{} converter.SetReturnModels([]interface{}{test_data.DripDripModel})
fetcher := &mocks.MockLogFetcher{}
fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
repository.SetMissingHeaders([]core.Header{fakeHeader})
transformer := drip_drip.DripDripTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id)) Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
Expect(repository.PassedModels).To(Equal([]drip_drip.DripDripModel{test_data.DripDripModel})) Expect(repository.PassedModels).To(Equal([]interface{}{test_data.DripDripModel}))
}) })
It("returns error if repository returns error for create", func() { 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}) fetcher.SetFetchedLogs([]types.Log{test_data.EthDripDripLog})
repository := &drip_drip_mocks.MockDripDripRepository{} repository.SetMissingHeaders([]core.Header{headerOne})
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
repository.SetCreateError(fakes.FakeError) repository.SetCreateError(fakes.FakeError)
transformer := drip_drip.DripDripTransformer{
Fetcher: fetcher,
Converter: converter,
Repository: repository,
}
err := transformer.Execute() err := transformer.Execute()

View File

@ -17,6 +17,8 @@ package integration_tests
import ( import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "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/pkg/transformers/drip_drip"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -40,8 +42,14 @@ var _ = Describe("DripDrip Transformer", func() {
err = persistHeader(db, blockNumber) err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
initializer := drip_drip.DripDripTransformerInitializer{Config: config} initializer := factories.LogNoteTransformer{
transformer := initializer.NewDripDripTransformer(db, blockchain) Config: drip_drip.DripDripConfig,
Converter: &drip_drip.DripDripConverter{},
Repository: &drip_drip.DripDripRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute() err = transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -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
}

View File

@ -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))
}

View File

@ -83,14 +83,19 @@ var (
Fetcher: &shared.Fetcher{}, Fetcher: &shared.Fetcher{},
}.NewLogNoteTransformer }.NewLogNoteTransformer
DentTransformerInitializer = factories.Transformer{ DentTransformerInitializer = factories.LogNoteTransformer{
Config: dent.DentConfig, Config: dent.DentConfig,
Converter: &dent.DentConverter{}, Converter: &dent.DentConverter{},
Repository: &dent.DentRepository{}, Repository: &dent.DentRepository{},
Fetcher: &shared.Fetcher{}, 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{ DripFileIlkTransformerInitializer = factories.LogNoteTransformer{
Config: ilk2.DripFileIlkConfig, Config: ilk2.DripFileIlkConfig,