Add test for get num squeaks with address in block range db method (#1640)

This commit is contained in:
Jonathan Zernik 2021-10-18 12:47:14 -07:00 committed by GitHub
parent 0dfe29ef06
commit 3ffa122f4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 19 deletions

View file

@ -665,25 +665,25 @@ class SqueakDb:
num_squeaks = row["num_squeaks"]
return num_squeaks
def number_of_squeaks_with_address_with_block(
self,
address: str,
block_height: int,
) -> int:
""" Get number of squeaks with address with block height. """
s = (
select([
func.count().label("num_squeaks"),
])
.select_from(self.squeaks)
.where(self.squeaks.c.author_address == address)
.where(self.squeaks.c.n_block_height == block_height)
)
with self.get_connection() as connection:
result = connection.execute(s)
row = result.fetchone()
num_squeaks = row["num_squeaks"]
return num_squeaks
# def number_of_squeaks_with_address_with_block(
# self,
# address: str,
# block_height: int,
# ) -> int:
# """ Get number of squeaks with address with block height. """
# s = (
# select([
# func.count().label("num_squeaks"),
# ])
# .select_from(self.squeaks)
# .where(self.squeaks.c.author_address == address)
# .where(self.squeaks.c.n_block_height == block_height)
# )
# with self.get_connection() as connection:
# result = connection.execute(s)
# row = result.fetchone()
# num_squeaks = row["num_squeaks"]
# return num_squeaks
def number_of_squeaks_with_address_in_block_range(
self,

View file

@ -639,3 +639,19 @@ def test_get_number_of_squeaks(
num_squeaks = squeak_db.get_number_of_squeaks()
assert num_squeaks == len(inserted_squeak_hashes)
def test_number_of_squeaks_with_address_in_block_range(
squeak_db,
address_str,
inserted_squeak_hashes,
):
min_block = 43
max_block = 91
num_squeaks = squeak_db.number_of_squeaks_with_address_in_block_range(
address=address_str,
min_block=min_block,
max_block=max_block,
)
assert num_squeaks == max_block - min_block + 1