Rename Flog pack to Vow flog

- enables differentiation if another contract implements flog
- also deletes flog-specific mocks
This commit is contained in:
Rob Mulholand 2018-10-26 14:31:02 -05:00
parent 1b680d2a4b
commit ed624330f6
14 changed files with 78 additions and 180 deletions

View File

@ -97,7 +97,7 @@ func buildTransformerInitializerMap() map[string]shared2.TransformerInitializer
transformerInitializerMap[shared2.DripFileRepoLabel] = transformers.DripFileRepoTransformerInitializer transformerInitializerMap[shared2.DripFileRepoLabel] = transformers.DripFileRepoTransformerInitializer
transformerInitializerMap[shared2.DripFileVowLabel] = transformers.DripFileVowTransfromerInitializer transformerInitializerMap[shared2.DripFileVowLabel] = transformers.DripFileVowTransfromerInitializer
transformerInitializerMap[shared2.FlipKickLabel] = transformers.FlipKickTransformerInitializer transformerInitializerMap[shared2.FlipKickLabel] = transformers.FlipKickTransformerInitializer
transformerInitializerMap[shared2.FlogLabel] = transformers.FlogTransformerInitializer transformerInitializerMap[shared2.VowFlogLabel] = transformers.FlogTransformerInitializer
transformerInitializerMap[shared2.FlopKickLabel] = transformers.FlopKickTransformerInitializer transformerInitializerMap[shared2.FlopKickLabel] = transformers.FlopKickTransformerInitializer
transformerInitializerMap[shared2.FrobLabel] = transformers.FrobTransformerInitializer transformerInitializerMap[shared2.FrobLabel] = transformers.FrobTransformerInitializer
transformerInitializerMap[shared2.PitFileDebtCeilingLabel] = transformers.PitFileDebtCeilingTransformerInitializer transformerInitializerMap[shared2.PitFileDebtCeilingLabel] = transformers.PitFileDebtCeilingTransformerInitializer

View File

