forked from cerc-io/ipld-eth-server
Update pit file debt ceiling tests
This commit is contained in:
parent
24199cb67e
commit
d9b6603109
@ -17,10 +17,10 @@ package debt_ceiling_test
|
|||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
||||||
|
|
||||||
"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/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,6 +54,6 @@ var _ = Describe("Pit file debt ceiling 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]).To(Equal(test_data.PitFileDebtCeilingModel))
|
Expect(models[0].(debt_ceiling.PitFileDebtCeilingModel)).To(Equal(test_data.PitFileDebtCeilingModel))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -32,17 +32,17 @@ import (
|
|||||||
|
|
||||||
var _ = Describe("Pit file debt ceiling repository", func() {
|
var _ = Describe("Pit file debt ceiling repository", func() {
|
||||||
var (
|
var (
|
||||||
db *postgres.DB
|
db *postgres.DB
|
||||||
pitFileRepository debt_ceiling.Repository
|
pitFileDebtCeilingRepository debt_ceiling.PitFileDebtCeilingRepository
|
||||||
err error
|
err error
|
||||||
headerRepository datastore.HeaderRepository
|
headerRepository datastore.HeaderRepository
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(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)
|
||||||
pitFileRepository = debt_ceiling.NewPitFileDebtCeilingRepository(db)
|
pitFileDebtCeilingRepository = debt_ceiling.PitFileDebtCeilingRepository{DB: db}
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Create", func() {
|
Describe("Create", func() {
|
||||||
@ -52,7 +52,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = pitFileRepository.Create(headerID, []debt_ceiling.PitFileDebtCeilingModel{test_data.PitFileDebtCeilingModel})
|
err = pitFileDebtCeilingRepository.Create(headerID, []interface{}{test_data.PitFileDebtCeilingModel})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("does not duplicate pit file events", func() {
|
It("does not duplicate pit file events", func() {
|
||||||
err = pitFileRepository.Create(headerID, []debt_ceiling.PitFileDebtCeilingModel{test_data.PitFileDebtCeilingModel})
|
err = pitFileDebtCeilingRepository.Create(headerID, []interface{}{test_data.PitFileDebtCeilingModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||||
@ -100,7 +100,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("creates a row for a new headerID", func() {
|
It("creates a row for a new headerID", func() {
|
||||||
err = pitFileRepository.MarkHeaderChecked(headerID)
|
err = pitFileDebtCeilingRepository.MarkHeaderChecked(headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
@ -112,7 +112,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
It("updates row when headerID already exists", func() {
|
It("updates row when headerID already exists", func() {
|
||||||
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||||
|
|
||||||
err = pitFileRepository.MarkHeaderChecked(headerID)
|
err = pitFileDebtCeilingRepository.MarkHeaderChecked(headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
@ -144,10 +144,11 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("returns headers that haven't been checked", func() {
|
It("returns headers that haven't been checked", func() {
|
||||||
err := pitFileRepository.MarkHeaderChecked(headerIDs[1])
|
|
||||||
|
err := pitFileDebtCeilingRepository.MarkHeaderChecked(headerIDs[1])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
headers, err := pitFileRepository.MissingHeaders(startingBlock, endingBlock)
|
headers, err := pitFileDebtCeilingRepository.MissingHeaders(startingBlock, endingBlock)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(headers)).To(Equal(2))
|
Expect(len(headers)).To(Equal(2))
|
||||||
@ -159,7 +160,7 @@ var _ = Describe("Pit file debt ceiling repository", 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())
|
||||||
|
|
||||||
headers, err := pitFileRepository.MissingHeaders(startingBlock, endingBlock)
|
headers, err := pitFileDebtCeilingRepository.MissingHeaders(startingBlock, endingBlock)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(headers)).To(Equal(3))
|
Expect(len(headers)).To(Equal(3))
|
||||||
@ -175,8 +176,8 @@ var _ = Describe("Pit file debt ceiling repository", func() {
|
|||||||
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
_, err = headerRepositoryTwo.CreateOrUpdateHeader(fakes.GetFakeHeader(n))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
pitFileRepository := debt_ceiling.NewPitFileDebtCeilingRepository(db)
|
pitFileRepository := debt_ceiling.PitFileDebtCeilingRepository{DB: db}
|
||||||
pitFileRepositoryTwo := debt_ceiling.NewPitFileDebtCeilingRepository(dbTwo)
|
pitFileRepositoryTwo := debt_ceiling.PitFileDebtCeilingRepository{DB: dbTwo}
|
||||||
err := pitFileRepository.MarkHeaderChecked(headerIDs[0])
|
err := pitFileRepository.MarkHeaderChecked(headerIDs[0])
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
||||||
|
|
||||||
"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/pit_file"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
||||||
"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"
|
||||||
@ -31,31 +31,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Pit file debt ceiling transformer", func() {
|
var _ = Describe("Pit file debt ceiling transformer", func() {
|
||||||
It("gets missing headers for block numbers specified in config", func() {
|
var (
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
config = debt_ceiling.DebtCeilingFileConfig
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
fetcher mocks.MockLogFetcher
|
||||||
Config: pit_file.PitFileConfig,
|
converter debt_ceiling_mocks.MockPitFileDebtCeilingConverter
|
||||||
Fetcher: &mocks.MockLogFetcher{},
|
repository debt_ceiling_mocks.MockPitFileDebtCeilingRepository
|
||||||
Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{},
|
transformer shared.Transformer
|
||||||
Repository: repository,
|
headerOne core.Header
|
||||||
}
|
headerTwo core.Header
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
fetcher = mocks.MockLogFetcher{}
|
||||||
|
converter = debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
||||||
|
repository = debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
||||||
|
headerOne = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||||
|
headerTwo = core.Header{Id: GinkgoRandomSeed(), BlockNumber: GinkgoRandomSeed()}
|
||||||
|
transformer = factories.Transformer{
|
||||||
|
Config: config,
|
||||||
|
Fetcher: &fetcher,
|
||||||
|
Converter: &converter,
|
||||||
|
Repository: &repository,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("gets missing headers for block numbers specified in config", func() {
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(repository.PassedStartingBlockNumber).To(Equal(pit_file.PitFileConfig.StartingBlockNumber))
|
Expect(repository.PassedStartingBlockNumber).To(Equal(config.StartingBlockNumber))
|
||||||
Expect(repository.PassedEndingBlockNumber).To(Equal(pit_file.PitFileConfig.EndingBlockNumber))
|
Expect(repository.PassedEndingBlockNumber).To(Equal(config.EndingBlockNumber))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns error if repository returns error for missing headers", func() {
|
It("returns error if repository returns error for missing headers", func() {
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeadersError(fakes.FakeError)
|
||||||
repository.SetMissingHeadersErr(fakes.FakeError)
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: &mocks.MockLogFetcher{},
|
|
||||||
Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{},
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
@ -63,34 +72,18 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("fetches logs for missing headers", func() {
|
It("fetches logs for missing headers", func() {
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
repository.SetMissingHeaders([]core.Header{headerOne, headerTwo})
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
|
||||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}, {BlockNumber: 2}})
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{},
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2}))
|
Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber}))
|
||||||
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{pit_file.PitFileConfig.ContractAddresses, pit_file.PitFileConfig.ContractAddresses}))
|
Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses}))
|
||||||
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}}))
|
Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns error if fetcher returns error", func() {
|
It("returns error if fetcher returns error", func() {
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
|
||||||
fetcher.SetFetcherError(fakes.FakeError)
|
fetcher.SetFetcherError(fakes.FakeError)
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{},
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
@ -98,34 +91,17 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("marks header checked if no logs returned", func() {
|
It("marks header checked if no logs returned", func() {
|
||||||
mockConverter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
mockRepository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
|
||||||
headerID := int64(123)
|
|
||||||
mockRepository.SetMissingHeaders([]core.Header{{Id: headerID}})
|
|
||||||
mockFetcher := &mocks.MockLogFetcher{}
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Converter: mockConverter,
|
|
||||||
Fetcher: mockFetcher,
|
|
||||||
Repository: mockRepository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
mockRepository.AssertMarkHeaderCheckedCalledWith(headerID)
|
repository.AssertMarkHeaderCheckedCalledWith(headerOne.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns error if marking header checked returns err", func() {
|
It("returns error if marking header checked returns err", func() {
|
||||||
mockConverter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
mockRepository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMarkHeaderCheckedError(fakes.FakeError)
|
||||||
mockRepository.SetMissingHeaders([]core.Header{{Id: int64(123)}})
|
|
||||||
mockRepository.SetMarkHeaderCheckedErr(fakes.FakeError)
|
|
||||||
mockFetcher := &mocks.MockLogFetcher{}
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Converter: mockConverter,
|
|
||||||
Fetcher: mockFetcher,
|
|
||||||
Repository: mockRepository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
@ -134,16 +110,8 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("converts matching logs", func() {
|
It("converts matching logs", func() {
|
||||||
converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
|
||||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: converter,
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
@ -152,17 +120,9 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("returns error if converter returns error", func() {
|
It("returns error if converter returns error", func() {
|
||||||
converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
|
||||||
converter.SetConverterError(fakes.FakeError)
|
converter.SetConverterError(fakes.FakeError)
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
|
||||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1}})
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: converter,
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
@ -171,37 +131,20 @@ var _ = Describe("Pit file debt ceiling transformer", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("persists pit file model", func() {
|
It("persists pit file model", func() {
|
||||||
converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
|
||||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
fakeHeader := core.Header{BlockNumber: 1, Id: 2}
|
|
||||||
repository.SetMissingHeaders([]core.Header{fakeHeader})
|
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: converter,
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(repository.PassedHeaderID).To(Equal(fakeHeader.Id))
|
Expect(repository.PassedHeaderID).To(Equal(headerOne.Id))
|
||||||
Expect(repository.PassedModels).To(Equal([]debt_ceiling.PitFileDebtCeilingModel{test_data.PitFileDebtCeilingModel}))
|
Expect(repository.PassedModels).To(Equal([]interface{}{test_data.PitFileDebtCeilingModel}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns error if repository returns error for create", func() {
|
It("returns error if repository returns error for create", func() {
|
||||||
converter := &debt_ceiling_mocks.MockPitFileDebtCeilingConverter{}
|
|
||||||
fetcher := &mocks.MockLogFetcher{}
|
|
||||||
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
fetcher.SetFetchedLogs([]types.Log{test_data.EthPitFileDebtCeilingLog})
|
||||||
repository := &debt_ceiling_mocks.MockPitFileDebtCeilingRepository{}
|
repository.SetMissingHeaders([]core.Header{headerOne})
|
||||||
repository.SetMissingHeaders([]core.Header{{BlockNumber: 1, Id: 2}})
|
|
||||||
repository.SetCreateError(fakes.FakeError)
|
repository.SetCreateError(fakes.FakeError)
|
||||||
transformer := debt_ceiling.PitFileDebtCeilingTransformer{
|
|
||||||
Fetcher: fetcher,
|
|
||||||
Converter: converter,
|
|
||||||
Repository: repository,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := transformer.Execute()
|
err := transformer.Execute()
|
||||||
|
|
||||||
|
@ -17,20 +17,19 @@ package debt_ceiling
|
|||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockPitFileDebtCeilingConverter struct {
|
type MockPitFileDebtCeilingConverter struct {
|
||||||
converterErr error
|
converterError error
|
||||||
PassedLogs []types.Log
|
PassedLogs []types.Log
|
||||||
}
|
}
|
||||||
|
|
||||||
func (converter *MockPitFileDebtCeilingConverter) ToModels(ethLogs []types.Log) ([]debt_ceiling.PitFileDebtCeilingModel, error) {
|
func (converter *MockPitFileDebtCeilingConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||||
converter.PassedLogs = ethLogs
|
converter.PassedLogs = ethLogs
|
||||||
return []debt_ceiling.PitFileDebtCeilingModel{test_data.PitFileDebtCeilingModel}, converter.converterErr
|
return []interface{}{test_data.PitFileDebtCeilingModel}, converter.converterError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (converter *MockPitFileDebtCeilingConverter) SetConverterError(e error) {
|
func (converter *MockPitFileDebtCeilingConverter) SetConverterError(e error) {
|
||||||
converter.converterErr = e
|
converter.converterError = e
|
||||||
}
|
}
|
||||||
|
@ -16,46 +16,46 @@ package debt_ceiling
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockPitFileDebtCeilingRepository struct {
|
type MockPitFileDebtCeilingRepository struct {
|
||||||
createErr error
|
createError error
|
||||||
markHeaderCheckedErr error
|
markHeaderCheckedError error
|
||||||
markHeaderCheckedPassedHeaderID int64
|
markHeaderCheckedPassedHeaderID int64
|
||||||
missingHeaders []core.Header
|
missingHeaders []core.Header
|
||||||
missingHeadersErr error
|
missingHeadersError error
|
||||||
PassedStartingBlockNumber int64
|
PassedStartingBlockNumber int64
|
||||||
PassedEndingBlockNumber int64
|
PassedEndingBlockNumber int64
|
||||||
PassedHeaderID int64
|
PassedHeaderID int64
|
||||||
PassedModels []debt_ceiling.PitFileDebtCeilingModel
|
PassedModels []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
|
func (repository *MockPitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
|
||||||
repository.markHeaderCheckedPassedHeaderID = headerID
|
repository.markHeaderCheckedPassedHeaderID = headerID
|
||||||
return repository.markHeaderCheckedErr
|
return repository.markHeaderCheckedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) Create(headerID int64, models []debt_ceiling.PitFileDebtCeilingModel) error {
|
func (repository *MockPitFileDebtCeilingRepository) Create(headerID int64, models []interface{}) error {
|
||||||
repository.PassedHeaderID = headerID
|
repository.PassedHeaderID = headerID
|
||||||
repository.PassedModels = models
|
repository.PassedModels = models
|
||||||
return repository.createErr
|
return repository.createError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
func (repository *MockPitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||||
repository.PassedStartingBlockNumber = startingBlockNumber
|
repository.PassedStartingBlockNumber = startingBlockNumber
|
||||||
repository.PassedEndingBlockNumber = endingBlockNumber
|
repository.PassedEndingBlockNumber = endingBlockNumber
|
||||||
return repository.missingHeaders, repository.missingHeadersErr
|
return repository.missingHeaders, repository.missingHeadersError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) SetMarkHeaderCheckedErr(e error) {
|
func (repository *MockPitFileDebtCeilingRepository) SetMarkHeaderCheckedError(e error) {
|
||||||
repository.markHeaderCheckedErr = e
|
repository.markHeaderCheckedError = e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) SetMissingHeadersErr(e error) {
|
func (repository *MockPitFileDebtCeilingRepository) SetMissingHeadersError(e error) {
|
||||||
repository.missingHeadersErr = e
|
repository.missingHeadersError = e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) SetMissingHeaders(headers []core.Header) {
|
func (repository *MockPitFileDebtCeilingRepository) SetMissingHeaders(headers []core.Header) {
|
||||||
@ -63,9 +63,11 @@ func (repository *MockPitFileDebtCeilingRepository) SetMissingHeaders(headers []
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) SetCreateError(e error) {
|
func (repository *MockPitFileDebtCeilingRepository) SetCreateError(e error) {
|
||||||
repository.createErr = e
|
repository.createError = e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository *MockPitFileDebtCeilingRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
func (repository *MockPitFileDebtCeilingRepository) AssertMarkHeaderCheckedCalledWith(i int64) {
|
||||||
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repository *MockPitFileDebtCeilingRepository) SetDB(db *postgres.DB) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user