Skip to content

Commit efa0d89

Browse files
committed
test: change credentials, change window
1 parent 46d1381 commit efa0d89

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public interface CryptomarketRestClient extends Closeable {
6464
/**
6565
* Changes the window used in authenticated calls
6666
*
67-
* @param window acceptable time between request and server execution
67+
* @param window acceptable time between request and server execution in millis
6868
*/
6969
public void changeWindow(Integer window);
7070

@@ -1394,7 +1394,7 @@ public String getEstimateWithdrawalFee(String currency, String amount, @Nullable
13941394
* <p>
13951395
* Requires the "Payment information" API key Access Right
13961396
* <p>
1397-
* https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
1397+
* https://api.exchange.cryptomkt.com/#bulk-estimate-withdrawal-fee
13981398
*
13991399
* @param feeRequests a list of fee requests
14001400
* @return the list of fees
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.cryptomarket.sdk;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.util.List;
6+
7+
import org.junit.Test;
8+
9+
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
10+
import com.cryptomarket.sdk.models.Balance;
11+
import com.cryptomarket.sdk.rest.CryptomarketRestClient;
12+
import com.cryptomarket.sdk.rest.CryptomarketRestClientImpl;
13+
14+
public class TestRestClientChangeCredentials {
15+
CryptomarketRestClient client = new CryptomarketRestClientImpl(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
16+
17+
@Test
18+
public void testChangeCredentials() throws CryptomarketSDKException {
19+
List<Balance> balances = client.getWalletBalances();
20+
if (balances.size() == 0)
21+
fail();
22+
balances.forEach(balance -> {
23+
if (balance.getCurrency() == null || balance.getCurrency().equals(""))
24+
fail();
25+
});
26+
27+
client.changeCredentials("null", "null");
28+
try {
29+
balances = client.getWalletBalances();
30+
fail("should fail");
31+
} catch (CryptomarketSDKException e) {
32+
// good
33+
}
34+
client.changeCredentials(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
35+
36+
balances = client.getWalletBalances();
37+
if (balances.size() == 0)
38+
fail();
39+
balances.forEach(balance -> {
40+
if (balance.getCurrency() == null || balance.getCurrency().equals(""))
41+
fail();
42+
});
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.cryptomarket.sdk;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.util.List;
6+
7+
import org.junit.Test;
8+
9+
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
10+
import com.cryptomarket.sdk.models.Balance;
11+
import com.cryptomarket.sdk.rest.CryptomarketRestClient;
12+
import com.cryptomarket.sdk.rest.CryptomarketRestClientImpl;
13+
14+
public class TestRestClientChangeWindow {
15+
CryptomarketRestClient client = new CryptomarketRestClientImpl(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
16+
17+
@Test
18+
public void testChangeCredentials() throws CryptomarketSDKException {
19+
List<Balance> balances = client.getWalletBalances();
20+
if (balances.size() == 0)
21+
fail();
22+
balances.forEach(balance -> {
23+
if (balance.getCurrency() == null || balance.getCurrency().equals(""))
24+
fail();
25+
});
26+
27+
client.changeWindow(100);
28+
try {
29+
balances = client.getWalletBalances();
30+
fail("should fail");
31+
} catch (CryptomarketSDKException e) {
32+
// good
33+
}
34+
client.changeWindow(10_000);
35+
36+
balances = client.getWalletBalances();
37+
if (balances.size() == 0)
38+
fail();
39+
balances.forEach(balance -> {
40+
if (balance.getCurrency() == null || balance.getCurrency().equals(""))
41+
fail();
42+
});
43+
}
44+
}

src/test/java/com/cryptomarket/sdk/TestRestClientWalletManagement.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cryptomarket.sdk;
22

3+
import static org.junit.Assert.assertTrue;
34
import static org.junit.Assert.fail;
45

56
import java.util.List;
@@ -205,6 +206,7 @@ public void testGetTransactionHistoryWithParams() throws CryptomarketSDKExceptio
205206
.offset(0)
206207
.currencies(List.of())
207208
.from("1614815872000"));
209+
assertTrue(transactions.size() > 0);
208210
transactions.forEach(Checker.checkTransaction);
209211
}
210212

src/test/java/com/cryptomarket/sdk/TestWSWalletClient.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package com.cryptomarket.sdk;
22

3+
import com.cryptomarket.params.OrderBy;
4+
import com.cryptomarket.params.ParamsBuilder;
5+
import com.cryptomarket.params.Sort;
6+
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
7+
import com.cryptomarket.sdk.models.Transaction;
38
import com.cryptomarket.sdk.websocket.CryptomarketWSWalletClient;
49
import com.cryptomarket.sdk.websocket.CryptomarketWSWalletClientImpl;
510

11+
import static org.junit.Assert.assertTrue;
12+
613
import java.io.IOException;
14+
import java.util.List;
715

816
import org.junit.After;
917
import org.junit.Before;
@@ -53,4 +61,18 @@ public void testGetTransactions() {
5361
Helpers.sleep(3);
5462
}
5563

64+
@Test
65+
public void testGetTransactionHistoryWithParams() throws CryptomarketSDKException {
66+
wsClient.getTransactions((transactions, exception) -> {
67+
assertTrue(transactions.size() > 0);
68+
transactions.forEach(Checker.checkTransaction);
69+
}, new ParamsBuilder()
70+
.orderBy(OrderBy.CREATED_AT)
71+
.sort(Sort.DESC)
72+
.limit(1000)
73+
.offset(0)
74+
.currencies(List.of())
75+
.from("1614815872000"));
76+
}
77+
5678
}

0 commit comments

Comments
 (0)