Skip to content

Commit 9c8630a

Browse files
author
Jeff Schroeder
committed
Addressing price account review feedback for tests
* Make a `price_account` fixture * Rename test_price_account() --> test_price_account_update_from() * Split out tests for aggregate confidence_interval and aggregate price * Move an assertion for the min_publishers to the end Thanks @cctdaniel
1 parent 90b0ac2 commit 9c8630a

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

tests/test_price_account.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,14 @@ def price_account_bytes():
141141

142142

143143
@pytest.fixture
144-
def price_account_key():
145-
return SolanaPublicKey("5ALDzwcRJfSyGdGyhP3kP628aqBNHZzLuVww7o9kdspe")
146-
147-
148-
def test_price_account(price_account_bytes, price_account_key, solana_client):
149-
price_account = PythPriceAccount(
150-
key=price_account_key,
144+
def price_account(solana_client):
145+
return PythPriceAccount(
146+
key=SolanaPublicKey("5ALDzwcRJfSyGdGyhP3kP628aqBNHZzLuVww7o9kdspe"),
151147
solana=solana_client,
152148
)
149+
150+
151+
def test_price_account_update_from(price_account_bytes, price_account):
153152
price_account.update_from(buffer=price_account_bytes, version=2, offset=0)
154153

155154
assert price_account.price_type == PythPriceType.PRICE
@@ -171,8 +170,6 @@ def test_price_account(price_account_bytes, price_account_key, solana_client):
171170
"price": 707.125,
172171
"confidence_interval": 0.366305,
173172
}
174-
assert price_account.min_publishers == 0
175-
176173
# Only assert the first element of the 19 price components
177174
assert dict(price_account.price_components[0]) == {
178175
"publisher_key": SolanaPublicKey(
@@ -198,13 +195,10 @@ def test_price_account(price_account_bytes, price_account_key, solana_client):
198195
},
199196
"exponent": -8,
200197
}
198+
assert price_account.min_publishers == 0
201199

202200

203-
def test_price_account_str(price_account_bytes, price_account_key, solana_client):
204-
price_account = PythPriceAccount(
205-
key=price_account_key,
206-
solana=solana_client,
207-
)
201+
def test_price_account_str(price_account_bytes, price_account, solana_client):
208202
expected_empty = "PythPriceAccount PythPriceType.UNKNOWN (5ALDzwcRJfSyGdGyhP3kP628aqBNHZzLuVww7o9kdspe)"
209203
assert str(price_account) == expected_empty
210204

@@ -223,13 +217,15 @@ def test_price_account_str(price_account_bytes, price_account_key, solana_client
223217
assert str(price_account) == expected_with_product
224218

225219

226-
def test_price_account_agregate_properties(
227-
price_account_bytes, price_account_key, solana_client
220+
def test_price_account_agregate_conf_interval(
221+
price_account_bytes, price_account,
228222
):
229-
price_account = PythPriceAccount(
230-
key=price_account_key,
231-
solana=solana_client,
232-
)
233223
price_account.update_from(buffer=price_account_bytes, version=2, offset=0)
234-
assert price_account.aggregate_price == 707.125
235224
assert price_account.aggregate_price_confidence_interval == 0.366305
225+
226+
227+
def test_price_account_agregate_price(
228+
price_account_bytes, price_account,
229+
):
230+
price_account.update_from(buffer=price_account_bytes, version=2, offset=0)
231+
assert price_account.aggregate_price == 707.125

0 commit comments

Comments
 (0)