MCPcopy
hub / github.com/ccxt/ccxt / testBalance

Method testBalance

java/tests/src/main/java/tests/exchange/TestBalance.java:14–56  ·  view source on GitHub ↗
(Exchange exchange, Object skippedProperties, Object method, Object entry)

Source from the content-addressed store, hash-verified

12
13public class TestBalance extends BaseTest {
14 public static void testBalance(Exchange exchange, Object skippedProperties, Object method, Object entry)
15 {
16 Object format = new java.util.HashMap<String, Object>() {{
17 put( "free", new java.util.HashMap<String, Object>() {{}} );
18 put( "used", new java.util.HashMap<String, Object>() {{}} );
19 put( "total", new java.util.HashMap<String, Object>() {{}} );
20 put( "info", new java.util.HashMap<String, Object>() {{}} );
21 }};
22 TestSharedMethods.AssertStructure(exchange, skippedProperties, method, entry, format);
23 Object logText = TestSharedMethods.logTemplate(exchange, method, entry);
24 //
25 Object codesTotal = Helpers.objectKeys(Helpers.GetValue(entry, "total"));
26 Object codesFree = Helpers.objectKeys(Helpers.GetValue(entry, "free"));
27 Object codesUsed = Helpers.objectKeys(Helpers.GetValue(entry, "used"));
28 TestSharedMethods.AssertNonEmtpyArray(exchange, skippedProperties, method, codesTotal, "total");
29 TestSharedMethods.AssertNonEmtpyArray(exchange, skippedProperties, method, codesFree, "free");
30 TestSharedMethods.AssertNonEmtpyArray(exchange, skippedProperties, method, codesUsed, "used");
31 Object allCodes = exchange.arrayConcat(codesTotal, codesFree);
32 allCodes = exchange.arrayConcat(allCodes, codesUsed);
33 Object codesLength = Helpers.getArrayLength(codesTotal);
34 Object freeLength = Helpers.getArrayLength(codesFree);
35 Object usedLength = Helpers.getArrayLength(codesUsed);
36 Assert(Helpers.isTrue((Helpers.isEqual(codesLength, freeLength))) || Helpers.isTrue((Helpers.isEqual(codesLength, usedLength))), Helpers.add("free and total and used codes have different lengths", logText));
37 for (var i = 0; Helpers.isLessThan(i, Helpers.getArrayLength(allCodes)); i++)
38 {
39 Object code = Helpers.GetValue(allCodes, i);
40 // TestSharedMethods.AssertCurrencyCode (exchange, skippedProperties, method, entry, code);
41 Assert(Helpers.inOp(Helpers.GetValue(entry, "total"), code), Helpers.add(Helpers.add(Helpers.add("code ", code), " not in total"), logText));
42 Assert(Helpers.inOp(Helpers.GetValue(entry, "free"), code), Helpers.add(Helpers.add(Helpers.add("code ", code), " not in free"), logText));
43 Assert(Helpers.inOp(Helpers.GetValue(entry, "used"), code), Helpers.add(Helpers.add(Helpers.add("code ", code), " not in used"), logText));
44 Object total = exchange.safeString(Helpers.GetValue(entry, "total"), code);
45 Object free = exchange.safeString(Helpers.GetValue(entry, "free"), code);
46 Object used = exchange.safeString(Helpers.GetValue(entry, "used"), code);
47 Assert(!Helpers.isEqual(total, null), Helpers.add("total is undefined", logText));
48 Assert(!Helpers.isEqual(free, null), Helpers.add("free is undefined", logText));
49 Assert(!Helpers.isEqual(used, null), Helpers.add("used is undefined", logText));
50 Assert(Precise.stringGe(total, "0"), Helpers.add("total is not positive", logText));
51 Assert(Precise.stringGe(free, "0"), Helpers.add("free is not positive", logText));
52 Assert(Precise.stringGe(used, "0"), Helpers.add("used is not positive", logText));
53 Object sumFreeUsed = Precise.stringAdd(free, used);
54 Assert(Precise.stringEq(total, sumFreeUsed), Helpers.add("free and used do not sum to total", logText));
55 }
56 }
57
58}

Callers 2

testFetchBalanceMethod · 0.95
testWatchBalanceMethod · 0.95

Calls 15

AssertStructureMethod · 0.95
logTemplateMethod · 0.95
objectKeysMethod · 0.95
GetValueMethod · 0.95
AssertNonEmtpyArrayMethod · 0.95
getArrayLengthMethod · 0.95
isTrueMethod · 0.95
isEqualMethod · 0.95
addMethod · 0.95
isLessThanMethod · 0.95
inOpMethod · 0.95
stringGeMethod · 0.95

Tested by

no test coverage detected