mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Add test for get num squeaks with address in block range db method (#1640)
This commit is contained in:
parent
0dfe29ef06
commit
3ffa122f4f
2 changed files with 35 additions and 19 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue