forked from serum-community/pyserum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor bootstrapped fixtures (serum-community#28)
* Add wallet fixture * Make format * Extra verbose logging for int tests * Update make scripts * Refactor bootstrapped fixtures
- Loading branch information
1 parent
1cc4b7b
commit 43cfe1b
Showing
6 changed files
with
201 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,19 +1,134 @@ | ||
import pytest | ||
from typing import Dict | ||
|
||
import pytest | ||
from solana.account import Account | ||
from solana.publickey import PublicKey | ||
|
||
__dex_fixtures = {} | ||
__cached_params = {} | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def serum_dex(): | ||
if not __dex_fixtures: | ||
def __bs_params() -> Dict[str, str]: | ||
if not __cached_params: | ||
with open("tests/crank.log") as crank_log: | ||
for line in crank_log.readlines(): | ||
if ":" not in line: | ||
continue | ||
key, val = line.strip().replace(",", "").split(": ") | ||
assert val is not None | ||
__dex_fixtures[key] = PublicKey(val) | ||
return __dex_fixtures | ||
assert key, "key must not be None" | ||
assert val, "val must not be None" | ||
__cached_params[key] = val | ||
return __cached_params | ||
|
||
|
||
def __bootstrap_account(pubkey: str, secret: str) -> Account: | ||
secret = [int(b) for b in secret[1:-1].split(" ")] | ||
account = Account(secret) | ||
assert str(account.public_key()) == pubkey, "account must map to provided public key" | ||
return account | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_payer(__bs_params) -> Account: | ||
"""Bootstrapped payer account.""" | ||
return __bootstrap_account(__bs_params["payer"], __bs_params["payer_secret"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_base_mint(__bs_params) -> Account: | ||
"""Bootstrapped base mint account.""" | ||
return __bootstrap_account(__bs_params["coin_mint"], __bs_params["coin_mint_secret"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_quote_mint(__bs_params) -> Account: | ||
"""Bootstrapped quote mint account.""" | ||
return __bootstrap_account(__bs_params["pc_mint"], __bs_params["pc_mint_secret"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_base_wallet(__bs_params) -> Account: | ||
"""Bootstrapped base mint account.""" | ||
return __bootstrap_account(__bs_params["coin_wallet"], __bs_params["coin_wallet_secret"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_quote_wallet(__bs_params) -> Account: | ||
"""Bootstrapped quote mint account.""" | ||
return __bootstrap_account(__bs_params["pc_wallet"], __bs_params["pc_wallet_secret"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_market_pk(__bs_params) -> PublicKey: | ||
"""Public key of the boostrapped market.""" | ||
return PublicKey(__bs_params["market"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_req_q_pk(__bs_params) -> PublicKey: | ||
"""Public key of the bootstrapped request queue.""" | ||
return PublicKey(__bs_params["req_q"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_event_q_pk(__bs_params) -> PublicKey: | ||
"""Public key of the bootstrapped request queue.""" | ||
return PublicKey(__bs_params["event_q"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_bids_pk(__bs_params) -> PublicKey: | ||
"""Public key of the bootstrapped bids book.""" | ||
return PublicKey(__bs_params["bids"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_asks_pk(__bs_params) -> PublicKey: | ||
"""Public key of the bootstrapped asks book.""" | ||
return PublicKey(__bs_params["asks"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_base_vault_pk(__bs_params) -> PublicKey: | ||
"""Public key of the base vault account.""" | ||
return PublicKey(__bs_params["coin_vault"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_quote_vault_pk(__bs_params) -> PublicKey: | ||
"""Public key of the quote vault account.""" | ||
return PublicKey(__bs_params["pc_vault"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_vault_signer_pk(__bs_params) -> PublicKey: | ||
"""Public key of the bootstrapped vault signer.""" | ||
return PublicKey(__bs_params["vault_signer_key"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_bid_account_pk(__bs_params) -> PublicKey: | ||
"""Public key of the initial bid order account.""" | ||
return PublicKey(__bs_params["bid_account"]) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.fixture(scope="session") | ||
def stubbed_ask_account_pk(__bs_params) -> PublicKey: | ||
"""Public key of the initial ask order account.""" | ||
return PublicKey(__bs_params["ask_account"]) |
This file contains 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 |
---|---|---|
@@ -1,22 +1,73 @@ | ||
import pytest | ||
|
||
from solana.account import Account | ||
from solana.publickey import PublicKey | ||
|
||
|
||
@pytest.mark.integration | ||
def test_serum_dex(serum_dex): | ||
"""Make sure serum_dex fixture is populated with public keys.""" | ||
assert isinstance(serum_dex["coin_mint"], PublicKey) | ||
assert isinstance(serum_dex["pc_mint"], PublicKey) | ||
assert isinstance(serum_dex["market"], PublicKey) | ||
assert isinstance(serum_dex["req_q"], PublicKey) | ||
assert isinstance(serum_dex["event_q"], PublicKey) | ||
assert isinstance(serum_dex["bids"], PublicKey) | ||
assert isinstance(serum_dex["asks"], PublicKey) | ||
assert isinstance(serum_dex["coin_vault"], PublicKey) | ||
assert isinstance(serum_dex["pc_vault"], PublicKey) | ||
assert isinstance(serum_dex["vault_signer_key"], PublicKey) | ||
assert isinstance(serum_dex["wallet"], PublicKey) | ||
assert isinstance(serum_dex["bid_account"], PublicKey) | ||
assert isinstance(serum_dex["ask_account"], PublicKey) | ||
assert isinstance(serum_dex["dex_program_id"], PublicKey) | ||
def test_payer(stubbed_payer): | ||
assert isinstance(stubbed_payer, Account) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_base_mint(stubbed_base_mint): | ||
assert isinstance(stubbed_base_mint, Account) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_base_wallet(stubbed_base_wallet): | ||
assert isinstance(stubbed_base_wallet, Account) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_base_vault_pk(stubbed_base_vault_pk): | ||
assert isinstance(stubbed_base_vault_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_quote_mint(stubbed_quote_mint): | ||
assert isinstance(stubbed_quote_mint, Account) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_quote_wallet(stubbed_quote_wallet): | ||
assert isinstance(stubbed_quote_wallet, Account) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_quote_vault_pk(stubbed_quote_vault_pk): | ||
assert isinstance(stubbed_quote_vault_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_market_pk(stubbed_market_pk): | ||
assert isinstance(stubbed_market_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_event_q_pk(stubbed_event_q_pk): | ||
assert isinstance(stubbed_event_q_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_req_q_pk(stubbed_req_q_pk): | ||
assert isinstance(stubbed_req_q_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_bids_pk(stubbed_bids_pk): | ||
assert isinstance(stubbed_bids_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_asks_pk(stubbed_asks_pk): | ||
assert isinstance(stubbed_asks_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_bid_account_pk(stubbed_bid_account_pk): | ||
assert isinstance(stubbed_bid_account_pk, PublicKey) | ||
|
||
|
||
@pytest.mark.integration | ||
def test_ask_account_pk(stubbed_ask_account_pk): | ||
assert isinstance(stubbed_ask_account_pk, PublicKey) |