94 lines
3.2 KiB
Python
94 lines
3.2 KiB
Python
import os
|
|
import sys
|
|
|
|
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
|
sys.path.append(root)
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
|
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import ccxt # noqa: F402
|
|
|
|
def helper_test_handle_market_type_and_params():
|
|
exchange = ccxt.Exchange({
|
|
'id': 'sampleexchange',
|
|
'options': {
|
|
'defaultType': 'valueFromOptions',
|
|
'fetchX': {
|
|
'defaultType': 'valueFromMethodOptions',
|
|
},
|
|
},
|
|
})
|
|
initial_params = {
|
|
'defaultType': 'valueFromParam',
|
|
}
|
|
market = exchange.safe_market('TEST1/TEST2')
|
|
market['type'] = 'spot'
|
|
#
|
|
# ########### test different variations ###########
|
|
#
|
|
# case #1, should prevail: param
|
|
#
|
|
[market_type_1, params1] = exchange.handle_market_type_and_params('fetchX', market, initial_params, 'valueDefault')
|
|
assert 'defaultType' in initial_params
|
|
assert not ('defaultType' in params1)
|
|
assert market_type_1 == 'valueFromParam'
|
|
#
|
|
# case #2, should prevail: market.type
|
|
#
|
|
[market_type_2, params2] = exchange.handle_market_type_and_params('fetchX', market, {}, 'valueDefault')
|
|
assert market_type_2 == 'spot'
|
|
#
|
|
# case #3, should prevail: valueDefault
|
|
#
|
|
[market_type_3, params3] = exchange.handle_market_type_and_params('fetchX', None, {}, 'valueDefault')
|
|
assert market_type_3 == 'valueDefault'
|
|
#
|
|
# case #4, should prevail: method options
|
|
#
|
|
[market_type_4, params4] = exchange.handle_market_type_and_params('fetchX', None, {})
|
|
assert market_type_4 == 'valueFromMethodOptions'
|
|
#
|
|
# case #5, should prevail: options
|
|
#
|
|
[market_type_5, params5] = exchange.handle_market_type_and_params('fetchY', None, {}, None)
|
|
assert market_type_5 == 'valueFromOptions'
|
|
#
|
|
# case #6, should prevail: spot (because hardcoded in base)
|
|
#
|
|
exchange.options['defaultType'] = None
|
|
[market_type_6, params6] = exchange.handle_market_type_and_params('fetchY', None, {}, None)
|
|
assert market_type_6 == 'spot'
|
|
# fake assertion to avoid unused vars
|
|
assert params1 is not None or params2 is not None or params3 is not None or params4 is not None or params5 is not None or params6 is not None
|
|
|
|
|
|
def helper_test_handle_network_request():
|
|
exchange = ccxt.Exchange({
|
|
'id': 'sampleexchange',
|
|
'options': {
|
|
'networks': {
|
|
'XYZ': 'Xyz',
|
|
},
|
|
},
|
|
})
|
|
exchange.currencies = exchange.create_safe_dictionary() # todo: initialize in C# base files
|
|
currency_code = 'ETH' # todo: in future with complex cases
|
|
# no-case
|
|
[request1, params1] = exchange.handle_request_network({
|
|
'network': 'XYZ',
|
|
}, {}, 'chain_id', currency_code, False)
|
|
assert not ('network' in params1)
|
|
assert 'chain_id' in request1
|
|
assert request1['chain_id'] == 'Xyz'
|
|
|
|
|
|
def test_handle_methods():
|
|
helper_test_handle_market_type_and_params()
|
|
helper_test_handle_network_request()
|