Use transformer factory for Bite (#89)

* Use transformer factory for Bite

- introduces separate transformer factory for non-LogNote events
- converter includes `ToEntities` for events defined via ABI

* Updates after rebasing with staging
This commit is contained in:
Rob Mulholand 2018-10-26 13:26:10 -05:00 committed by Elizabeth
parent 0e5b23993a
commit d1ee501f12
57 changed files with 539 additions and 506 deletions

View File

@ -20,10 +20,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
)
var BiteConfig = shared.TransformerConfig{
var BiteConfig = shared.SingleTransformerConfig{
TransformerName: shared.BiteLabel,
ContractAddresses: []string{shared.CatContractAddress},
ContractAbi: shared.CatABI,
Topics: []string{shared.BiteSignature},
Topic: shared.BiteSignature,
StartingBlockNumber: 0,
EndingBlockNumber: 10000000,
}

View File

@ -19,6 +19,7 @@ package bite
import (
"bytes"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
@ -26,15 +27,10 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
)
type Converter interface {
ToEntities(contractAbi string, ethLogs []types.Log) ([]BiteEntity, error)
ToModels(biteEntities []BiteEntity) ([]BiteModel, error)
}
type BiteConverter struct{}
func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]BiteEntity, error) {
var entities []BiteEntity
func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) {
var entities []interface{}
for _, ethLog := range ethLogs {
entity := &BiteEntity{}
address := ethLog.Address
@ -60,19 +56,24 @@ func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Bite
return entities, nil
}
func (converter BiteConverter) ToModels(entities []BiteEntity) ([]BiteModel, error) {
var models []BiteModel
func (converter BiteConverter) ToModels(entities []interface{}) ([]interface{}, error) {
var models []interface{}
for _, entity := range entities {
ilk := string(bytes.Trim(entity.Ilk[:], "\x00"))
urn := common.BytesToAddress(entity.Urn[:]).String()
ink := entity.Ink
art := entity.Art
iArt := entity.IArt
tab := entity.Tab
flip := entity.Flip
logIdx := entity.LogIndex
txIdx := entity.TransactionIndex
rawLogJson, err := json.Marshal(entity.Raw)
biteEntity, ok := entity.(BiteEntity)
if !ok {
return nil, fmt.Errorf("entity of type %T, not %T", entity, BiteEntity{})
}
ilk := string(bytes.Trim(biteEntity.Ilk[:], "\x00"))
urn := common.BytesToAddress(biteEntity.Urn[:]).String()
ink := biteEntity.Ink
art := biteEntity.Art
iArt := biteEntity.IArt
tab := biteEntity.Tab
flip := biteEntity.Flip
logIdx := biteEntity.LogIndex
txIdx := biteEntity.TransactionIndex
rawLogJson, err := json.Marshal(biteEntity.Raw)
rawLogString := string(rawLogJson)
if err != nil {
return nil, err

View File

@ -37,15 +37,7 @@ var _ = Describe("Bite Converter", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(entities)).To(Equal(1))
entity := entities[0]
Expect(entity.Ilk).To(Equal(test_data.BiteEntity.Ilk))
Expect(entity.Urn).To(Equal(test_data.BiteEntity.Urn))
Expect(entity.Ink).To(Equal(test_data.BiteEntity.Ink))
Expect(entity.Art).To(Equal(test_data.BiteEntity.Art))
Expect(entity.Tab).To(Equal(test_data.BiteEntity.Tab))
Expect(entity.Flip).To(Equal(test_data.BiteEntity.Flip))
Expect(entity.IArt).To(Equal(test_data.BiteEntity.IArt))
Expect(entity.TransactionIndex).To(Equal(test_data.BiteEntity.TransactionIndex))
Expect(entity.Raw).To(Equal(test_data.BiteEntity.Raw))
Expect(entity).To(Equal(test_data.BiteEntity))
})
It("returns an error if converting log to entity fails", func() {
@ -59,7 +51,7 @@ var _ = Describe("Bite Converter", func() {
var emptyEntity = bite.BiteEntity{}
It("converts an Entity to a Model", func() {
models, err := converter.ToModels([]bite.BiteEntity{test_data.BiteEntity})
models, err := converter.ToModels([]interface{}{test_data.BiteEntity})
Expect(err).NotTo(HaveOccurred())
Expect(len(models)).To(Equal(1))
@ -81,7 +73,7 @@ var _ = Describe("Bite Converter", func() {
TransactionIndex: 0,
Raw: string(emptyLog),
}
models, err := converter.ToModels([]bite.BiteEntity{emptyEntity})
models, err := converter.ToModels([]interface{}{emptyEntity})
Expect(err).NotTo(HaveOccurred())
Expect(len(models)).To(Equal(1))

View File

@ -15,34 +15,34 @@
package bite
import (
"fmt"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
type Repository interface {
Create(headerID int64, models []BiteModel) error
MarkHeaderChecked(headerID int64) error
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
}
type BiteRepository struct {
db *postgres.DB
}
func NewBiteRepository(db *postgres.DB) Repository {
return BiteRepository{db: db}
func (repository *BiteRepository) SetDB(db *postgres.DB) {
repository.db = db
}
func (repository BiteRepository) Create(headerID int64, models []BiteModel) error {
func (repository BiteRepository) Create(headerID int64, models []interface{}) error {
tx, err := repository.db.Begin()
if err != nil {
return err
}
for _, model := range models {
biteModel, ok := model.(BiteModel)
if !ok {
tx.Rollback()
return fmt.Errorf("model of type %T, not %T", model, BiteModel{})
}
_, err := tx.Exec(
`INSERT into maker.bite (header_id, ilk, urn, ink, art, iart, tab, nflip, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5::NUMERIC, $6::NUMERIC, $7::NUMERIC, $8::NUMERIC, $9, $10, $11)`,
headerID, model.Ilk, model.Urn, model.Ink, model.Art, model.IArt, model.Tab, model.NFlip, model.LogIndex, model.TransactionIndex, model.Raw,
headerID, biteModel.Ilk, biteModel.Urn, biteModel.Ink, biteModel.Art, biteModel.IArt, biteModel.Tab, biteModel.NFlip, biteModel.LogIndex, biteModel.TransactionIndex, biteModel.Raw,
)
if err != nil {
tx.Rollback()
@ -57,6 +57,7 @@ func (repository BiteRepository) Create(headerID int64, models []BiteModel) erro
tx.Rollback()
return err
}
return tx.Commit()
}

View File

@ -16,6 +16,7 @@ package bite_test
import (
"database/sql"
"math/rand"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -26,13 +27,14 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Bite repository", func() {
var (
biteRepository bite.Repository
biteRepository factories.Repository
db *postgres.DB
err error
headerRepository datastore.HeaderRepository
@ -42,7 +44,8 @@ var _ = Describe("Bite repository", func() {
db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db)
biteRepository = bite.NewBiteRepository(db)
biteRepository = &bite.BiteRepository{}
biteRepository.SetDB(db)
})
Describe("Create", func() {
@ -51,12 +54,12 @@ var _ = Describe("Bite repository", func() {
BeforeEach(func() {
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
Expect(err).NotTo(HaveOccurred())
err = biteRepository.Create(headerID, []bite.BiteModel{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
})
It("persists a bite record", func() {
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
var dbBite bite.BiteModel
err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, log_idx, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
@ -73,6 +76,21 @@ var _ = Describe("Bite repository", func() {
})
It("marks header as checked for logs", func() {
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
var headerChecked bool
err = db.Get(&headerChecked, `SELECT bite_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(headerChecked).To(BeTrue())
})
It("updates a header as checked if row already exists", func() {
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
Expect(err).NotTo(HaveOccurred())
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
var headerChecked bool
err = db.Get(&headerChecked, `SELECT bite_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
@ -80,13 +98,19 @@ var _ = Describe("Bite repository", func() {
})
It("does not duplicate bite events", func() {
err = biteRepository.Create(headerID, []bite.BiteModel{test_data.BiteModel})
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
})
It("removes bite if corresponding header is deleted", func() {
err = biteRepository.Create(headerID, []interface{}{test_data.BiteModel})
Expect(err).NotTo(HaveOccurred())
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
@ -95,6 +119,13 @@ var _ = Describe("Bite repository", func() {
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows))
})
It("returns an error if the model type is not a Bite", func() {
err = biteRepository.Create(headerID, []interface{}{test_data.WrongModel{}})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("model of type test_data.WrongModel, not bite.BiteModel"))
})
})
Describe("MarkHeaderChecked", func() {
@ -135,7 +166,7 @@ var _ = Describe("Bite repository", func() {
)
BeforeEach(func() {
startingBlock = GinkgoRandomSeed()
startingBlock = rand.Int63()
biteBlock = startingBlock + 1
endingBlock = startingBlock + 2
@ -183,7 +214,8 @@ var _ = Describe("Bite repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred())
}
biteRepositoryTwo := bite.NewBiteRepository(dbTwo)
biteRepositoryTwo := bite.BiteRepository{}
biteRepositoryTwo.SetDB(dbTwo)
nodeOneMissingHeaders, err := biteRepository.MissingHeaders(blockNumbers[0], blockNumbers[len(blockNumbers)-1])
Expect(err).NotTo(HaveOccurred())

View File

@ -1,97 +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 bite
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 BiteTransformer struct {
Repository Repository
Fetcher shared.LogFetcher
Converter Converter
Config shared.TransformerConfig
}
type BiteTransformerInitializer struct {
Config shared.TransformerConfig
}
func (i BiteTransformerInitializer) NewBiteTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
fetcher := shared.NewFetcher(blockChain)
repository := NewBiteRepository(db)
transformer := BiteTransformer{
Fetcher: fetcher,
Repository: repository,
Converter: BiteConverter{},
Config: i.Config,
}
return transformer
}
func (b BiteTransformer) Execute() error {
config := b.Config
topics := [][]common.Hash{{common.HexToHash(shared.BiteSignature)}}
missingHeaders, err := b.Repository.MissingHeaders(config.StartingBlockNumber, config.EndingBlockNumber)
if err != nil {
log.Println("Error fetching missing headers:", err)
return err
}
log.Printf("Fetching bite event logs for %d headers \n", len(missingHeaders))
for _, header := range missingHeaders {
ethLogs, err := b.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber)
if err != nil {
log.Println("Error fetching matching logs:", err)
return err
}
if len(ethLogs) < 1 {
err = b.Repository.MarkHeaderChecked(header.Id)
if err != nil {
return err
}
}
entities, err := b.Converter.ToEntities(config.ContractAbi, ethLogs)
if err != nil {
return err
}
model, err := b.Converter.ToModels(entities)
if err != nil {
log.Println("Error converting logs:", err)
return err
}
err = b.Repository.Create(header.Id, model)
if err != nil {
log.Println("Error persisting bite record:", err)
return err
}
}
return nil
}
func (b BiteTransformer) SetConfig(config shared.TransformerConfig) {
b.Config = config
}

View File

@ -27,33 +27,36 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
bite_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/bite"
)
var _ = Describe("Bite Transformer", func() {
var repository bite_mocks.MockBiteRepository
var repository mocks.MockRepository
var fetcher mocks.MockLogFetcher
var converter bite_mocks.MockBiteConverter
var transformer bite.BiteTransformer
var converter mocks.MockConverter
var transformer shared.Transformer
var blockNumber1 = rand.Int63()
var blockNumber2 = rand.Int63()
BeforeEach(func() {
repository = bite_mocks.MockBiteRepository{}
repository = mocks.MockRepository{}
fetcher = mocks.MockLogFetcher{}
converter = bite_mocks.MockBiteConverter{}
converter = mocks.MockConverter{}
transformer = bite.BiteTransformer{
transformer = factories.Transformer{
Repository: &repository,
Fetcher: &fetcher,
Converter: &converter,
Config: bite.BiteConfig,
}
}.NewTransformer(nil, nil)
})
transformer.SetConfig(bite.BiteConfig)
It("sets the blockchain and db", func() {
Expect(fetcher.SetBcCalled).To(BeTrue())
Expect(repository.SetDbCalled).To(BeTrue())
})
It("gets missing headers for blocks in the configured range", func() {
@ -65,7 +68,7 @@ var _ = Describe("Bite Transformer", func() {
})
It("returns an error if it fails to get missing headers", func() {
repository.SetMissingHeadersErr(fakes.FakeError)
repository.SetMissingHeadersError(fakes.FakeError)
err := transformer.Execute()
Expect(err).To(HaveOccurred())
@ -103,7 +106,7 @@ var _ = Describe("Bite Transformer", func() {
It("returns error if marking header checked returns err", func() {
repository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
repository.SetMarkHeaderCheckedErr(fakes.FakeError)
repository.SetMarkHeaderCheckedError(fakes.FakeError)
err := transformer.Execute()
@ -117,7 +120,7 @@ var _ = Describe("Bite Transformer", func() {
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(converter.ConverterAbi).To(Equal(bite.BiteConfig.ContractAbi))
Expect(converter.ContractAbi).To(Equal(bite.BiteConfig.ContractAbi))
Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.EthBiteLog}))
})
@ -125,7 +128,30 @@ var _ = Describe("Bite Transformer", func() {
headerId := int64(1)
repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1, Id: headerId}})
fetcher.SetFetchedLogs([]types.Log{test_data.EthBiteLog})
converter.SetConverterError(fakes.FakeError)
converter.ToEntitiesError = fakes.FakeError
err := transformer.Execute()
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(fakes.FakeError))
})
It("converts an entity to a BiteModel", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
fetcher.SetFetchedLogs([]types.Log{test_data.EthBiteLog})
converter.EntitiesToReturn = []interface{}{test_data.BiteEntity}
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(converter.EntitiesToConvert[0]).To(Equal(test_data.BiteEntity))
})
It("returns an error if converting to models fails", func() {
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
fetcher.SetFetchedLogs([]types.Log{test_data.EthBiteLog})
converter.EntitiesToReturn = []interface{}{test_data.BiteEntity}
converter.ToModelsError = fakes.FakeError
err := transformer.Execute()
@ -137,12 +163,13 @@ var _ = Describe("Bite Transformer", func() {
headerId := int64(1)
repository.SetMissingHeaders([]core.Header{{BlockNumber: blockNumber1, Id: headerId}})
fetcher.SetFetchedLogs([]types.Log{test_data.EthBiteLog})
converter.ModelsToReturn = []interface{}{test_data.BiteModel}
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(repository.PassedHeaderID).To(Equal(headerId))
Expect(repository.PassedBiteModels).To(Equal([]bite.BiteModel{test_data.BiteModel}))
Expect(repository.PassedModels[0]).To(Equal(test_data.BiteModel))
})
It("returns error if persisting bite record fails", func() {

View File

@ -34,7 +34,7 @@ var _ = Describe("Cat file chop lump transformer", func() {
var (
config = chop_lump.CatFileChopLumpConfig
repository mocks.MockRepository
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
fetcher mocks.MockLogFetcher
transformer shared.Transformer
headerOne core.Header
@ -43,14 +43,14 @@ var _ = Describe("Cat file chop lump transformer", func() {
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})

View File

@ -34,7 +34,7 @@ var _ = Describe("Cat file flip transformer", func() {
var (
config = flip.CatFileFlipConfig
repository mocks.MockRepository
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
fetcher mocks.MockLogFetcher
transformer shared.Transformer
headerOne core.Header
@ -43,14 +43,14 @@ var _ = Describe("Cat file flip transformer", func() {
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})

View File

@ -34,7 +34,7 @@ var _ = Describe("Cat file pit vow transformer", func() {
var (
config = pit_vow.CatFilePitVowConfig
repository mocks.MockRepository
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
fetcher mocks.MockLogFetcher
transformer shared.Transformer
headerOne core.Header
@ -43,14 +43,14 @@ var _ = Describe("Cat file pit vow transformer", func() {
BeforeEach(func() {
repository = mocks.MockRepository{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
fetcher = mocks.MockLogFetcher{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})

View File

@ -34,7 +34,7 @@ var _ = Describe("DealTransformer", func() {
var config = deal.DealConfig
var repository mocks.MockRepository
var fetcher mocks.MockLogFetcher
var converter mocks.MockConverter
var converter mocks.MockLogNoteConverter
var transformer shared.Transformer
var headerOne core.Header
var headerTwo core.Header
@ -42,13 +42,13 @@ var _ = Describe("DealTransformer", func() {
BeforeEach(func() {
repository = mocks.MockRepository{}
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
transformer = factories.Transformer{
converter = mocks.MockLogNoteConverter{}
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
headerTwo = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
})

View File

@ -35,7 +35,7 @@ var _ = Describe("Drip file ilk transformer", func() {
var (
config = ilk.DripFileIlkConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,14 +44,14 @@ var _ = Describe("Drip file ilk transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
headerTwo = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
})

View File

@ -35,7 +35,7 @@ var _ = Describe("Drip file repo transformer", func() {
var (
config = repo.DripFileRepoConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,14 +44,14 @@ var _ = Describe("Drip file repo transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
headerTwo = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
})

View File

@ -35,7 +35,7 @@ var _ = Describe("Drip file vow transformer", func() {
var (
config = vow.DripFileVowConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,14 +44,14 @@ var _ = Describe("Drip file vow transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
headerTwo = core.Header{BlockNumber: rand.Int63(), Id: rand.Int63()}
})

View File

@ -0,0 +1,22 @@
// 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 factories
import "github.com/ethereum/go-ethereum/core/types"
type Converter interface {
ToEntities(contractAbi string, ethLog []types.Log) ([]interface{}, error)
ToModels([]interface{}) ([]interface{}, error)
}

View File

@ -0,0 +1,21 @@
// 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 factories
import "github.com/ethereum/go-ethereum/core/types"
type LogNoteConverter interface {
ToModels(ethLog []types.Log) ([]interface{}, error)
}

View File

@ -0,0 +1,85 @@
// 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 factories
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 LogNoteTransformer struct {
Config shared.SingleTransformerConfig
Converter LogNoteConverter
Repository Repository
Fetcher shared.SettableLogFetcher
}
func (transformer LogNoteTransformer) NewLogNoteTransformer(db *postgres.DB, bc core.BlockChain) shared.Transformer {
transformer.Repository.SetDB(db)
transformer.Fetcher.SetBC(bc)
return transformer
}
func (transformer LogNoteTransformer) Execute() error {
transformerName := transformer.Config.TransformerName
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
if err != nil {
log.Printf("Error fetching mising headers in %v transformer: %v \n", transformerName, err)
return err
}
// Grab event signature from transformer config
// (Double-array structure required for go-ethereum FilterQuery)
var topic = [][]common.Hash{{common.HexToHash(transformer.Config.Topic)}}
log.Printf("Fetching %v event logs for %d headers \n", transformerName, len(missingHeaders))
for _, header := range missingHeaders {
// Fetch the missing logs for a given header
matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topic, header.BlockNumber)
if err != nil {
log.Printf("Error fetching matching logs in %v transformer: %v", transformerName, err)
return err
}
// No matching logs, mark the header as checked for this type of logs
if len(matchingLogs) < 1 {
err := transformer.Repository.MarkHeaderChecked(header.Id)
if err != nil {
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
return err
}
// Continue with the next header; nothing to persist
continue
}
models, err := transformer.Converter.ToModels(matchingLogs)
if err != nil {
log.Printf("Error converting logs in %v: %v", transformerName, err)
return err
}
err = transformer.Repository.Create(header.Id, models)
if err != nil {
log.Printf("Error persisting %v record: %v", transformerName, err)
return err
}
}
return nil
}

View File

@ -0,0 +1,27 @@
// 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 factories
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
type Repository interface {
Create(headerID int64, models []interface{}) error
MarkHeaderChecked(headerID int64) error
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
SetDB(db *postgres.DB)
}

View File

@ -15,13 +15,12 @@
package factories
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"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"
)
@ -32,17 +31,6 @@ type Transformer struct {
Fetcher shared.SettableLogFetcher
}
type Converter interface {
ToModels(ethLog []types.Log) ([]interface{}, error)
}
type Repository interface {
Create(headerID int64, models []interface{}) error
MarkHeaderChecked(headerID int64) error
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
SetDB(db *postgres.DB)
}
func (transformer Transformer) NewTransformer(db *postgres.DB, bc core.BlockChain) shared.Transformer {
transformer.Repository.SetDB(db)
transformer.Fetcher.SetBC(bc)
@ -51,39 +39,40 @@ func (transformer Transformer) NewTransformer(db *postgres.DB, bc core.BlockChai
func (transformer Transformer) Execute() error {
transformerName := transformer.Config.TransformerName
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
config := transformer.Config
topics := [][]common.Hash{{common.HexToHash(config.Topic)}}
missingHeaders, err := transformer.Repository.MissingHeaders(config.StartingBlockNumber, config.EndingBlockNumber)
if err != nil {
log.Printf("Error fetching missing headers in %v transformer: %v \n", transformerName, err)
return err
}
// Grab event signature from transformer config
// (Double-array structure required for go-ethereum FilterQuery)
var topic = [][]common.Hash{{common.HexToHash(transformer.Config.Topic)}}
log.Printf("Fetching %v event logs for %d headers \n", transformerName, len(missingHeaders))
for _, header := range missingHeaders {
// Fetch the missing logs for a given header
matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topic, header.BlockNumber)
logs, err := transformer.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber)
if err != nil {
log.Printf("Error fetching matching logs in %v transformer: %v", transformerName, err)
return err
}
// No matching logs, mark the header as checked for this type of logs
if len(matchingLogs) < 1 {
err := transformer.Repository.MarkHeaderChecked(header.Id)
if len(logs) < 1 {
err = transformer.Repository.MarkHeaderChecked(header.Id)
if err != nil {
log.Printf("Error marking header as checked in %v: %v", transformerName, err)
return err
}
// Continue with the next header; nothing to persist
continue
}
models, err := transformer.Converter.ToModels(matchingLogs)
entities, err := transformer.Converter.ToEntities(config.ContractAbi, logs)
if err != nil {
log.Printf("Error converting logs in %v: %v", transformerName, err)
log.Printf("Error converting logs to entities in %v: %v", transformerName, err)
return err
}
models, err := transformer.Converter.ToModels(entities)
if err != nil {
log.Printf("Error converting entities to models in %v: %v", transformerName, err)
return err
}
@ -92,6 +81,8 @@ func (transformer Transformer) Execute() error {
log.Printf("Error persisting %v record: %v", transformerName, err)
return err
}
}
return nil
}

View File

@ -45,12 +45,12 @@ var _ = Describe("Flog transformer", func() {
repository = flog_mocks.MockFlogRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -19,6 +19,8 @@ import (
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/test_config"
)
@ -40,8 +42,13 @@ var _ = Describe("Bite Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := bite.BiteTransformerInitializer{Config: config}
transformer := initializer.NewBiteTransformer(db, blockchain)
initializer := factories.Transformer{
Config: config,
Converter: &bite.BiteConverter{},
Repository: &bite.BiteRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -61,13 +61,13 @@ var _ = Describe("Cat File transformer", func() {
config.StartingBlockNumber = chopLumpBlockNumber
config.EndingBlockNumber = chopLumpBlockNumber
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Converter: &chop_lump.CatFileChopLumpConverter{},
Repository: &chop_lump.CatFileChopLumpRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
@ -99,13 +99,13 @@ var _ = Describe("Cat File transformer", func() {
config.StartingBlockNumber = flipBlockNumber
config.EndingBlockNumber = flipBlockNumber
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Converter: &flip.CatFileFlipConverter{},
Repository: &flip.CatFileFlipRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())
@ -129,13 +129,13 @@ var _ = Describe("Cat File transformer", func() {
config.StartingBlockNumber = pitVowBlockNumber
config.EndingBlockNumber = pitVowBlockNumber
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Converter: &pit_vow.CatFilePitVowConverter{},
Repository: &pit_vow.CatFilePitVowRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -56,13 +56,13 @@ var _ = Describe("Deal transformer", func() {
config.StartingBlockNumber = flipBlockNumber
config.EndingBlockNumber = flipBlockNumber
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Converter: &deal.DealConverter{},
Repository: &deal.DealRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err := transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Drip File Vow Transformer", func() {
var _ = Describe("Drip File Vow LogNoteTransformer", func() {
It("transforms DripFileVow log events", func() {
blockNumber := int64(8762197)
config := vow.DripFileVowConfig
@ -42,13 +42,13 @@ var _ = Describe("Drip File Vow Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vow.DripFileVowConverter{},
Repository: &vow.DripFileVowRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("PitFileDebtCeiling Transformer", func() {
var _ = Describe("PitFileDebtCeiling LogNoteTransformer", func() {
It("fetches and transforms a PitFileDebtCeiling event from Kovan chain", func() {
blockNumber := int64(8535578)
config := debt_ceiling.DebtCeilingFileConfig
@ -42,13 +42,13 @@ var _ = Describe("PitFileDebtCeiling Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &debt_ceiling.PitFileDebtCeilingConverter{},
Repository: &debt_ceiling.PitFileDebtCeilingRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("PitFileIlk Transformer", func() {
var _ = Describe("PitFileIlk LogNoteTransformer", func() {
It("fetches and transforms a PitFileIlk event from Kovan chain", func() {
blockNumber := int64(9103223)
config := ilk.IlkFileConfig
@ -42,13 +42,13 @@ var _ = Describe("PitFileIlk Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &ilk.PitFileIlkConverter{},
Repository: &ilk.PitFileIlkRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("PitFileStabilityFee Transformer", func() {
var _ = Describe("PitFileStabilityFee LogNoteTransformer", func() {
It("fetches and transforms a PitFileStabilityFee event from Kovan chain", func() {
blockNumber := int64(8535544)
config := stability_fee.StabilityFeeFileConfig
@ -42,13 +42,13 @@ var _ = Describe("PitFileStabilityFee Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &stability_fee.PitFileStabilityFeeConverter{},
Repository: &stability_fee.PitFileStabilityFeeRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -50,13 +50,13 @@ var _ = Describe("Price feeds transformer", func() {
config.StartingBlockNumber = blockNumber
config.EndingBlockNumber = blockNumber
transformerInitializer := factories.Transformer{
transformerInitializer := factories.LogNoteTransformer{
Config: config,
Converter: &price_feeds.PriceFeedConverter{},
Repository: &price_feeds.PriceFeedRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := transformerInitializer.NewTransformer(db, blockChain)
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
err = transformer.Execute()
@ -77,13 +77,13 @@ var _ = Describe("Price feeds transformer", func() {
config.StartingBlockNumber = blockNumber
config.EndingBlockNumber = blockNumber
transformerInitializer := factories.Transformer{
transformerInitializer := factories.LogNoteTransformer{
Config: config,
Converter: &price_feeds.PriceFeedConverter{},
Repository: &price_feeds.PriceFeedRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := transformerInitializer.NewTransformer(db, blockChain)
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
err = transformer.Execute()
@ -104,13 +104,13 @@ var _ = Describe("Price feeds transformer", func() {
config.StartingBlockNumber = blockNumber
config.EndingBlockNumber = blockNumber
transformerInitializer := factories.Transformer{
transformerInitializer := factories.LogNoteTransformer{
Config: config,
Converter: &price_feeds.PriceFeedConverter{},
Repository: &price_feeds.PriceFeedRepository{},
Fetcher: &shared.Fetcher{},
}
transformer := transformerInitializer.NewTransformer(db, blockChain)
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
err = transformer.Execute()

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Tend Transformer", func() {
var _ = Describe("Tend LogNoteTransformer", func() {
It("fetches and transforms a Tend event from Kovan chain", func() {
blockNumber := int64(8935601)
config := tend.TendConfig
@ -42,13 +42,13 @@ var _ = Describe("Tend Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &tend.TendConverter{},
Repository: &tend.TendRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())
@ -81,13 +81,13 @@ var _ = Describe("Tend Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &tend.TendConverter{},
Repository: &tend.TendRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("VatFlux Transformer", func() {
var _ = Describe("VatFlux LogNoteTransformer", func() {
It("transforms VatFlux log events", func() {
blockNumber := int64(9004474)
config := vat_flux.VatFluxConfig
@ -42,13 +42,13 @@ var _ = Describe("VatFlux Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_flux.VatFluxConverter{},
Repository: &vat_flux.VatFluxRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -43,13 +43,13 @@ var _ = Describe("VatFold Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_fold.VatFoldConverter{},
Repository: &vat_fold.VatFoldRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -44,12 +44,12 @@ var _ = Describe("Vat Grab Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
transformer := factories.Transformer{
transformer := factories.LogNoteTransformer{
Config: vat_grab.VatGrabConfig,
Converter: &vat_grab.VatGrabConverter{},
Repository: &vat_grab.VatGrabRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer(db, blockchain)
}.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -43,12 +43,12 @@ var _ = Describe("VatHeal Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
transformer := factories.Transformer{
transformer := factories.LogNoteTransformer{
Config: vat_heal.VatHealConfig,
Converter: &vat_heal.VatHealConverter{},
Repository: &vat_heal.VatHealRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer(db, blockchain)
}.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -24,7 +24,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("VatInit Transformer", func() {
var _ = Describe("VatInit LogNoteTransformer", func() {
It("transforms VatInit log events", func() {
blockNumber := int64(8535561)
config := vat_init.VatInitConfig
@ -42,13 +42,13 @@ var _ = Describe("VatInit Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_init.VatInitConverter{},
Repository: &vat_init.VatInitRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -25,7 +25,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("VatMove Transformer", func() {
var _ = Describe("VatMove LogNoteTransformer", func() {
It("transforms VatMove log events", func() {
blockNumber := int64(9004628)
config := vat_move.VatMoveConfig
@ -43,13 +43,13 @@ var _ = Describe("VatMove Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_move.VatMoveConverter{},
Repository: &vat_move.VatMoveRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -34,13 +34,13 @@ var _ = Describe("Vat slip transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_slip.VatSlipConverter{},
Repository: &vat_slip.VatSlipRepository{},
}
transformer := initializer.NewTransformer(db, blockChain)
transformer := initializer.NewLogNoteTransformer(db, blockChain)
err = transformer.Execute()

View File

@ -26,7 +26,7 @@ import (
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("VatTune Transformer", func() {
var _ = Describe("VatTune LogNoteTransformer", func() {
It("transforms VatTune log events", func() {
blockNumber := int64(8761670)
config := vat_tune.VatTuneConfig
@ -44,13 +44,13 @@ var _ = Describe("VatTune Transformer", func() {
err = persistHeader(db, blockNumber)
Expect(err).NotTo(HaveOccurred())
initializer := factories.Transformer{
initializer := factories.LogNoteTransformer{
Config: config,
Fetcher: &shared.Fetcher{},
Converter: &vat_tune.VatTuneConverter{},
Repository: &vat_tune.VatTuneRepository{},
}
transformer := initializer.NewTransformer(db, blockchain)
transformer := initializer.NewLogNoteTransformer(db, blockchain)
err = transformer.Execute()
Expect(err).NotTo(HaveOccurred())

View File

@ -35,7 +35,7 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
var (
config = debt_ceiling.DebtCeilingFileConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,16 +44,16 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -35,7 +35,7 @@ var _ = Describe("Pit file ilk transformer", func() {
var (
config = ilk.IlkFileConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,16 +44,16 @@ var _ = Describe("Pit file ilk transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Repository: &repository,
Fetcher: &fetcher,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -35,7 +35,7 @@ var _ = Describe("Pit file stability fee transformer", func() {
var (
config = stability_fee.StabilityFeeFileConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,14 +44,14 @@ var _ = Describe("Pit file stability fee transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
})

View File

@ -34,7 +34,7 @@ var _ = Describe("Price feed transformer", func() {
var (
config = price_feeds.PriceFeedConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -43,16 +43,16 @@ var _ = Describe("Price feed transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and db", func() {

View File

@ -31,10 +31,10 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
)
var _ = Describe("Tend Transformer", func() {
var _ = Describe("Tend LogNoteTransformer", func() {
var (
config = tend.TendConfig
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
fetcher mocks.MockLogFetcher
transformer shared.Transformer
@ -43,17 +43,17 @@ var _ = Describe("Tend Transformer", func() {
)
BeforeEach(func() {
converter = mocks.MockConverter{}
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.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -1,44 +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 bite
import (
"github.com/ethereum/go-ethereum/core/types"
. "github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)
type MockBiteConverter struct {
ConverterAbi string
LogsToConvert []types.Log
EntitiesToConvert []BiteEntity
ConverterError error
}
func (mbc *MockBiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]BiteEntity, error) {
mbc.ConverterAbi = contractAbi
mbc.LogsToConvert = append(mbc.LogsToConvert, ethLogs...)
return []BiteEntity{test_data.BiteEntity}, mbc.ConverterError
}
func (mbc *MockBiteConverter) ToModels(entities []BiteEntity) ([]BiteModel, error) {
mbc.EntitiesToConvert = append(mbc.EntitiesToConvert, entities...)
return []BiteModel{test_data.BiteModel}, mbc.ConverterError
}
func (mbc *MockBiteConverter) SetConverterError(err error) {
mbc.ConverterError = err
}

View File

@ -1,72 +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 bite
import (
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/transformers/bite"
)
type MockBiteRepository struct {
createError error
PassedEndingBlockNumber int64
PassedBiteModels []bite.BiteModel
PassedHeaderID int64
PassedStartingBlockNumber int64
PassedTransactionIndex uint
markHeaderCheckedErr error
markHeaderCheckedPassedHeaderID int64
missingHeaders []core.Header
missingHeadersErr error
}
func (repository *MockBiteRepository) SetCreateError(err error) {
repository.createError = err
}
func (repository *MockBiteRepository) SetMissingHeadersErr(err error) {
repository.missingHeadersErr = err
}
func (repository *MockBiteRepository) SetMissingHeaders(headers []core.Header) {
repository.missingHeaders = headers
}
func (repository *MockBiteRepository) Create(headerID int64, models []bite.BiteModel) error {
repository.PassedHeaderID = headerID
repository.PassedBiteModels = models
return repository.createError
}
func (repository *MockBiteRepository) MarkHeaderChecked(headerID int64) error {
repository.markHeaderCheckedPassedHeaderID = headerID
return repository.markHeaderCheckedErr
}
func (repository *MockBiteRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
repository.PassedStartingBlockNumber = startingBlockNumber
repository.PassedEndingBlockNumber = endingBlockNumber
return repository.missingHeaders, repository.missingHeadersErr
}
func (repository *MockBiteRepository) SetMarkHeaderCheckedErr(e error) {
repository.markHeaderCheckedErr = e
}
func (repository *MockBiteRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
}

View File

@ -5,20 +5,22 @@ import (
)
type MockConverter struct {
err error
returnModels []interface{}
PassedLogs []types.Log
ToEntitiesError error
ToModelsError error
ContractAbi string
LogsToConvert []types.Log
EntitiesToConvert []interface{}
EntitiesToReturn []interface{}
ModelsToReturn []interface{}
}
func (converter *MockConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
converter.PassedLogs = ethLogs
return converter.returnModels, converter.err
func (converter *MockConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]interface{}, error) {
converter.ContractAbi = contractAbi
converter.LogsToConvert = ethLogs
return converter.EntitiesToReturn, converter.ToEntitiesError
}
func (converter *MockConverter) SetConverterError(e error) {
converter.err = e
}
func (converter *MockConverter) SetReturnModels(models []interface{}) {
converter.returnModels = models
func (converter *MockConverter) ToModels(entities []interface{}) ([]interface{}, error) {
converter.EntitiesToConvert = entities
return converter.ModelsToReturn, converter.ToModelsError
}

View File

@ -0,0 +1,24 @@
package mocks
import (
"github.com/ethereum/go-ethereum/core/types"
)
type MockLogNoteConverter struct {
err error
returnModels []interface{}
PassedLogs []types.Log
}
func (converter *MockLogNoteConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
converter.PassedLogs = ethLogs
return converter.returnModels, converter.err
}
func (converter *MockLogNoteConverter) SetConverterError(e error) {
converter.err = e
}
func (converter *MockLogNoteConverter) SetReturnModels(models []interface{}) {
converter.returnModels = models
}

View File

@ -48,158 +48,172 @@ import (
)
var (
BiteTransformerInitializer = bite.BiteTransformerInitializer{Config: bite.BiteConfig}.NewBiteTransformer
BiteTransformerInitializer = factories.Transformer{
Config: bite.BiteConfig,
Converter: &bite.BiteConverter{},
Repository: &bite.BiteRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
CatFileChopLumpTransformerInitializer = factories.Transformer{
CatFileChopLumpTransformerInitializer = factories.LogNoteTransformer{
Config: chop_lump.CatFileChopLumpConfig,
Converter: &chop_lump.CatFileChopLumpConverter{},
Repository: &chop_lump.CatFileChopLumpRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
CatFileFlipTransformerInitializer = factories.Transformer{
CatFileFlipTransformerInitializer = factories.LogNoteTransformer{
Config: flip.CatFileFlipConfig,
Converter: &flip.CatFileFlipConverter{},
Repository: &flip.CatFileFlipRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
CatFilePitVowTransformerInitializer = factories.Transformer{
CatFilePitVowTransformerInitializer = factories.LogNoteTransformer{
Config: pit_vow.CatFilePitVowConfig,
Converter: &pit_vow.CatFilePitVowConverter{},
Repository: &pit_vow.CatFilePitVowRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
DealTransformerInitializer = factories.Transformer{
DealTransformerInitializer = factories.LogNoteTransformer{
Config: deal.DealConfig,
Converter: &deal.DealConverter{},
Repository: &deal.DealRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
DentTransformerInitializer = dent.DentTransformerInitializer{Config: dent.DentConfig}.NewDentTransformer
DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer
DripFileIlkTransformerInitializer = factories.Transformer{
DripFileIlkTransformerInitializer = factories.LogNoteTransformer{
Config: ilk2.DripFileIlkConfig,
Converter: &ilk2.DripFileIlkConverter{},
Repository: &ilk2.DripFileIlkRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
DripFileRepoTransformerInitializer = factories.Transformer{
DripFileRepoTransformerInitializer = factories.LogNoteTransformer{
Config: repo.DripFileRepoConfig,
Converter: &repo.DripFileRepoConverter{},
Repository: &repo.DripFileRepoRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
DripFileVowTransfromerInitializer = factories.Transformer{
DripFileVowTransfromerInitializer = factories.LogNoteTransformer{
Config: vow.DripFileVowConfig,
Converter: &vow.DripFileVowConverter{},
Repository: &vow.DripFileVowRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
FlipKickTransformerInitializer = flip_kick.FlipKickTransformerInitializer{Config: flip_kick.FlipKickConfig}.NewFlipKickTransformer
FlogTransformerInitializer = factories.Transformer{
FlogTransformerInitializer = factories.LogNoteTransformer{
Config: flog.FlogConfig,
Converter: &flog.FlogConverter{},
Repository: &flog.FlogRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
FlopKickTransformerInitializer = flop_kick.FlopKickTransformerInitializer{Config: flop_kick.Config}.NewFlopKickTransformer
FrobTransformerInitializer = frob.FrobTransformerInitializer{Config: frob.FrobConfig}.NewFrobTransformer
PitFileDebtCeilingTransformerInitializer = factories.Transformer{
PitFileDebtCeilingTransformerInitializer = factories.LogNoteTransformer{
Config: debt_ceiling.DebtCeilingFileConfig,
Converter: &debt_ceiling.PitFileDebtCeilingConverter{},
Repository: &debt_ceiling.PitFileDebtCeilingRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
PitFileIlkTransformerInitializer = factories.Transformer{
PitFileIlkTransformerInitializer = factories.LogNoteTransformer{
Config: ilk.IlkFileConfig,
Converter: &ilk.PitFileIlkConverter{},
Repository: &ilk.PitFileIlkRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
PitFileStabilityFeeTransformerInitializer = factories.Transformer{
PitFileStabilityFeeTransformerInitializer = factories.LogNoteTransformer{
Config: stability_fee.StabilityFeeFileConfig,
Converter: &stability_fee.PitFileStabilityFeeConverter{},
Repository: &stability_fee.PitFileStabilityFeeRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
PriceFeedTransformerInitializer = factories.Transformer{
PriceFeedTransformerInitializer = factories.LogNoteTransformer{
Config: price_feeds.PriceFeedConfig,
Converter: &price_feeds.PriceFeedConverter{},
Repository: &price_feeds.PriceFeedRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
TendTransformerInitializer = factories.Transformer{
TendTransformerInitializer = factories.LogNoteTransformer{
Config: tend.TendConfig,
Converter: &tend.TendConverter{},
Repository: &tend.TendRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
VatInitTransformerInitializer = factories.Transformer{
VatInitTransformerInitializer = factories.LogNoteTransformer{
Config: vat_init.VatInitConfig,
Converter: &vat_init.VatInitConverter{},
Repository: &vat_init.VatInitRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatGrabTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatGrabTransformerInitializer = factories.LogNoteTransformer{
Config: vat_grab.VatGrabConfig,
Converter: &vat_grab.VatGrabConverter{},
Repository: &vat_grab.VatGrabRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatFoldTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatFoldTransformerInitializer = factories.LogNoteTransformer{
Config: vat_fold.VatFoldConfig,
Converter: &vat_fold.VatFoldConverter{},
Repository: &vat_fold.VatFoldRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatHealTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatHealTransformerInitializer = factories.LogNoteTransformer{
Config: vat_heal.VatHealConfig,
Converter: &vat_heal.VatHealConverter{},
Repository: &vat_heal.VatHealRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatMoveTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatMoveTransformerInitializer = factories.LogNoteTransformer{
Config: vat_move.VatMoveConfig,
Converter: &vat_move.VatMoveConverter{},
Repository: &vat_move.VatMoveRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatSlipTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatSlipTransformerInitializer = factories.LogNoteTransformer{
Config: vat_slip.VatSlipConfig,
Converter: &vat_slip.VatSlipConverter{},
Repository: &vat_slip.VatSlipRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatTollTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatTollTransformerInitializer = factories.LogNoteTransformer{
Config: vat_toll.VatTollConfig,
Converter: &vat_toll.VatTollConverter{},
Repository: &vat_toll.VatTollRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatTuneTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatTuneTransformerInitializer = factories.LogNoteTransformer{
Config: vat_tune.VatTuneConfig,
Converter: &vat_tune.VatTuneConverter{},
Repository: &vat_tune.VatTuneRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
VatFluxTransformerInitializer = factories.Transformer{
}.NewLogNoteTransformer
VatFluxTransformerInitializer = factories.LogNoteTransformer{
Config: vat_flux.VatFluxConfig,
Converter: &vat_flux.VatFluxConverter{},
Repository: &vat_flux.VatFluxRepository{},
Fetcher: &shared.Fetcher{},
}.NewTransformer
}.NewLogNoteTransformer
)
func TransformerInitializers() []shared.TransformerInitializer {

View File

@ -21,7 +21,7 @@ var _ = Describe("Vat flux transformer", func() {
var (
config = vat_flux.VatFluxConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -30,16 +30,16 @@ var _ = Describe("Vat flux transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -35,7 +35,7 @@ var _ = Describe("Vat fold transformer", func() {
var (
config = vat_fold.VatFoldConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -44,16 +44,16 @@ var _ = Describe("Vat fold transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -6,13 +6,12 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_grab"
)
var _ = Describe("Vat grab converter", func() {
var converter factories.Converter
var converter vat_grab.VatGrabConverter
BeforeEach(func() {
converter = vat_grab.VatGrabConverter{}

View File

@ -18,7 +18,7 @@ import (
var _ = Describe("Vat grab transformer", func() {
var (
config = vat_grab.VatGrabConfig
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
fetcher mocks.MockLogFetcher
transformer shared.Transformer
@ -27,13 +27,13 @@ var _ = Describe("Vat grab transformer", func() {
BeforeEach(func() {
repository = mocks.MockRepository{}
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
transformer = factories.Transformer{
converter = mocks.MockLogNoteConverter{}
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -36,20 +36,20 @@ var _ = Describe("VatHeal Transformer", func() {
repository mocks.MockRepository
transformer shared.Transformer
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
config = vat_heal.VatHealConfig
)
BeforeEach(func() {
repository = mocks.MockRepository{}
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
transformer = factories.Transformer{
converter = mocks.MockLogNoteConverter{}
transformer = factories.LogNoteTransformer{
Repository: &repository,
Config: config,
Fetcher: &fetcher,
Converter: &converter,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the database and blockchain", func() {

View File

@ -34,7 +34,7 @@ import (
var _ = Describe("Vat init transformer", func() {
var (
config = vat_init.VatInitConfig
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
fetcher mocks.MockLogFetcher
transformer shared.Transformer
@ -43,17 +43,17 @@ var _ = Describe("Vat init transformer", func() {
)
BeforeEach(func() {
converter = mocks.MockConverter{}
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.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Fetcher: &fetcher,
Converter: &converter,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -34,7 +34,7 @@ import (
var _ = Describe("Vat move transformer", func() {
var config = vat_move.VatMoveConfig
var fetcher mocks.MockLogFetcher
var converter mocks.MockConverter
var converter mocks.MockLogNoteConverter
var repository mocks.MockRepository
var transformer shared.Transformer
var headerOne core.Header
@ -42,16 +42,16 @@ var _ = Describe("Vat move transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -20,7 +20,7 @@ var _ = Describe("Vat slip transformer", func() {
var (
config = vat_slip.VatSlipConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -29,16 +29,16 @@ var _ = Describe("Vat slip transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -21,7 +21,7 @@ var _ = Describe("Vat toll transformer", func() {
var (
config = vat_toll.VatTollConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -30,16 +30,16 @@ var _ = Describe("Vat toll transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {

View File

@ -21,7 +21,7 @@ var _ = Describe("Vat tune transformer", func() {
var (
config = vat_tune.VatTuneConfig
fetcher mocks.MockLogFetcher
converter mocks.MockConverter
converter mocks.MockLogNoteConverter
repository mocks.MockRepository
transformer shared.Transformer
headerOne core.Header
@ -30,16 +30,16 @@ var _ = Describe("Vat tune transformer", func() {
BeforeEach(func() {
fetcher = mocks.MockLogFetcher{}
converter = mocks.MockConverter{}
converter = mocks.MockLogNoteConverter{}
repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.Transformer{
transformer = factories.LogNoteTransformer{
Config: config,
Converter: &converter,
Fetcher: &fetcher,
Repository: &repository,
}.NewTransformer(nil, nil)
}.NewLogNoteTransformer(nil, nil)
})
It("sets the blockchain and database", func() {