Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test file types #21989

Merged
merged 13 commits into from
May 24, 2024
4 changes: 2 additions & 2 deletions ts/src/test/Exchange/base/test.currency.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Exchange } from "../../../../ccxt";
import { Currency, Exchange } from "../../../../ccxt";
import testSharedMethods from './test.sharedMethods.js';

function testCurrency (exchange: Exchange, skippedProperties: object, method: string, entry: object) {
function testCurrency (exchange: Exchange, skippedProperties: object, method: string, entry: Currency) {
const format = {
'id': 'btc', // string literal for referencing within an exchange
'code': 'BTC', // uppercase string literal of a pair of currencies
Expand Down
44 changes: 23 additions & 21 deletions ts/src/test/Exchange/base/test.sharedMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import assert from 'assert';
import { Exchange } from "../../../../ccxt";
import Precise from '../../../base/Precise.js';
import { OnMaintenance, OperationFailed } from '../../../base/errors.js';
import { Str } from '../../../base/types';

function logTemplate (exchange: Exchange, method: string, entry: object) {
return ' <<< ' + exchange.id + ' ' + method + ' ::: ' + exchange.json (entry) + ' >>> ';
}

function isTemporaryFailure (e) {
function isTemporaryFailure (e: any) {
return (e instanceof OperationFailed) && (!(e instanceof OnMaintenance));
}

function stringValue (value) {
function stringValue (value: any) {
let stringVal = undefined;
if (typeof value === 'string') {
stringVal = value;
Expand All @@ -23,7 +24,7 @@ function stringValue (value) {
return stringVal;
}

function assertType (exchange: Exchange, skippedProperties: object, entry: object, key, format) {
function assertType (exchange: Exchange, skippedProperties: object, entry: object, key: string | number, format: object) {
if (key in skippedProperties) {
return undefined;
}
Expand All @@ -39,7 +40,7 @@ function assertType (exchange: Exchange, skippedProperties: object, entry: objec
return result;
}

function assertStructure (exchange: Exchange, skippedProperties: object, method: string, entry: object, format, emptyAllowedFor = []) {
function assertStructure (exchange: Exchange, skippedProperties: object, method: string, entry: object, format: any[] | object, emptyAllowedFor = []) {
const logText = logTemplate (exchange, method, entry);
assert (entry, 'item is null/undefined' + logText);
// get all expected & predefined keys for this specific item and ensure thos ekeys exist in parsed structure
Expand Down Expand Up @@ -96,7 +97,7 @@ function assertStructure (exchange: Exchange, skippedProperties: object, method:
}
}

function assertTimestamp (exchange: Exchange, skippedProperties: object, method: string, entry: object, nowToCheck: any = undefined, keyNameOrIndex : any = 'timestamp') {
function assertTimestamp (exchange: Exchange, skippedProperties: object, method: string, entry: object, nowToCheck: any = undefined, keyNameOrIndex : string | number = 'timestamp') {
const logText = logTemplate (exchange, method, entry);
const skipValue = exchange.safeValue (skippedProperties, keyNameOrIndex);
if (skipValue !== undefined) {
Expand Down Expand Up @@ -148,7 +149,7 @@ function assertTimestampAndDatetime (exchange: Exchange, skippedProperties: obje
}
}

function assertCurrencyCode (exchange: Exchange, skippedProperties: object, method: string, entry: object, actualCode, expectedCode = undefined) {
function assertCurrencyCode (exchange: Exchange, skippedProperties: object, method: string, entry: object, actualCode: Str, expectedCode: Str = undefined) {
if (('currency' in skippedProperties) || ('currencyIdAndCode' in skippedProperties)) {
return;
}
Expand Down Expand Up @@ -181,7 +182,7 @@ function assertValidCurrencyIdAndCode (exchange: Exchange, skippedProperties: ob
}
}

function assertSymbol (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, expectedSymbol = undefined) {
function assertSymbol (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, expectedSymbol: Str = undefined) {
if (key in skippedProperties) {
return;
}
Expand All @@ -203,7 +204,7 @@ function assertSymbolInMarkets (exchange: Exchange, skippedProperties: object, m
}


function assertGreater (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertGreater (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -214,7 +215,7 @@ function assertGreater (exchange: Exchange, skippedProperties: object, method: s
}
}

function assertGreaterOrEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertGreaterOrEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -225,7 +226,7 @@ function assertGreaterOrEqual (exchange: Exchange, skippedProperties: object, me
}
}

function assertLess (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertLess (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -236,7 +237,7 @@ function assertLess (exchange: Exchange, skippedProperties: object, method: stri
}
}

function assertLessOrEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertLessOrEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -247,7 +248,7 @@ function assertLessOrEqual (exchange: Exchange, skippedProperties: object, metho
}
}

function assertEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -258,7 +259,7 @@ function assertEqual (exchange: Exchange, skippedProperties: object, method: str
}
}

function assertNonEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, compareTo) {
function assertNonEqual (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, compareTo: string) {
if (key in skippedProperties) {
return;
}
Expand All @@ -269,7 +270,7 @@ function assertNonEqual (exchange: Exchange, skippedProperties: object, method:
}
}

function assertInArray (exchange: Exchange, skippedProperties: object, method: string, entry: object, key, expectedArray) {
function assertInArray (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number, expectedArray: any[]) {
if (key in skippedProperties) {
return;
}
Expand All @@ -282,10 +283,11 @@ function assertInArray (exchange: Exchange, skippedProperties: object, method: s
}
}

function assertFeeStructure (exchange: Exchange, skippedProperties: object, method: string, entry: object, key) {
function assertFeeStructure (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number) {
const logText = logTemplate (exchange, method, entry);
const keyString = stringValue (key);
if (Number.isInteger (key)) {
key = key as number;
assert (Array.isArray (entry), 'fee container is expected to be an array' + logText);
assert (key < entry.length, 'fee key ' + keyString + ' was expected to be present in entry' + logText);
} else {
Expand All @@ -302,7 +304,7 @@ function assertFeeStructure (exchange: Exchange, skippedProperties: object, meth
}
}

function assertTimestampOrder (exchange: Exchange, method: string, codeOrSymbol: string, items, ascending = true) {
function assertTimestampOrder (exchange: Exchange, method: string, codeOrSymbol: string, items: any[], ascending = true) {
for (let i = 0; i < items.length; i++) {
if (i > 0) {
const currentTs = items[i - 1]['timestamp'];
Expand All @@ -316,7 +318,7 @@ function assertTimestampOrder (exchange: Exchange, method: string, codeOrSymbol:
}
}

function assertInteger (exchange: Exchange, skippedProperties: object, method: string, entry: object, key) {
function assertInteger (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number) {
if (key in skippedProperties) {
return;
}
Expand All @@ -330,7 +332,7 @@ function assertInteger (exchange: Exchange, skippedProperties: object, method: s
}
}

function checkPrecisionAccuracy (exchange: Exchange, skippedProperties: object, method: string, entry: object, key) {
function checkPrecisionAccuracy (exchange: Exchange, skippedProperties: object, method: string, entry: object, key: string | number) {
if (key in skippedProperties) {
return;
}
Expand Down Expand Up @@ -366,14 +368,14 @@ function removeProxyOptions (exchange: Exchange, skippedProperties: object) {
return [ proxyUrl, httpProxy, httpsProxy, socksProxy ];
}

function setProxyOptions (exchange: Exchange, skippedProperties: object, proxyUrl, httpProxy, httpsProxy, socksProxy) {
function setProxyOptions (exchange: Exchange, skippedProperties: object, proxyUrl: string, httpProxy: string, httpsProxy: string, socksProxy: string) {
exchange.proxyUrl = proxyUrl;
exchange.httpProxy = httpProxy;
exchange.httpsProxy = httpsProxy;
exchange.socksProxy = socksProxy;
}

samgermain marked this conversation as resolved.
Show resolved Hide resolved
function assertNonEmtpyArray (exchange, skippedProperties, method, entry, hint = undefined) {
function assertNonEmtpyArray (exchange: Exchange, skippedProperties: object, method: string, entry: any[] | object, hint: Str = undefined) {
let logText = logTemplate (exchange, method, entry);
if (hint !== undefined) {
logText = logText + ' ' + hint;
Expand All @@ -385,7 +387,7 @@ function assertNonEmtpyArray (exchange, skippedProperties, method, entry, hint =
assert (entry.length > 0, 'response is expected to be a non-empty array' + logText + ' (add "emptyResponse" in skip-tests.json to skip this check)');
}

function assertRoundMinuteTimestamp (exchange, skippedProperties, method, entry, key) {
function assertRoundMinuteTimestamp (exchange: Exchange, skippedProperties: object, method: string, entry: any[] | object, key: string | number) {
if (key in skippedProperties) {
return;
}
Expand Down