-
Notifications
You must be signed in to change notification settings - Fork 32
add tests for PythAccount and PythClient #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8cc3df1
replace SolanaAccount initialization in each tests with solana_accoun…
cctdaniel cf4528e
add test coverage for PythClient
cctdaniel 6551bce
update PythAccount test coverage
cctdaniel cbaa843
add test to get ratelimit and create watch session
cctdaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import pytest | ||
|
||
from _pytest.logging import LogCaptureFixture | ||
|
||
from pythclient.solana import SolanaClient, SolanaPublicKey | ||
from pythclient.pythaccounts import PythAccount, PythAccountType, PythProductAccount | ||
|
||
|
||
BCH_PRODUCT_ACCOUNT_KEY_DEVNET = '89GseEmvNkzAMMEXcW9oTYzqRPXTsJ3BmNerXmgA1osV' | ||
BCH_PRICE_ACCOUNT_KEY_DEVNET = '4EQrNZYk5KR1RnjyzbaaRbHsv8VqZWzSUtvx58wLsZbj' | ||
|
||
PRODUCT_ACCOUNT_B64_DATA = ('1MOyoQIAAAACAAAAlwAAADAClHlZh5cpDjY4oXEsKb3iNn0OynlPd4sltaRy8ZLeBnN5bWJvbAdCQ0gv' | ||
'VVNECmFzc2V0X3R5cGUGQ3J5cHRvDnF1b3RlX2N1cnJlbmN5A1VTRAtkZXNjcmlwdGlvbgdCQ0gvVVNE' | ||
'DmdlbmVyaWNfc3ltYm9sBkJDSFVTRARiYXNlA0JDSA==') | ||
|
||
|
||
@pytest.fixture | ||
def solana_pubkey(): | ||
return SolanaPublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J") | ||
|
||
|
||
@pytest.fixture | ||
def pyth_account(solana_pubkey, solana_client): | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return PythAccount( | ||
key=solana_pubkey, | ||
solana=solana_client, | ||
) | ||
|
||
|
||
@ pytest.fixture | ||
def product_account(solana_client: SolanaClient) -> PythProductAccount: | ||
product_account = PythProductAccount( | ||
key=SolanaPublicKey(BCH_PRODUCT_ACCOUNT_KEY_DEVNET), | ||
solana=solana_client, | ||
) | ||
product_account.slot = 96866599 | ||
product_account.attrs = { | ||
'asset_type': 'Crypto', | ||
'symbol': 'BCH/USD', | ||
'quote_currency': 'USD', | ||
'description': 'BCH/USD', | ||
'generic_symbol': 'BCHUSD', | ||
'base': 'BCH' | ||
} | ||
product_account.first_price_account_key = SolanaPublicKey( | ||
BCH_PRICE_ACCOUNT_KEY_DEVNET, | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
return product_account | ||
|
||
|
||
def test_product_account_update_with_rpc_response_with_data( | ||
product_account: PythProductAccount | ||
): | ||
assert product_account.slot == 96866599 | ||
assert product_account.lamports is None | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
slot = 96866600 | ||
value = { | ||
'lamports': 1000000000, | ||
'data': [ | ||
PRODUCT_ACCOUNT_B64_DATA, | ||
'base64' | ||
] | ||
} | ||
|
||
product_account.update_with_rpc_response(slot=slot, value=value) | ||
assert product_account.slot == 96866600 | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_pyth_account_update_with_rpc_response_wrong_type( | ||
pyth_account: PythAccount, | ||
caplog: LogCaptureFixture | ||
): | ||
assert pyth_account.slot is None | ||
assert pyth_account.lamports is None | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
slot = 96866600 | ||
value = { | ||
'lamports': 1000000000, | ||
'data': [ | ||
PRODUCT_ACCOUNT_B64_DATA, | ||
'base64' | ||
] | ||
} | ||
|
||
exc_message = f"wrong Pyth account type {PythAccountType.PRODUCT} for {type(pyth_account)}" | ||
with pytest.raises(ValueError, match=exc_message): | ||
pyth_account.update_with_rpc_response(slot=slot, value=value) | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_pyth_account_update_with_rpc_response_no_data( | ||
pyth_account: PythAccount, | ||
caplog: LogCaptureFixture | ||
): | ||
assert pyth_account.slot is None | ||
assert pyth_account.lamports is None | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
slot = 106498726 | ||
value = { | ||
"lamports": 1000000000 | ||
} | ||
|
||
exc_message = f'invalid account data response from Solana for key {pyth_account.key}: {value}' | ||
with pytest.raises(ValueError, match=exc_message): | ||
pyth_account.update_with_rpc_response(slot=slot, value=value) | ||
assert exc_message in caplog.text |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Make these into fixtures