-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adding first integration test function + framework (#63)
* test: Creating integration tests
- Loading branch information
Showing
10 changed files
with
335 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ name: Python | |
"on": | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
markers = | ||
integration: mark a test as requiring a full vega sim infrastructure with running backend |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import pytest | ||
|
||
from tests.integration.utils.fixtures import ( | ||
vega_service_with_market, | ||
vega_service, | ||
create_and_faucet_wallet, | ||
WalletConfig, | ||
) | ||
from vega_sim.null_service import VegaServiceNull | ||
import vega_sim.proto.vega as vega_protos | ||
|
||
|
||
LIQ = WalletConfig("liq", "liq") | ||
|
||
|
||
@pytest.mark.integration | ||
def test_submit_amend_liquidity(vega_service_with_market: VegaServiceNull): | ||
vega = vega_service_with_market | ||
market_id = vega.all_markets()[0].id | ||
|
||
create_and_faucet_wallet(vega=vega, wallet=LIQ) | ||
vega.submit_liquidity( | ||
LIQ.name, | ||
market_id=market_id, | ||
commitment_amount=100, | ||
fee=0.001, | ||
buy_specs=[("PEGGED_REFERENCE_MID", 0.5, 1)], | ||
sell_specs=[("PEGGED_REFERENCE_MID", 0.5, 1)], | ||
is_amendment=False, | ||
) | ||
vega.forward("1s") | ||
|
||
liq_provis = vega.party_liquidity_provisions(LIQ.name, market_id=market_id) | ||
|
||
assert len(liq_provis) == 1 | ||
|
||
for provis in [ | ||
liq_provis[0].sells[0].liquidity_order, | ||
liq_provis[0].buys[0].liquidity_order, | ||
]: | ||
assert provis.reference == vega_protos.vega.PeggedReference.PEGGED_REFERENCE_MID | ||
assert provis.offset == "50000" | ||
assert provis.proportion == 1 | ||
|
||
buy_specs = [ | ||
vega_protos.vega.LiquidityOrder( | ||
reference=vega_protos.vega.PeggedReference.PEGGED_REFERENCE_MID, | ||
offset="100000", | ||
proportion=2, | ||
), | ||
vega_protos.vega.LiquidityOrder( | ||
reference=vega_protos.vega.PeggedReference.PEGGED_REFERENCE_BEST_BID, | ||
offset="500000", | ||
proportion=5, | ||
), | ||
] | ||
sell_specs = [ | ||
vega_protos.vega.LiquidityOrder( | ||
reference=vega_protos.vega.PeggedReference.PEGGED_REFERENCE_MID, | ||
offset="500000", | ||
proportion=6, | ||
), | ||
vega_protos.vega.LiquidityOrder( | ||
reference=vega_protos.vega.PeggedReference.PEGGED_REFERENCE_BEST_ASK, | ||
offset="20000", | ||
proportion=1, | ||
), | ||
] | ||
vega.submit_liquidity( | ||
LIQ.name, | ||
market_id=market_id, | ||
commitment_amount=200, | ||
fee=0.005, | ||
buy_specs=[("PEGGED_REFERENCE_MID", 1, 2), ("PEGGED_REFERENCE_BEST_BID", 5, 5)], | ||
sell_specs=[ | ||
("PEGGED_REFERENCE_MID", 5, 6), | ||
("PEGGED_REFERENCE_BEST_ASK", 0.2, 1), | ||
], | ||
is_amendment=True, | ||
) | ||
|
||
vega.forward("1s") | ||
liq_provis = vega.party_liquidity_provisions(LIQ.name, market_id=market_id) | ||
|
||
assert len(liq_provis) == 1 | ||
|
||
for provis, exp_provis in zip(liq_provis[0].sells, sell_specs): | ||
assert provis.liquidity_order.reference == exp_provis.reference | ||
assert provis.liquidity_order.offset == exp_provis.offset | ||
assert provis.liquidity_order.proportion == exp_provis.proportion | ||
|
||
for provis, exp_provis in zip(liq_provis[0].buys, buy_specs): | ||
assert provis.liquidity_order.reference == exp_provis.reference | ||
assert provis.liquidity_order.offset == exp_provis.offset | ||
assert provis.liquidity_order.proportion == exp_provis.proportion |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import pytest | ||
from collections import namedtuple | ||
|
||
from vega_sim.null_service import VegaServiceNull | ||
|
||
WalletConfig = namedtuple("WalletConfig", ["name", "passphrase"]) | ||
|
||
MM_WALLET = WalletConfig("mm", "pin") | ||
|
||
AUCTION1 = WalletConfig("auction1", "auction1") | ||
AUCTION2 = WalletConfig("auction2", "auction2") | ||
|
||
TERMINATE_WALLET = WalletConfig("TERMINATE", "TERMINATE") | ||
|
||
TRADER_WALLET = WalletConfig("TRADER", "TRADER") | ||
|
||
ASSET_NAME = "tDAI" | ||
|
||
WALLETS = [MM_WALLET, AUCTION1, AUCTION2, TERMINATE_WALLET, TRADER_WALLET] | ||
|
||
|
||
def create_and_faucet_wallet( | ||
vega: VegaServiceNull, wallet: WalletConfig, amount: float = 1e4 | ||
): | ||
asset_id = vega.find_asset_id(symbol=ASSET_NAME) | ||
vega.create_wallet(wallet.name, wallet.passphrase) | ||
vega.mint(wallet.name, asset_id, amount) | ||
|
||
|
||
def build_basic_market(vega: VegaServiceNull): | ||
for wallet in WALLETS: | ||
vega.create_wallet(wallet.name, wallet.passphrase) | ||
|
||
vega.mint( | ||
MM_WALLET.name, | ||
asset="VOTE", | ||
amount=1e4, | ||
) | ||
vega.forward("10s") | ||
|
||
# Create asset | ||
vega.create_asset( | ||
MM_WALLET.name, | ||
name=ASSET_NAME, | ||
symbol=ASSET_NAME, | ||
decimals=5, | ||
max_faucet_amount=1e10, | ||
) | ||
vega.forward("10s") | ||
vega.wait_for_datanode_sync() | ||
|
||
asset_id = vega.find_asset_id(symbol=ASSET_NAME) | ||
|
||
for wallet in WALLETS: | ||
vega.mint( | ||
wallet.name, | ||
asset=asset_id, | ||
amount=10000, | ||
) | ||
vega.forward("10s") | ||
vega.create_simple_market( | ||
market_name="CRYPTO:BTCDAI/DEC22", | ||
proposal_wallet=MM_WALLET.name, | ||
settlement_asset_id=asset_id, | ||
termination_wallet=TERMINATE_WALLET.name, | ||
market_decimals=5, | ||
liquidity_commitment=vega.build_new_market_liquidity_commitment( | ||
asset_id=asset_id, | ||
commitment_amount=100, | ||
fee=0.002, | ||
buy_specs=[("PEGGED_REFERENCE_MID", 0.0005, 1)], | ||
sell_specs=[("PEGGED_REFERENCE_MID", 0.0005, 1)], | ||
market_decimals=5, | ||
), | ||
) | ||
market_id = vega.all_markets()[0].id | ||
|
||
# Add transactions in the proposed market to pass opening auction at price 0.3 | ||
vega.submit_order( | ||
trading_wallet=AUCTION1.name, | ||
market_id=market_id, | ||
order_type="TYPE_LIMIT", | ||
time_in_force="TIME_IN_FORCE_GTC", | ||
side="SIDE_BUY", | ||
volume=1, | ||
price=0.3, | ||
) | ||
|
||
vega.submit_order( | ||
trading_wallet=AUCTION2.name, | ||
market_id=market_id, | ||
order_type="TYPE_LIMIT", | ||
time_in_force="TIME_IN_FORCE_GTC", | ||
side="SIDE_SELL", | ||
volume=1, | ||
price=0.3, | ||
) | ||
|
||
vega.submit_order( | ||
trading_wallet=TRADER_WALLET.name, | ||
market_id=market_id, | ||
order_type="TYPE_LIMIT", | ||
time_in_force="TIME_IN_FORCE_GTC", | ||
side="SIDE_BUY", | ||
volume=1, | ||
price=0.29998, | ||
) | ||
vega.submit_order( | ||
trading_wallet=TRADER_WALLET.name, | ||
market_id=market_id, | ||
order_type="TYPE_LIMIT", | ||
time_in_force="TIME_IN_FORCE_GTC", | ||
side="SIDE_SELL", | ||
volume=1, | ||
price=0.30002, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def vega_service(): | ||
with VegaServiceNull(warn_on_raw_data_access=False, run_with_console=False) as vega: | ||
yield vega | ||
|
||
|
||
@pytest.fixture | ||
def vega_service_with_market(vega_service): | ||
build_basic_market(vega_service) | ||
return vega_service |
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