@ -50,7 +50,7 @@ var (
VatContractAddress = getContractValue("contract.vat", "0xcd726790550afcd77e9a7a47e86a3f9010af126b") VatContractAddress = getContractValue("contract.vat", "0xcd726790550afcd77e9a7a47e86a3f9010af126b")
VowContractAddress = getContractValue("contract.vow", "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1") VowContractAddress = getContractValue("contract.vow", "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1")
//TODO: get pit and drip file method signatures directly from the ABI //TODO: get cat, pit, and drip file method signatures directly from the ABI
biteMethod = GetSolidityMethodSignature(CatABI, "Bite") biteMethod = GetSolidityMethodSignature(CatABI, "Bite")
catFileChopLumpMethod = "file(bytes32,bytes32,uint256)" catFileChopLumpMethod = "file(bytes32,bytes32,uint256)"
catFileFlipMethod = GetSolidityMethodSignature(CatABI, "file") catFileFlipMethod = GetSolidityMethodSignature(CatABI, "file")
@ -62,7 +62,6 @@ var (
dripFileRepoMethod = GetSolidityMethodSignature(DripABI, "file") dripFileRepoMethod = GetSolidityMethodSignature(DripABI, "file")
dripFileVowMethod = "file(bytes32,bytes32)" dripFileVowMethod = "file(bytes32,bytes32)"
flipKickMethod = GetSolidityMethodSignature(FlipperABI, "Kick") flipKickMethod = GetSolidityMethodSignature(FlipperABI, "Kick")
flogMethod = GetSolidityMethodSignature(VowABI, "flog")
flopKickMethod = GetSolidityMethodSignature(FlopperABI, "Kick") flopKickMethod = GetSolidityMethodSignature(FlopperABI, "Kick")
frobMethod = GetSolidityMethodSignature(PitABI, "Frob") frobMethod = GetSolidityMethodSignature(PitABI, "Frob")
logValueMethod = GetSolidityMethodSignature(MedianizerABI, "LogValue") logValueMethod = GetSolidityMethodSignature(MedianizerABI, "LogValue")
@ -70,28 +69,28 @@ var (
pitFileIlkMethod = "file(bytes32,bytes32,uint256)" pitFileIlkMethod = "file(bytes32,bytes32,uint256)"
pitFileStabilityFeeMethod = GetSolidityMethodSignature(PitABI, "file") pitFileStabilityFeeMethod = GetSolidityMethodSignature(PitABI, "file")
tendMethod = GetSolidityMethodSignature(FlipperABI, "tend") tendMethod = GetSolidityMethodSignature(FlipperABI, "tend")
vatHealMethod = GetSolidityMethodSignature(VatABI, "heal") vatFluxMethod = GetSolidityMethodSignature(VatABI, "flux")
vatFoldMethod = GetSolidityMethodSignature(VatABI, "fold")
vatGrabMethod = GetSolidityMethodSignature(VatABI, "grab") vatGrabMethod = GetSolidityMethodSignature(VatABI, "grab")
vatHealMethod = GetSolidityMethodSignature(VatABI, "heal")
vatInitMethod = GetSolidityMethodSignature(VatABI, "init") vatInitMethod = GetSolidityMethodSignature(VatABI, "init")
vatMoveMethod = GetSolidityMethodSignature(VatABI, "move") vatMoveMethod = GetSolidityMethodSignature(VatABI, "move")
vatFoldMethod = GetSolidityMethodSignature(VatABI, "fold")
vatSlipMethod = GetSolidityMethodSignature(VatABI, "slip") vatSlipMethod = GetSolidityMethodSignature(VatABI, "slip")
vatTollMethod = GetSolidityMethodSignature(VatABI, "toll") vatTollMethod = GetSolidityMethodSignature(VatABI, "toll")
vatTuneMethod = GetSolidityMethodSignature(VatABI, "tune") vatTuneMethod = GetSolidityMethodSignature(VatABI, "tune")
vatFluxMethod = GetSolidityMethodSignature(VatABI, "flux") vowFlogMethod = GetSolidityMethodSignature(VowABI, "flog")
BiteSignature = GetEventSignature(biteMethod) BiteSignature = GetEventSignature(biteMethod)
DealSignature = GetLogNoteSignature(dealMethod)
CatFileChopLumpSignature = GetLogNoteSignature(catFileChopLumpMethod) CatFileChopLumpSignature = GetLogNoteSignature(catFileChopLumpMethod)
CatFileFlipSignature = GetLogNoteSignature(catFileFlipMethod) CatFileFlipSignature = GetLogNoteSignature(catFileFlipMethod)
CatFilePitVowSignature = GetLogNoteSignature(catFilePitVowMethod) CatFilePitVowSignature = GetLogNoteSignature(catFilePitVowMethod)
DealSignature = GetLogNoteSignature(dealMethod)
DentFunctionSignature = GetLogNoteSignature(dentMethod) DentFunctionSignature = GetLogNoteSignature(dentMethod)
DripDripSignature = GetLogNoteSignature(dripDripMethod) DripDripSignature = GetLogNoteSignature(dripDripMethod)
DripFileIlkSignature = GetLogNoteSignature(dripFileIlkMethod) DripFileIlkSignature = GetLogNoteSignature(dripFileIlkMethod)
DripFileRepoSignature = GetLogNoteSignature(dripFileRepoMethod) DripFileRepoSignature = GetLogNoteSignature(dripFileRepoMethod)
DripFileVowSignature = GetLogNoteSignature(dripFileVowMethod) DripFileVowSignature = GetLogNoteSignature(dripFileVowMethod)
FlipKickSignature = GetEventSignature(flipKickMethod) FlipKickSignature = GetEventSignature(flipKickMethod)
FlogSignature = GetLogNoteSignature(flogMethod)
FlopKickSignature = GetEventSignature(flopKickMethod) FlopKickSignature = GetEventSignature(flopKickMethod)
FrobSignature = GetEventSignature(frobMethod) FrobSignature = GetEventSignature(frobMethod)
LogValueSignature = GetEventSignature(logValueMethod) LogValueSignature = GetEventSignature(logValueMethod)
@ -99,28 +98,28 @@ var (
PitFileIlkSignature = GetLogNoteSignature(pitFileIlkMethod) PitFileIlkSignature = GetLogNoteSignature(pitFileIlkMethod)
PitFileStabilityFeeSignature = GetLogNoteSignature(pitFileStabilityFeeMethod) PitFileStabilityFeeSignature = GetLogNoteSignature(pitFileStabilityFeeMethod)
TendFunctionSignature = GetLogNoteSignature(tendMethod) TendFunctionSignature = GetLogNoteSignature(tendMethod)
VatHealSignature = GetLogNoteSignature(vatHealMethod) VatFluxSignature = GetLogNoteSignature(vatFluxMethod)
VatFoldSignature = GetLogNoteSignature(vatFoldMethod)
VatGrabSignature = GetLogNoteSignature(vatGrabMethod) VatGrabSignature = GetLogNoteSignature(vatGrabMethod)
VatHealSignature = GetLogNoteSignature(vatHealMethod)
VatInitSignature = GetLogNoteSignature(vatInitMethod) VatInitSignature = GetLogNoteSignature(vatInitMethod)
VatMoveSignature = GetLogNoteSignature(vatMoveMethod) VatMoveSignature = GetLogNoteSignature(vatMoveMethod)
VatFoldSignature = GetLogNoteSignature(vatFoldMethod)
VatSlipSignature = GetLogNoteSignature(vatSlipMethod) VatSlipSignature = GetLogNoteSignature(vatSlipMethod)
VatTollSignature = GetLogNoteSignature(vatTollMethod) VatTollSignature = GetLogNoteSignature(vatTollMethod)
VatTuneSignature = GetLogNoteSignature(vatTuneMethod) VatTuneSignature = GetLogNoteSignature(vatTuneMethod)
VatFluxSignature = GetLogNoteSignature(vatFluxMethod) VowFlogSignature = GetLogNoteSignature(vowFlogMethod)
BiteLabel = "bite" BiteLabel = "bite"
DealLabel = "deal"
CatFileChopLumpLabel = "catFileChopLump" CatFileChopLumpLabel = "catFileChopLump"
CatFileFlipLabel = "catFileFlip" CatFileFlipLabel = "catFileFlip"
CatFilePitVowLabel = "catFilePitVow" CatFilePitVowLabel = "catFilePitVow"
DealLabel = "deal"
DentLabel = "dent" DentLabel = "dent"
DripDripLabel = "dripDrip" DripDripLabel = "dripDrip"
DripFileIlkLabel = "dripFileIlk" DripFileIlkLabel = "dripFileIlk"
DripFileRepoLabel = "dripFileRepo" DripFileRepoLabel = "dripFileRepo"
DripFileVowLabel = "dripFileVow" DripFileVowLabel = "dripFileVow"
FlipKickLabel = "flipKick" FlipKickLabel = "flipKick"
FlogLabel = "flog"
FlopKickLabel = "flopKick" FlopKickLabel = "flopKick"
FrobLabel = "frob" FrobLabel = "frob"
PitFileDebtCeilingLabel = "pitFileDebtCeiling" PitFileDebtCeilingLabel = "pitFileDebtCeiling"
@ -128,13 +127,14 @@ var (
PitFileStabilityFeeLabel = "pitFileStabilityFee" PitFileStabilityFeeLabel = "pitFileStabilityFee"
PriceFeedLabel = "priceFeed" PriceFeedLabel = "priceFeed"
TendLabel = "tend" TendLabel = "tend"
VatHealLabel = "vatHeal" VatFluxLabel = "vatFlux"
VatFoldLabel = "vatFold"
VatGrabLabel = "vatGrab" VatGrabLabel = "vatGrab"
VatHealLabel = "vatHeal"
VatInitLabel = "vatInit" VatInitLabel = "vatInit"
VatMoveLabel = "vatMove" VatMoveLabel = "vatMove"
VatFoldLabel = "vatFold"
VatSlipLabel = "vatSlip" VatSlipLabel = "vatSlip"
VatTollLabel = "vatToll" VatTollLabel = "vatToll"
VatTuneLabel = "vatTune" VatTuneLabel = "vatTune"
VatFluxLabel = "vatFlux" VowFlogLabel = "vowFlog"
) )

View File

@ -1,34 +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 flog
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)
type MockFlogConverter struct {
converterError error
PassedLogs []types.Log
}
func (converter *MockFlogConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
converter.PassedLogs = ethLogs
return []interface{}{test_data.FlogModel}, converter.converterError
}
func (converter *MockFlogConverter) SetConverterError(e error) {
converter.converterError = e
}

View File

@ -1,70 +0,0 @@
// Copyright 2018 Vulcanize
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package flog
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
type MockFlogRepository struct {
createError error
missingHeaders []core.Header
missingHeadersError error
PassedStartingBlockNumber int64
PassedEndingBlockNumber int64
PassedHeaderID int64
PassedModels []interface{}
CheckedHeaderIDs []int64
CheckedHeaderError error
SetDbCalled bool
}
func (repository *MockFlogRepository) Create(headerID int64, models []interface{}) error {
repository.PassedHeaderID = headerID
repository.PassedModels = models
return repository.createError
}
func (repository *MockFlogRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
repository.PassedStartingBlockNumber = startingBlockNumber
repository.PassedEndingBlockNumber = endingBlockNumber
return repository.missingHeaders, repository.missingHeadersError
}
func (repository *MockFlogRepository) SetMissingHeadersError(e error) {
repository.missingHeadersError = e
}
func (repository *MockFlogRepository) SetMissingHeaders(headers []core.Header) {
repository.missingHeaders = headers
}
func (repository *MockFlogRepository) SetCreateError(e error) {
repository.createError = e
}
func (repository *MockFlogRepository) MarkHeaderChecked(headerId int64) error {
repository.CheckedHeaderIDs = append(repository.CheckedHeaderIDs, headerId)
return repository.CheckedHeaderError
}
func (repository *MockFlogRepository) SetCheckedHeaderError(e error) {
repository.CheckedHeaderError = e
}
func (repository *MockFlogRepository) SetDB(db *postgres.DB) {
repository.SetDbCalled = true
}

View File

@ -19,7 +19,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flog" "github.com/vulcanize/vulcanizedb/pkg/transformers/vow_flog"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
@ -42,7 +42,7 @@ var EthFlogLog = types.Log{
} }
var rawFlogLog, _ = json.Marshal(EthFlogLog) var rawFlogLog, _ = json.Marshal(EthFlogLog)
var FlogModel = flog.FlogModel{ var FlogModel = vow_flog.VowFlogModel{
Era: "1337", Era: "1337",
LogIndex: EthFlogLog.Index, LogIndex: EthFlogLog.Index,
TransactionIndex: EthFlogLog.TxIndex, TransactionIndex: EthFlogLog.TxIndex,

View File

@ -27,7 +27,6 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow" "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories" "github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flog"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flop_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/flop_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/frob" "github.com/vulcanize/vulcanizedb/pkg/transformers/frob"
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
@ -45,6 +44,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip" "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll" "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_toll"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune" "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vow_flog"
) )
var ( var (
@ -120,9 +120,9 @@ var (
FlipKickTransformerInitializer = flip_kick.FlipKickTransformerInitializer{Config: flip_kick.FlipKickConfig}.NewFlipKickTransformer FlipKickTransformerInitializer = flip_kick.FlipKickTransformerInitializer{Config: flip_kick.FlipKickConfig}.NewFlipKickTransformer
FlogTransformerInitializer = factories.LogNoteTransformer{ FlogTransformerInitializer = factories.LogNoteTransformer{
Config: flog.FlogConfig, Config: vow_flog.VowFlogConfig,
Converter: &flog.FlogConverter{}, Converter: &vow_flog.VowFlogConverter{},
Repository: &flog.FlogRepository{}, Repository: &vow_flog.VowFlogRepository{},
Fetcher: &shared.Fetcher{}, Fetcher: &shared.Fetcher{},
}.NewLogNoteTransformer }.NewLogNoteTransformer

View File

@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog package vow_flog
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var FlogConfig = shared.SingleTransformerConfig{ var VowFlogConfig = shared.SingleTransformerConfig{
TransformerName: shared.FlogLabel, TransformerName: shared.VowFlogLabel,
ContractAddresses: []string{shared.VowContractAddress}, ContractAddresses: []string{shared.VowContractAddress},
ContractAbi: shared.VowABI, ContractAbi: shared.VowABI,
Topic: shared.FlogSignature, Topic: shared.VowFlogSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog package vow_flog
import ( import (
"encoding/json" "encoding/json"
@ -22,9 +22,9 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
type FlogConverter struct{} type VowFlogConverter struct{}
func (FlogConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { func (VowFlogConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
var models []interface{} var models []interface{}
for _, ethLog := range ethLogs { for _, ethLog := range ethLogs {
err := verifyLog(ethLog) err := verifyLog(ethLog)
@ -38,7 +38,7 @@ func (FlogConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
model := FlogModel{ model := VowFlogModel{
Era: era.String(), Era: era.String(),
LogIndex: ethLog.Index, LogIndex: ethLog.Index,
TransactionIndex: ethLog.TxIndex, TransactionIndex: ethLog.TxIndex,

View File

@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog_test package vow_flog_test
import ( import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flog" "github.com/vulcanize/vulcanizedb/pkg/transformers/vow_flog"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
) )
var _ = Describe("Flog converter", func() { var _ = Describe("Vow flog converter", func() {
var converter flog.FlogConverter var converter vow_flog.VowFlogConverter
BeforeEach(func() { BeforeEach(func() {
converter = flog.FlogConverter{} converter = vow_flog.VowFlogConverter{}
}) })
It("returns err if log is missing topics", func() { It("returns err if log is missing topics", func() {
@ -53,6 +53,6 @@ var _ = Describe("Flog converter", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(len(models)).To(Equal(1)) Expect(len(models)).To(Equal(1))
Expect(models[0].(flog.FlogModel)).To(Equal(test_data.FlogModel)) Expect(models[0].(vow_flog.VowFlogModel)).To(Equal(test_data.FlogModel))
}) })
}) })

View File

@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog package vow_flog
type FlogModel struct { type VowFlogModel struct {
Era string Era string
LogIndex uint `db:"log_idx"` LogIndex uint `db:"log_idx"`
TransactionIndex uint `db:"tx_idx"` TransactionIndex uint `db:"tx_idx"`

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog package vow_flog
import ( import (
"fmt" "fmt"
@ -20,21 +20,21 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
) )
type FlogRepository struct { type VowFlogRepository struct {
db *postgres.DB db *postgres.DB
} }
func (repository FlogRepository) Create(headerID int64, models []interface{}) error { func (repository VowFlogRepository) Create(headerID int64, models []interface{}) error {
tx, err := repository.db.Begin() tx, err := repository.db.Begin()
if err != nil { if err != nil {
return err return err
} }
for _, model := range models { for _, model := range models {
flog, ok := model.(FlogModel) flog, ok := model.(VowFlogModel)
if !ok { if !ok {
tx.Rollback() tx.Rollback()
return fmt.Errorf("model of type %T, not %T", model, FlogModel{}) return fmt.Errorf("model of type %T, not %T", model, VowFlogModel{})
} }
_, err = tx.Exec( _, err = tx.Exec(
@ -60,7 +60,7 @@ func (repository FlogRepository) Create(headerID int64, models []interface{}) er
return tx.Commit() return tx.Commit()
} }
func (repository FlogRepository) MarkHeaderChecked(headerID int64) error { func (repository VowFlogRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, vow_flog_checked) _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, vow_flog_checked)
VALUES ($1, $2) VALUES ($1, $2)
ON CONFLICT (header_id) DO ON CONFLICT (header_id) DO
@ -68,7 +68,7 @@ func (repository FlogRepository) MarkHeaderChecked(headerID int64) error {
return err return err
} }
func (repository FlogRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository VowFlogRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header var result []core.Header
err := repository.db.Select( err := repository.db.Select(
&result, &result,
@ -85,6 +85,6 @@ func (repository FlogRepository) MissingHeaders(startingBlockNumber, endingBlock
return result, err return result, err
} }
func (repository *FlogRepository) SetDB(db *postgres.DB) { func (repository *VowFlogRepository) SetDB(db *postgres.DB) {
repository.db = db repository.db = db
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog_test package vow_flog_test
import ( import (
"database/sql" "database/sql"
@ -26,15 +26,15 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flog"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vow_flog"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
) )
var _ = Describe("Flog repository", func() { var _ = Describe("Vow flog repository", func() {
var ( var (
db *postgres.DB db *postgres.DB
flogRepository flog.FlogRepository flogRepository vow_flog.VowFlogRepository
err error err error
headerRepository datastore.HeaderRepository headerRepository datastore.HeaderRepository
) )
@ -43,7 +43,7 @@ var _ = Describe("Flog repository", func() {
db = test_config.NewTestDB(core.Node{}) db = test_config.NewTestDB(core.Node{})
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
headerRepository = repositories.NewHeaderRepository(db) headerRepository = repositories.NewHeaderRepository(db)
flogRepository = flog.FlogRepository{} flogRepository = vow_flog.VowFlogRepository{}
flogRepository.SetDB(db) flogRepository.SetDB(db)
}) })
@ -55,11 +55,11 @@ var _ = Describe("Flog repository", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
It("adds a flog event", func() { It("adds a vow flog event", func() {
err = flogRepository.Create(headerID, []interface{}{test_data.FlogModel}) err = flogRepository.Create(headerID, []interface{}{test_data.FlogModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
var dbFlog flog.FlogModel var dbFlog vow_flog.VowFlogModel
err = db.Get(&dbFlog, `SELECT era, log_idx, tx_idx, raw_log FROM maker.vow_flog WHERE header_id = $1`, headerID) err = db.Get(&dbFlog, `SELECT era, log_idx, tx_idx, raw_log FROM maker.vow_flog WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(dbFlog.Era).To(Equal(test_data.FlogModel.Era)) Expect(dbFlog.Era).To(Equal(test_data.FlogModel.Era))
@ -91,7 +91,7 @@ var _ = Describe("Flog repository", func() {
Expect(headerChecked).To(BeTrue()) Expect(headerChecked).To(BeTrue())
}) })
It("does not duplicate flog events", func() { It("does not duplicate vow flog events", func() {
err = flogRepository.Create(headerID, []interface{}{test_data.FlogModel}) err = flogRepository.Create(headerID, []interface{}{test_data.FlogModel})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -100,11 +100,11 @@ var _ = Describe("Flog repository", func() {
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint")) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
}) })
It("removes flog events if corresponding header is deleted", func() { It("removes vow flog events if corresponding header is deleted", func() {
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID) _, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
var dbFlog flog.FlogModel var dbFlog vow_flog.VowFlogModel
err = db.Get(&dbFlog, `SELECT era, log_idx, tx_idx, raw_log FROM maker.vow_flog WHERE header_id = $1`, headerID) err = db.Get(&dbFlog, `SELECT era, log_idx, tx_idx, raw_log FROM maker.vow_flog WHERE header_id = $1`, headerID)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows)) Expect(err).To(MatchError(sql.ErrNoRows))
@ -181,7 +181,7 @@ var _ = Describe("Flog repository", func() {
Expect(headers[1].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber))) Expect(headers[1].BlockNumber).To(Or(Equal(startingBlockNumber), Equal(endingBlockNumber)))
}) })
It("only treats headers as checked if flog logs have been checked", func() { It("only treats headers as checked if vow flog logs have been checked", func() {
_, err := db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerIDs[1]) _, err := db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerIDs[1])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -201,7 +201,7 @@ var _ = Describe("Flog repository", func() {
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n)) _, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
} }
flogRepositoryTwo := flog.FlogRepository{} flogRepositoryTwo := vow_flog.VowFlogRepository{}
flogRepositoryTwo.SetDB(dbTwo) flogRepositoryTwo.SetDB(dbTwo)
err := flogRepository.MarkHeaderChecked(headerIDs[0]) err := flogRepository.MarkHeaderChecked(headerIDs[0])
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())

View File

@ -12,37 +12,38 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog_test package vow_flog_test
import ( import (
"math/rand"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories" "github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flog"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks"
flog_mocks "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/mocks/flog" "github.com/vulcanize/vulcanizedb/pkg/transformers/vow_flog"
"math/rand"
) )
var _ = Describe("Flog transformer", func() { var _ = Describe("Vow flog transformer", func() {
var config = flog.FlogConfig var config = vow_flog.VowFlogConfig
var fetcher mocks.MockLogFetcher var fetcher mocks.MockLogFetcher
var converter flog_mocks.MockFlogConverter var converter mocks.MockLogNoteConverter
var repository flog_mocks.MockFlogRepository var repository mocks.MockRepository
var transformer shared.Transformer var transformer shared.Transformer
var headerOne core.Header var headerOne core.Header
var headerTwo core.Header var headerTwo core.Header
BeforeEach(func() { BeforeEach(func() {
fetcher = mocks.MockLogFetcher{} fetcher = mocks.MockLogFetcher{}
converter = flog_mocks.MockFlogConverter{} converter = mocks.MockLogNoteConverter{}
repository = flog_mocks.MockFlogRepository{} repository = mocks.MockRepository{}
headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()} headerOne = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()} headerTwo = core.Header{Id: rand.Int63(), BlockNumber: rand.Int63()}
transformer = factories.LogNoteTransformer{ transformer = factories.LogNoteTransformer{
@ -86,7 +87,7 @@ var _ = Describe("Flog transformer", func() {
config.ContractAddresses, config.ContractAddresses,
config.ContractAddresses, config.ContractAddresses,
})) }))
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.FlogSignature)}})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.VowFlogSignature)}}))
}) })
It("returns error if fetcher returns error", func() { It("returns error if fetcher returns error", func() {
@ -126,13 +127,13 @@ var _ = Describe("Flog transformer", func() {
err := transformer.Execute() err := transformer.Execute()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(repository.CheckedHeaderIDs).To(ContainElement(headerOne.Id)) Expect(repository.MarkHeaderCheckedPassedHeaderIDs).To(ContainElement(headerOne.Id))
Expect(repository.CheckedHeaderIDs).To(ContainElement(headerTwo.Id)) Expect(repository.MarkHeaderCheckedPassedHeaderIDs).To(ContainElement(headerTwo.Id))
}) })
It("returns error if marking header checked returns err", func() { It("returns error if marking header checked returns err", func() {
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo}) repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
repository.SetCheckedHeaderError(fakes.FakeError) repository.SetMarkHeaderCheckedError(fakes.FakeError)
fetcher.SetFetchedLogs([]types.Log{}) fetcher.SetFetchedLogs([]types.Log{})
err := transformer.Execute() err := transformer.Execute()
@ -141,7 +142,8 @@ var _ = Describe("Flog transformer", func() {
Expect(err).To(MatchError(fakes.FakeError)) Expect(err).To(MatchError(fakes.FakeError))
}) })
It("persists flog model", func() { It("persists vow flog model", func() {
converter.SetReturnModels([]interface{}{test_data.FlogModel})
fetcher.SetFetchedLogs([]types.Log{test_data.EthFlogLog}) fetcher.SetFetchedLogs([]types.Log{test_data.EthFlogLog})
repository.SetMissingHeaders([]core.Header{headerOne}) repository.SetMissingHeaders([]core.Header{headerOne})

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package flog package vow_flog
import ( import (
"testing" "testing"
@ -23,9 +23,9 @@ import (
"log" "log"
) )
func TestFlog(t *testing.T) { func TestVowFlog(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Flog Suite") RunSpecs(t, "VowFlog Suite")
} }
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {