Skip to content

Commit

Permalink
fix add_feed_ids bug (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel authored Feb 22, 2024
1 parent 8cd3b85 commit 8d671af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pythclient/hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ async def get_price_feed_ids(self) -> list[str]:
return data

def add_feed_ids(self, feed_ids: list[str]):
self.feed_ids += feed_ids
self.feed_ids = list(set(self.feed_ids))
self.pending_feed_ids += feed_ids
# convert feed_ids to a set to remove any duplicates from the input
new_feed_ids_set = set(feed_ids)

# update self.feed_ids; convert to set for union operation, then back to list
self.feed_ids = list(set(self.feed_ids).union(new_feed_ids_set))

# update self.pending_feed_ids with only those IDs that are truly new
self.pending_feed_ids = list(set(self.pending_feed_ids).union(new_feed_ids_set))

@staticmethod
def extract_price_feed_v1(data: dict) -> PriceFeed:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='pythclient',
version='0.1.23',
version='0.1.24',
packages=['pythclient'],
author='Pyth Developers',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_hermes_add_feed_ids(hermes_client: HermesClient, mock_get_price_f

assert len(set(hermes_client.feed_ids)) == len(hermes_client.feed_ids)
assert set(hermes_client.feed_ids) == set(feed_ids_pre + feed_ids)
assert set(hermes_client.pending_feed_ids) == set(pending_feed_ids_pre + feed_ids)
assert len(hermes_client.pending_feed_ids) == len(set(pending_feed_ids_pre + feed_ids))

def test_hermes_extract_price_feed_v1(hermes_client: HermesClient, data_v1: dict):
price_feed = hermes_client.extract_price_feed_v1(data_v1)
Expand Down

0 comments on commit 8d671af

Please sign in to comment.