forked from cerc-io/ipld-eth-server
Use transformer factory for Vat tune
This commit is contained in:
parent
5682ee988b
commit
78d746bb5b
@ -20,6 +20,8 @@ import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
||||
"github.com/vulcanize/vulcanizedb/test_config"
|
||||
)
|
||||
@ -42,8 +44,13 @@ var _ = Describe("VatTune Transformer", func() {
|
||||
err = persistHeader(rpcClient, db, blockNumber)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
initializer := vat_tune.VatTuneTransformerInitializer{Config: config}
|
||||
transformer := initializer.NewVatTuneTransformer(db, blockchain)
|
||||
initializer := factories.Transformer{
|
||||
Config: config,
|
||||
Fetcher: &shared.Fetcher{},
|
||||
Converter: &vat_tune.VatTuneConverter{},
|
||||
Repository: &vat_tune.VatTuneRepository{},
|
||||
}
|
||||
transformer := initializer.NewTransformer(db, blockchain)
|
||||
err = transformer.Execute()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -3,7 +3,6 @@ package vat_tune
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
||||
)
|
||||
|
||||
type MockVatTuneConverter struct {
|
||||
@ -11,9 +10,9 @@ type MockVatTuneConverter struct {
|
||||
PassedLogs []types.Log
|
||||
}
|
||||
|
||||
func (converter *MockVatTuneConverter) ToModels(ethLogs []types.Log) ([]vat_tune.VatTuneModel, error) {
|
||||
func (converter *MockVatTuneConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
converter.PassedLogs = ethLogs
|
||||
return []vat_tune.VatTuneModel{test_data.VatTuneModel}, converter.err
|
||||
return []interface{}{test_data.VatTuneModel}, converter.err
|
||||
}
|
||||
|
||||
func (converter *MockVatTuneConverter) SetConverterError(e error) {
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type MockVatTuneRepository struct {
|
||||
@ -16,10 +16,11 @@ type MockVatTuneRepository struct {
|
||||
PassedStartingBlockNumber int64
|
||||
PassedEndingBlockNumber int64
|
||||
PassedHeaderID int64
|
||||
PassedModels []vat_tune.VatTuneModel
|
||||
PassedModels []interface{}
|
||||
SetDbCalled bool
|
||||
}
|
||||
|
||||
func (repository *MockVatTuneRepository) Create(headerID int64, models []vat_tune.VatTuneModel) error {
|
||||
func (repository *MockVatTuneRepository) Create(headerID int64, models []interface{}) error {
|
||||
repository.PassedHeaderID = headerID
|
||||
repository.PassedModels = models
|
||||
return repository.createErr
|
||||
@ -36,6 +37,10 @@ func (repository *MockVatTuneRepository) MissingHeaders(startingBlockNumber, end
|
||||
return repository.missingHeaders, repository.missingHeadersErr
|
||||
}
|
||||
|
||||
func (repository *MockVatTuneRepository) SetDB(db *postgres.DB) {
|
||||
repository.SetDbCalled = true
|
||||
}
|
||||
|
||||
func (repository *MockVatTuneRepository) SetMissingHeadersErr(e error) {
|
||||
repository.missingHeadersErr = e
|
||||
}
|
||||
|
@ -126,7 +126,12 @@ var (
|
||||
}.NewTransformer
|
||||
VatSlipTransformerInitializer = vat_slip.VatSlipTransformerInitializer{Config: vat_slip.VatSlipConfig}.NewVatSlipTransformer
|
||||
VatTollTransformerInitializer = vat_toll.VatTollTransformerInitializer{Config: vat_toll.VatTollConfig}.NewVatTollTransformer
|
||||
VatTuneTransformerInitializer = vat_tune.VatTuneTransformerInitializer{Config: vat_tune.VatTuneConfig}.NewVatTuneTransformer
|
||||
VatTuneTransformerInitializer = factories.Transformer{
|
||||
Config: vat_tune.VatTuneConfig,
|
||||
Converter: &vat_tune.VatTuneConverter{},
|
||||
Repository: &vat_tune.VatTuneRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
VatFluxTransformerInitializer = vat_flux.VatFluxTransformerInitializer{Config: vat_flux.VatFluxConfig}.NewVatFluxTransformer
|
||||
)
|
||||
|
||||
|
@ -2,10 +2,11 @@ package vat_tune
|
||||
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var VatTuneConfig = shared.TransformerConfig{
|
||||
var VatTuneConfig = shared.SingleTransformerConfig{
|
||||
TransformerName: shared.VatTuneLabel,
|
||||
ContractAddresses: []string{shared.VatContractAddress},
|
||||
ContractAbi: shared.VatABI,
|
||||
Topics: []string{shared.VatTuneSignature},
|
||||
Topic: shared.VatTuneSignature,
|
||||
StartingBlockNumber: 0,
|
||||
EndingBlockNumber: 10000000,
|
||||
}
|
||||
|
@ -12,14 +12,10 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type Converter interface {
|
||||
ToModels(ethLogs []types.Log) ([]VatTuneModel, error)
|
||||
}
|
||||
|
||||
type VatTuneConverter struct{}
|
||||
|
||||
func (VatTuneConverter) ToModels(ethLogs []types.Log) ([]VatTuneModel, error) {
|
||||
var models []VatTuneModel
|
||||
func (VatTuneConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
err := verifyLog(ethLog)
|
||||
if err != nil {
|
||||
@ -31,9 +27,9 @@ func (VatTuneConverter) ToModels(ethLogs []types.Log) ([]VatTuneModel, error) {
|
||||
wBytes := shared.GetDataBytesAtIndex(-3, ethLog.Data)
|
||||
w := common.BytesToAddress(wBytes)
|
||||
dinkBytes := shared.GetDataBytesAtIndex(-2, ethLog.Data)
|
||||
dink := big.NewInt(0).SetBytes(dinkBytes).String()
|
||||
dink := big.NewInt(0).SetBytes(dinkBytes)
|
||||
dartBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data)
|
||||
dart := big.NewInt(0).SetBytes(dartBytes).String()
|
||||
dart := big.NewInt(0).SetBytes(dartBytes)
|
||||
|
||||
raw, err := json.Marshal(ethLog)
|
||||
if err != nil {
|
||||
@ -44,8 +40,8 @@ func (VatTuneConverter) ToModels(ethLogs []types.Log) ([]VatTuneModel, error) {
|
||||
Urn: urn.String(),
|
||||
V: v.String(),
|
||||
W: w.String(),
|
||||
Dink: dink,
|
||||
Dart: dart,
|
||||
Dink: dink.String(),
|
||||
Dart: dart.String(),
|
||||
TransactionIndex: ethLog.TxIndex,
|
||||
LogIndex: ethLog.Index,
|
||||
Raw: raw,
|
||||
|
@ -1,36 +1,30 @@
|
||||
package vat_tune
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(headerID int64, models []VatTuneModel) error
|
||||
MarkHeaderChecked(headerID int64) error
|
||||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
|
||||
}
|
||||
|
||||
type VatTuneRepository struct {
|
||||
db *postgres.DB
|
||||
}
|
||||
|
||||
func NewVatTuneRepository(db *postgres.DB) VatTuneRepository {
|
||||
return VatTuneRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (repository VatTuneRepository) Create(headerID int64, models []VatTuneModel) error {
|
||||
func (repository VatTuneRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, model := range models {
|
||||
vatTune, ok := model.(VatTuneModel)
|
||||
if !ok {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("model of type %T, not %T", model, VatTuneModel{})
|
||||
}
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.vat_tune (header_id, ilk, urn, v, w, dink, dart, tx_idx, log_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10)`,
|
||||
headerID, model.Ilk, model.Urn, model.V, model.W, model.Dink, model.Dart, model.TransactionIndex, model.LogIndex, model.Raw,
|
||||
headerID, vatTune.Ilk, vatTune.Urn, vatTune.V, vatTune.W, vatTune.Dink, vatTune.Dart, vatTune.TransactionIndex, vatTune.LogIndex, vatTune.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
@ -72,3 +66,7 @@ func (repository VatTuneRepository) MissingHeaders(startingBlockNumber, endingBl
|
||||
)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (repository *VatTuneRepository) SetDB(db *postgres.DB) {
|
||||
repository.db = db
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
var _ = Describe("Vat tune repository", func() {
|
||||
var (
|
||||
db *postgres.DB
|
||||
vatTuneRepository vat_tune.Repository
|
||||
vatTuneRepository vat_tune.VatTuneRepository
|
||||
err error
|
||||
headerRepository datastore.HeaderRepository
|
||||
)
|
||||
@ -28,7 +28,8 @@ var _ = Describe("Vat tune repository", func() {
|
||||
db = test_config.NewTestDB(core.Node{})
|
||||
test_config.CleanTestDB(db)
|
||||
headerRepository = repositories.NewHeaderRepository(db)
|
||||
vatTuneRepository = vat_tune.NewVatTuneRepository(db)
|
||||
vatTuneRepository = vat_tune.VatTuneRepository{}
|
||||
vatTuneRepository.SetDB(db)
|
||||
})
|
||||
|
||||
Describe("Create", func() {
|
||||
@ -40,7 +41,7 @@ var _ = Describe("Vat tune repository", func() {
|
||||
})
|
||||
|
||||
It("adds a vat tune event", func() {
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var dbVatTune vat_tune.VatTuneModel
|
||||
@ -58,7 +59,7 @@ var _ = Describe("Vat tune repository", func() {
|
||||
})
|
||||
|
||||
It("marks header as checked for logs", func() {
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var headerChecked bool
|
||||
@ -70,7 +71,7 @@ var _ = Describe("Vat tune repository", func() {
|
||||
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 = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
var headerChecked bool
|
||||
@ -80,28 +81,28 @@ var _ = Describe("Vat tune repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate pit file vat_tune events", func() {
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||
})
|
||||
|
||||
It("allows for multiple flop kick events in one transaction if they have different log indexes", func() {
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
newVatTune := test_data.VatTuneModel
|
||||
newVatTune.LogIndex = newVatTune.LogIndex + 1
|
||||
err := vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{newVatTune})
|
||||
err := vatTuneRepository.Create(headerID, []interface{}{newVatTune})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("removes pit file vat_tune if corresponding header is deleted", func() {
|
||||
err = vatTuneRepository.Create(headerID, []vat_tune.VatTuneModel{test_data.VatTuneModel})
|
||||
err = vatTuneRepository.Create(headerID, []interface{}{test_data.VatTuneModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||
@ -198,8 +199,8 @@ var _ = Describe("Vat tune repository", func() {
|
||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
vatTuneRepository := vat_tune.NewVatTuneRepository(db)
|
||||
vatTuneRepositoryTwo := vat_tune.NewVatTuneRepository(dbTwo)
|
||||
vatTuneRepositoryTwo := vat_tune.VatTuneRepository{}
|
||||
vatTuneRepositoryTwo.SetDB(dbTwo)
|
||||
err := vatTuneRepository.MarkHeaderChecked(headerIDs[0])
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
package vat_tune
|
||||
|
||||
import (
|
||||
"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"
|
||||
"log"
|
||||
)
|
||||
|
||||
type VatTuneTransformerInitializer struct {
|
||||
Config shared.TransformerConfig
|
||||
}
|
||||
|
||||
func (initializer VatTuneTransformerInitializer) NewVatTuneTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
|
||||
converter := VatTuneConverter{}
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
repository := NewVatTuneRepository(db)
|
||||
return VatTuneTransformer{
|
||||
Config: initializer.Config,
|
||||
Converter: converter,
|
||||
Fetcher: fetcher,
|
||||
Repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
type VatTuneTransformer struct {
|
||||
Config shared.TransformerConfig
|
||||
Converter Converter
|
||||
Fetcher shared.LogFetcher
|
||||
Repository Repository
|
||||
}
|
||||
|
||||
func (transformer VatTuneTransformer) Execute() error {
|
||||
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("Fetching vat tune event logs for %d headers \n", len(missingHeaders))
|
||||
for _, header := range missingHeaders {
|
||||
topics := [][]common.Hash{{common.HexToHash(shared.VatTuneSignature)}}
|
||||
matchingLogs, err := transformer.Fetcher.FetchLogs(VatTuneConfig.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
|
||||
}
|
@ -8,38 +8,53 @@ import (
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
||||
"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"
|
||||
vat_tune_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/vat_tune"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
var _ = Describe("Vat tune transformer", func() {
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Config: vat_tune.VatTuneConfig,
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vat_tune_mocks.MockVatTuneConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
var config = vat_tune.VatTuneConfig
|
||||
var fetcher mocks.MockLogFetcher
|
||||
var converter vat_tune_mocks.MockVatTuneConverter
|
||||
var repository vat_tune_mocks.MockVatTuneRepository
|
||||
var transformer shared.Transformer
|
||||
var headerOne core.Header
|
||||
var headerTwo core.Header
|
||||
|
||||
BeforeEach(func() {
|
||||
fetcher = mocks.MockLogFetcher{}
|
||||
converter = vat_tune_mocks.MockVatTuneConverter{}
|
||||
repository = vat_tune_mocks.MockVatTuneRepository{}
|
||||
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
|
||||
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
|
||||
transformer = factories.Transformer{
|
||||
Config: config,
|
||||
Converter: &converter,
|
||||
Fetcher: &fetcher,
|
||||
Repository: &repository,
|
||||
}.NewTransformer(nil, nil)
|
||||
})
|
||||
|
||||
It("sets the blockchain and database", func() {
|
||||
Expect(fetcher.SetBcCalled).To(BeTrue())
|
||||
Expect(repository.SetDbCalled).To(BeTrue())
|
||||
})
|
||||
|
||||
It("gets missing headers for block numbers specified in config", func() {
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(vat_tune.VatTuneConfig.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(vat_tune.VatTuneConfig.EndingBlockNumber))
|
||||
Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
|
||||
Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for missing headers", func() {
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: &mocks.MockLogFetcher{},
|
||||
Converter: &vat_tune_mocks.MockVatTuneConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -48,33 +63,19 @@ var _ = Describe("Vat tune transformer", func() {
|
||||
})
|
||||
|
||||
It("fetches logs for missing headers", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &vat_tune_mocks.MockVatTuneConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{vat_tune.VatTuneConfig.ContractAddresses, vat_tune.VatTuneConfig.ContractAddresses}))
|
||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.VatTuneSignature)}}))
|
||||
})
|
||||
|
||||
It("returns error if fetcher returns error", func() {
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetcherError(fakes.FakeError)
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: &vat_tune_mocks.MockVatTuneConverter{},
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -83,34 +84,17 @@ var _ = Describe("Vat tune transformer", func() {
|
||||
})
|
||||
|
||||
It("marks header checked if no logs returned", func() {
|
||||
mockConverter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
mockRepository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
headerID := int64(123)
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
||||
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||
})
|
||||
|
||||
It("returns error if marking header checked returns err", func() {
|
||||
mockConverter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
mockRepository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
mockFetcher := &mocks.MockLogFetcher{}
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Converter: mockConverter,
|
||||
Fetcher: mockFetcher,
|
||||
Repository: mockRepository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -119,16 +103,8 @@ var _ = Describe("Vat tune transformer", func() {
|
||||
})
|
||||
|
||||
It("converts matching logs", func() {
|
||||
converter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatTuneLog})
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -137,17 +113,9 @@ var _ = Describe("Vat tune transformer", func() {
|
||||
})
|
||||
|
||||
It("returns error if converter returns error", func() {
|
||||
converter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
converter.SetConverterError(fakes.FakeError)
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatTuneLog})
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
@ -156,37 +124,20 @@ var _ = Describe("Vat tune transformer", func() {
|
||||
})
|
||||
|
||||
It("persists vat tune model", func() {
|
||||
converter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatTuneLog})
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]vat_tune.VatTuneModel{test_data.VatTuneModel}))
|
||||
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.VatTuneModel}))
|
||||
})
|
||||
|
||||
It("returns error if repository returns error for create", func() {
|
||||
converter := &vat_tune_mocks.MockVatTuneConverter{}
|
||||
fetcher := &mocks.MockLogFetcher{}
|
||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthVatTuneLog})
|
||||
repository := &vat_tune_mocks.MockVatTuneRepository{}
|
||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
||||
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||
repository.SetCreateError(fakes.FakeError)
|
||||
transformer := vat_tune.VatTuneTransformer{
|
||||
Fetcher: fetcher,
|
||||
Converter: converter,
|
||||
Repository: repository,
|
||||
}
|
||||
|
||||
err := transformer.Execute()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user