mango-explorer/tests/test_instructions.py

110 lines
4.6 KiB
Python
Raw Normal View History

import typing
from .context import mango
from .fakes import fake_context, fake_market, fake_seeded_public_key, fake_token, fake_wallet
from decimal import Decimal
from pyserum.enums import OrderType, Side
from pyserum.market.market import Market
from solana.publickey import PublicKey
from solana.transaction import TransactionInstruction
def test_build_create_spl_account_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
token: mango.Token = fake_token()
new_spl_account: PublicKey = fake_seeded_public_key("new SPL account")
actual = mango.build_create_spl_account_instructions(context, wallet, token, new_spl_account)
assert actual is not None
assert len(actual) == 2
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
assert actual[1] is not None
assert isinstance(actual[1], TransactionInstruction)
def test_build_transfer_spl_tokens_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
token: mango.Token = fake_token()
source: PublicKey = fake_seeded_public_key("source SPL account")
destination: PublicKey = fake_seeded_public_key("destination SPL account")
quantity: int = 7
actual = mango.build_transfer_spl_tokens_instructions(context, wallet, token, source, destination, quantity)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
def test_build_close_spl_account_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
address: PublicKey = fake_seeded_public_key("target SPL account")
actual = mango.build_close_spl_account_instructions(context, wallet, address)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
def test_build_create_serum_open_orders_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
market: Market = fake_market()
open_orders_address: PublicKey = fake_seeded_public_key("open orders account")
actual = mango.build_create_serum_open_orders_instructions(context, wallet, market, open_orders_address)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
def test_build_serum_place_order_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
market: Market = fake_market()
source: PublicKey = fake_seeded_public_key("source")
open_orders_address: PublicKey = fake_seeded_public_key("open orders account")
order_type: OrderType = OrderType.IOC
side: Side = Side.BUY
price: Decimal = Decimal(72)
quantity: Decimal = Decimal("0.05")
client_id: int = 53
fee_discount_address: PublicKey = fake_seeded_public_key("fee discount address")
actual = mango.build_serum_place_order_instructions(
context, wallet, market, source, open_orders_address, order_type, side, price, quantity, client_id, fee_discount_address)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
def test_build_serum_consume_events_instructions():
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
market = fake_market()
open_orders_addresses: typing.Sequence[PublicKey] = [fake_seeded_public_key("open orders account")]
limit: int = 64
actual = mango.build_serum_consume_events_instructions(context, wallet, market, open_orders_addresses, limit)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)
def test_build_serum_settle_instructions():
market = fake_market()
context: mango.Context = fake_context()
wallet: mango.Wallet = fake_wallet()
open_orders_address: PublicKey = fake_seeded_public_key("open orders account")
base_token_account_address: PublicKey = fake_seeded_public_key("base token account")
quote_token_account_address: PublicKey = fake_seeded_public_key("quote token account")
actual = mango.build_serum_settle_instructions(
context, wallet, market, open_orders_address, base_token_account_address, quote_token_account_address)
assert actual is not None
assert len(actual) == 1
assert actual[0] is not None
assert isinstance(actual[0], TransactionInstruction)