-
Notifications
You must be signed in to change notification settings - Fork 33
Conversation
32a6b3d
to
0f64198
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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`) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 id
s
There was a problem hiding this comment.
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 int64
s, so I'll follow suit.
BeforeEach(func() { | ||
tx, txErr = db.Beginx() | ||
Expect(txErr).NotTo(HaveOccurred()) | ||
}) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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{} | ||
}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this 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" |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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{} | ||
}) |
There was a problem hiding this comment.
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.
359ef6e
to
eacc4fc
Compare
eacc4fc
to
edc0bdf
Compare
Will need to update this version to a release when vulcanize/vulcanizedb#126 is merged in a released
full_sync_receipts
andheader_sync_receipts