2021-06-08 16:47:15 -07:00
|
|
|
import typing
|
|
|
|
|
2021-06-07 07:10:18 -07:00
|
|
|
from .context import mango
|
2021-06-25 09:21:53 -07:00
|
|
|
from .fakes import fake_context, fake_market, fake_seeded_public_key, fake_token, fake_wallet
|
2021-06-07 07:10:18 -07:00
|
|
|
|
|
|
|
from decimal import Decimal
|
2021-06-08 16:47:15 -07:00
|
|
|
from pyserum.enums import OrderType, Side
|
|
|
|
from pyserum.market.market import Market
|
2021-06-07 07:10:18 -07:00
|
|
|
from solana.publickey import PublicKey
|
2021-06-25 09:21:53 -07:00
|
|
|
from solana.transaction import TransactionInstruction
|
2021-06-07 07:10:18 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_create_spl_account_instructions():
|
2021-06-08 06:05:00 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
2021-06-08 06:05:00 -07:00
|
|
|
token: mango.Token = fake_token()
|
|
|
|
new_spl_account: PublicKey = fake_seeded_public_key("new SPL account")
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_create_spl_account_instructions(context, wallet, token, new_spl_account)
|
2021-06-08 06:05:00 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 1
|
|
|
|
assert len(actual.instructions) == 2
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
|
|
|
assert actual.instructions[1] is not None
|
|
|
|
assert isinstance(actual.instructions[1], TransactionInstruction)
|
2021-06-08 06:05:00 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_transfer_spl_tokens_instructions():
|
2021-06-08 06:05:00 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
2021-06-08 06:05:00 -07:00
|
|
|
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
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_transfer_spl_tokens_instructions(context, wallet, token, source, destination, quantity)
|
2021-06-08 06:05:00 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 0
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
2021-06-08 06:05:00 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_close_spl_account_instructions():
|
2021-06-08 06:05:00 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
2021-06-08 06:05:00 -07:00
|
|
|
address: PublicKey = fake_seeded_public_key("target SPL account")
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_close_spl_account_instructions(context, wallet, address)
|
2021-06-08 06:05:00 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 0
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
2021-06-08 06:05:00 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_create_serum_open_orders_instructions():
|
2021-06-08 16:47:15 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
|
|
|
market: Market = fake_market()
|
2021-07-01 13:24:08 -07:00
|
|
|
actual = mango.build_create_serum_open_orders_instructions(context, wallet, market)
|
2021-06-08 16:47:15 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 1
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
2021-06-08 16:47:15 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_serum_place_order_instructions():
|
2021-06-08 16:47:15 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
|
|
|
market: Market = fake_market()
|
2021-06-08 16:47:15 -07:00
|
|
|
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
|
2021-06-09 07:20:13 -07:00
|
|
|
fee_discount_address: PublicKey = fake_seeded_public_key("fee discount address")
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_serum_place_order_instructions(
|
2021-06-09 07:20:13 -07:00
|
|
|
context, wallet, market, source, open_orders_address, order_type, side, price, quantity, client_id, fee_discount_address)
|
2021-06-08 16:47:15 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 0
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
2021-06-25 09:21:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_build_serum_consume_events_instructions():
|
2021-06-08 16:47:15 -07:00
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
|
|
|
market = fake_market()
|
2021-06-25 07:50:37 -07:00
|
|
|
open_orders_addresses: typing.Sequence[PublicKey] = [fake_seeded_public_key("open orders account")]
|
2021-06-08 16:47:15 -07:00
|
|
|
limit: int = 64
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_serum_consume_events_instructions(context, wallet, market, open_orders_addresses, limit)
|
2021-06-08 16:47:15 -07:00
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 0
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|
2021-06-08 16:47:15 -07:00
|
|
|
|
|
|
|
|
2021-06-25 09:21:53 -07:00
|
|
|
def test_build_serum_settle_instructions():
|
2021-06-08 16:47:15 -07:00
|
|
|
market = fake_market()
|
|
|
|
context: mango.Context = fake_context()
|
2021-06-25 09:21:53 -07:00
|
|
|
wallet: mango.Wallet = fake_wallet()
|
2021-06-08 16:47:15 -07:00
|
|
|
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")
|
2021-06-25 09:21:53 -07:00
|
|
|
actual = mango.build_serum_settle_instructions(
|
2021-06-08 16:47:15 -07:00
|
|
|
context, wallet, market, open_orders_address, base_token_account_address, quote_token_account_address)
|
|
|
|
assert actual is not None
|
2021-07-01 13:24:08 -07:00
|
|
|
assert len(actual.signers) == 0
|
|
|
|
assert len(actual.instructions) == 1
|
|
|
|
assert actual.instructions[0] is not None
|
|
|
|
assert isinstance(actual.instructions[0], TransactionInstruction)
|