Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Vdb-585 create address table #126

Merged
merged 13 commits into from
Aug 26, 2019
Merged

Conversation

elizabethengelman
Copy link
Contributor

@elizabethengelman elizabethengelman commented Aug 5, 2019

  • factors out an address table to be referenced by FK in full_sync_receipts and header_sync_receipts
  • created a repository for addresses, header_sync_receipts and full_sync_receipts to eliminate some duplicate code
  • would love some feedback on this before I make similar changes in mcd_transformers

@elizabethengelman elizabethengelman force-pushed the vdb-585-create-address-table branch from 32a6b3d to 0f64198 Compare August 5, 2019 14:15
@elizabethengelman elizabethengelman requested review from i-norden, rmulhol, m0ar, aaizuss, Gslaughl and yaoandrew and removed request for i-norden August 5, 2019 22:00
Copy link
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

All my comments are incredibly minor and non-blocking. Thanks for improving our test coverage while implementing this feature!

func (AddressRepository) GetAddressById(db *postgres.DB, id int) (string, error) {
var address string
getErr := db.Get(&address, `SELECT address FROM public.addresses WHERE id = $1`, id)
if getErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return address, getErr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expect(createErr).NotTo(HaveOccurred())

var actualAddress dbAddress
getErr := db.Get(&actualAddress, `SELECT id, address FROM public.addresses LIMIT 1`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig using the LIMIT 1 instead of WHERE address = $1. Doesn't need to be a part of this PR, but I wonder if we want to start using that pattern in other places where we're going db.Get in tests 🤔

_, createErr := repo.GetOrCreateAddress(db, address)
Expect(createErr).NotTo(HaveOccurred())

_, getErr := repo.GetOrCreateAddress(db, address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe superfluous, but I wonder if we'd want to potentially assign the result here and Expect(idOne).To(Equal(idTwo))

It("creates an address record", func() {
addressId, createErr := repo.GetOrCreateAddressInTransaction(tx, address)
Expect(createErr).NotTo(HaveOccurred())
tx.Commit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth assigning commitErr := tx.Commit() and Expect(commitErr).NotTo(HaveOccurred())?

stringAddressToCommonAddress := common.HexToAddress(address)
hexAddress := stringAddressToCommonAddress.Hex()

var addressId int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a big deal, but I wonder if we want to pick one type between int and int64 that we're using to pass around db ids

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, good call! quickly looking through the other repos, it looks like they're treating ids as int64s, so I'll follow suit.

BeforeEach(func() {
tx, txErr = db.Beginx()
Expect(txErr).NotTo(HaveOccurred())
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't matter, but I wonder if we want to have an AfterEach to close/rollback the tx. Mostly thinking about whether a tx could leak and remain open if the test fails early (and if that could conceivably have any impact)

@@ -79,7 +79,9 @@ var _ = Describe("Watched Events Repository", func() {
Expect(err).ToNot(HaveOccurred())
blockId, err := blocksRepository.CreateOrUpdateBlock(core.Block{})
Expect(err).NotTo(HaveOccurred())
receiptId, err := receiptRepository.CreateReceipt(blockId, core.Receipt{})
tx, _ := db.Beginx()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth assigning and asserting against an error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db)
repo = repositories.AddressRepository{}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in tests that use the db, we tend to include an AfterEach that calls db.Close() - I don't know why we do that or if it's actually necessary though.

Copy link
Collaborator

@i-norden i-norden Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it would be better to have the test_config.CleanTestDB(db) in an AfterEach statement, I might be missing something but I think with the way it is right now any addresses that are added in the last test to be ran in this suite will be left over after the suite exits and could potentially lead to issues down the road with other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually a bit unclear about when we need to do db.Close and when we don't. I thought that db.Close was something that we were doing in the mcd_transformers repo since we're building up and tearing down the db for each test run, but I could be wrong.

I created VDB-799 as a way to make sure we're handling test cleanup consistently, does that make sense to handle this as part of that story? In the mean time, I'll add test_config.CleanTestDB(db) to an AfterEach.

Copy link
Collaborator

@i-norden i-norden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for undertaking this.

"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/test_config"
"math/big"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor (I can't find anything else to comment on 🙃 ) but could we split these and other files' imports up into the "standard lib", "external deps", and "internal deps" sections (I need to go back and do this to my seed node files too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 07e45dd

db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db)
repo = repositories.AddressRepository{}
})
Copy link
Collaborator

@i-norden i-norden Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it would be better to have the test_config.CleanTestDB(db) in an AfterEach statement, I might be missing something but I think with the way it is right now any addresses that are added in the last test to be ran in this suite will be left over after the suite exits and could potentially lead to issues down the road with other tests.

@elizabethengelman elizabethengelman changed the title [WIP] Vdb-585 create address table Vdb-585 create address table Aug 20, 2019
@elizabethengelman elizabethengelman force-pushed the vdb-585-create-address-table branch from 359ef6e to eacc4fc Compare August 20, 2019 16:02
@elizabethengelman elizabethengelman force-pushed the vdb-585-create-address-table branch from eacc4fc to edc0bdf Compare August 23, 2019 15:11
@elizabethengelman elizabethengelman merged commit b6a2a27 into staging Aug 26, 2019
@elizabethengelman elizabethengelman deleted the vdb-585-create-address-table branch August 26, 2019 20:13
elizabethengelman added a commit to vulcanize/mcd_transformers that referenced this pull request Aug 27, 2019
Will need to update this version to a release when
vulcanize/vulcanizedb#126 is merged in a
released
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants