integration tests (#75)

* Deal integration test

* Add LogIndex to CatFileChopLump to update unique constraint

* Add LogIndex to cat_file_pit_vow records

* Add integration tests for Cat.file transformers

* Add log index to Cat.file flip
This commit is contained in:
Elizabeth
2018-10-22 13:28:42 -05:00
committed by GitHub
parent 7870451b5c
commit 954fcf2378
17 changed files with 279 additions and 23 deletions
@@ -50,6 +50,7 @@ func (CatFileChopLumpConverter) ToModels(ethLogs []types.Log) ([]CatFileChopLump
What: what,
Data: data,
TransactionIndex: ethLog.TxIndex,
LogIndex: ethLog.Index,
Raw: raw,
}
results = append(results, result)
@@ -19,5 +19,6 @@ type CatFileChopLumpModel struct {
What string
Data string
TransactionIndex uint `db:"tx_idx"`
LogIndex uint `db:"log_idx"`
Raw []byte `db:"raw_log"`
}
@@ -40,9 +40,9 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []CatF
}
for _, model := range models {
_, err := tx.Exec(
`INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`,
headerID, model.Ilk, model.What, model.Data, model.TransactionIndex, model.Raw,
`INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
headerID, model.Ilk, model.What, model.Data, model.TransactionIndex, model.LogIndex, model.Raw,
)
if err != nil {
tx.Rollback()
@@ -81,6 +81,14 @@ var _ = Describe("Cat file chop lump repository", func() {
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
})
It("allows for multiple cat file chop lump events if they have different log indexes", func() {
newCatFileChopLump := test_data.CatFileChopLumpModel
newCatFileChopLump.LogIndex = newCatFileChopLump.LogIndex + 1
err = catFileRepository.Create(headerID, []chop_lump.CatFileChopLumpModel{newCatFileChopLump})
Expect(err).NotTo(HaveOccurred())
})
It("removes cat file chop lump if corresponding header is deleted", func() {
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
@@ -50,6 +50,7 @@ func (CatFileFlipConverter) ToModels(ethLogs []types.Log) ([]CatFileFlipModel, e
What: what,
Flip: flip,
TransactionIndex: ethLog.TxIndex,
LogIndex: ethLog.Index,
Raw: raw,
}
results = append(results, result)
+1
View File
@@ -19,5 +19,6 @@ type CatFileFlipModel struct {
What string
Flip string
TransactionIndex uint `db:"tx_idx"`
LogIndex uint `db:"log_idx"`
Raw []byte `db:"raw_log"`
}
+3 -3
View File
@@ -40,9 +40,9 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []CatFileF
}
for _, model := range models {
_, err = repository.db.Exec(
`INSERT into maker.cat_file_flip (header_id, ilk, what, flip, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6)`,
headerID, model.Ilk, model.What, model.Flip, model.TransactionIndex, model.Raw,
`INSERT into maker.cat_file_flip (header_id, ilk, what, flip, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6, $7)`,
headerID, model.Ilk, model.What, model.Flip, model.TransactionIndex, model.LogIndex, model.Raw,
)
if err != nil {
tx.Rollback()
@@ -58,12 +58,13 @@ var _ = Describe("Cat file flip repository", func() {
It("adds a cat file flip event", func() {
var dbResult flip.CatFileFlipModel
err = db.Get(&dbResult, `SELECT ilk, what, flip, tx_idx, raw_log FROM maker.cat_file_flip WHERE header_id = $1`, headerID)
err = db.Get(&dbResult, `SELECT ilk, what, flip, tx_idx, log_idx, raw_log FROM maker.cat_file_flip WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbResult.Ilk).To(Equal(test_data.CatFileFlipModel.Ilk))
Expect(dbResult.What).To(Equal(test_data.CatFileFlipModel.What))
Expect(dbResult.Flip).To(Equal(test_data.CatFileFlipModel.Flip))
Expect(dbResult.TransactionIndex).To(Equal(test_data.CatFileFlipModel.TransactionIndex))
Expect(dbResult.LogIndex).To(Equal(test_data.CatFileFlipModel.LogIndex))
Expect(dbResult.Raw).To(MatchJSON(test_data.CatFileFlipModel.Raw))
})
@@ -47,6 +47,7 @@ func (CatFilePitVowConverter) ToModels(ethLogs []types.Log) ([]CatFilePitVowMode
What: what,
Data: data,
TransactionIndex: ethLog.TxIndex,
LogIndex: ethLog.Index,
Raw: raw,
}
results = append(results, result)
@@ -18,5 +18,6 @@ type CatFilePitVowModel struct {
What string
Data string
TransactionIndex uint `db:"tx_idx"`
LogIndex uint `db:"log_idx"`
Raw []byte `db:"raw_log"`
}
@@ -40,9 +40,9 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []CatFil
}
for _, model := range models {
_, err = repository.db.Exec(
`INSERT into maker.cat_file_pit_vow (header_id, what, data, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5)`,
headerID, model.What, model.Data, model.TransactionIndex, model.Raw,
`INSERT into maker.cat_file_pit_vow (header_id, what, data, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6)`,
headerID, model.What, model.Data, model.TransactionIndex, model.LogIndex, model.Raw,
)
if err != nil {
tx.Rollback()
@@ -58,11 +58,12 @@ var _ = Describe("Cat file pit vow repository", func() {
It("adds a cat file pit vow event", func() {
var dbResult pit_vow.CatFilePitVowModel
err = db.Get(&dbResult, `SELECT what, data, tx_idx, raw_log FROM maker.cat_file_pit_vow WHERE header_id = $1`, headerID)
err = db.Get(&dbResult, `SELECT what, data, tx_idx, log_idx, raw_log FROM maker.cat_file_pit_vow WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbResult.What).To(Equal(test_data.CatFilePitVowModel.What))
Expect(dbResult.Data).To(Equal(test_data.CatFilePitVowModel.Data))
Expect(dbResult.TransactionIndex).To(Equal(test_data.CatFilePitVowModel.TransactionIndex))
Expect(dbResult.LogIndex).To(Equal(test_data.CatFilePitVowModel.LogIndex))
Expect(dbResult.Raw).To(MatchJSON(test_data.CatFilePitVowModel.Raw))
})