Skip to content

Commit

Permalink
fix tests/acceptance_test.py and idl load
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbigz committed Nov 17, 2023
1 parent 03b8379 commit d65103d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/driftpy/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def from_config(config: Config, provider: Provider, authority: Keypair = None):
file = Path(str(driftpy.__path__[0]) + "/idl/drift.json")
print(file)
with file.open() as f:
idl_dict = json.load(f)
idl = Idl.from_json(idl_dict)
raw = file.read_text()
idl = Idl.from_json(raw)

# create the program
program = Program(
Expand Down Expand Up @@ -730,7 +730,7 @@ async def get_place_spot_order_ix(
accounts={
"state": self.get_state_public_key(),
"user": user_account_public_key,
"authority": self.signer.pubkey,
"authority": self.signer.pubkey(),
},
remaining_accounts=remaining_accounts,
),
Expand Down Expand Up @@ -758,7 +758,7 @@ async def get_place_spot_orders_ix(
accounts={
"state": self.get_state_public_key(),
"user": self.get_user_account_public_key(user_id),
"authority": self.signer.pubkey,
"authority": self.signer.pubkey(),
},
remaining_accounts=remaining_accounts,
),
Expand All @@ -771,7 +771,7 @@ async def get_place_spot_orders_ix(
accounts={
"state": self.get_state_public_key(),
"user": user_account_public_key,
"authority": self.signer.pubkey,
"authority": self.signer.pubkey(),
},
remaining_accounts=remaining_accounts,
),
Expand Down Expand Up @@ -810,7 +810,7 @@ async def get_place_perp_order_ix(
accounts={
"state": self.get_state_public_key(),
"user": user_account_public_key,
"authority": self.signer.pubkey,
"authority": self.signer.pubkey(),
},
remaining_accounts=remaining_accounts,
),
Expand Down
21 changes: 12 additions & 9 deletions tests/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

from driftpy.constants.config import configs
from driftpy.constants.numeric_constants import PRICE_PRECISION, AMM_RESERVE_PRECISION
from driftpy.drift_client import driftClient
from driftpy.drift_client import DriftClient

from driftpy.addresses import *
from driftpy.types import *
from driftpy.accounts import *
from solana.keypair import Keypair
from solders.keypair import Keypair
# from solders.pubkey import Pubkey
from solana.rpc.async_api import AsyncClient


Expand All @@ -34,23 +35,23 @@


@async_fixture(scope="session")
async def drift_client() -> driftClient:
async def drift_client() -> DriftClient:
with open(os.path.expanduser(os.environ["ANCHOR_WALLET"]), "r") as f:
secret = json.load(f)
kp = Keypair.from_secret_key(bytes(secret))
kp = Keypair.from_bytes(bytes(secret))

wallet = Wallet(kp)
connection = AsyncClient("https://api.devnet.solana.com")

provider = Provider(connection, wallet)
config = configs["devnet"]

return driftClient.from_config(config, provider)
return DriftClient.from_config(config, provider)


@mark.asyncio
async def test_get_perp_market(
drift_client: driftClient,
drift_client: DriftClient,
):
ix = await drift_client.get_place_perp_order_ix(
OrderParams(
Expand All @@ -62,7 +63,7 @@ async def test_get_perp_market(
price=10 * PRICE_PRECISION,
market_index=0,
reduce_only=False,
post_only=PostOnlyParam.NONE(),
post_only=PostOnlyParams.NONE(),
immediate_or_cancel=False,
max_ts=None,
trigger_price=None,
Expand All @@ -74,9 +75,11 @@ async def test_get_perp_market(
)
)

assert(len(ix.accounts)>5)

assert (
str(ix.keys[3].pubkey) == "5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7"
str(ix.accounts[3].pubkey) == "5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7"
), "incorrect spot oracle address"
assert (
str(ix.keys[4].pubkey) == "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"
str(ix.accounts[4].pubkey) == "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"
), "incorrect perp oracle address"

0 comments on commit d65103d

Please sign in to comment.