-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathEtherScanAPITests.java
79 lines (67 loc) · 2.69 KB
/
EtherScanAPITests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanConnectionException;
import io.goodforgod.api.etherscan.error.EtherScanKeyException;
import io.goodforgod.api.etherscan.http.EthHttpClient;
import io.goodforgod.api.etherscan.http.impl.UrlEthHttpClient;
import io.goodforgod.api.etherscan.model.Balance;
import java.net.URI;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
/**
* @author GoodforGod
* @since 05.11.2018
*/
class EtherScanAPITests extends ApiRunner {
private final EthNetworks network = EthNetworks.SEPOLIA;
@Test
void validKey() {
String validKey = "YourKey";
EtherScanAPI api = EtherScanAPI.builder().withApiKey(validKey).withNetwork(network).build();
assertNotNull(api);
}
@Test
void emptyKey() {
assertThrows(EtherScanKeyException.class, () -> EtherScanAPI.builder().withApiKey("").build());
}
@Test
void blankKey() {
assertThrows(EtherScanKeyException.class,
() -> EtherScanAPI.builder().withApiKey(" ").withNetwork(network).build());
}
@Test
void noTimeoutOnRead() {
Supplier<EthHttpClient> supplier = () -> new UrlEthHttpClient(Duration.ofMillis(300));
EtherScanAPI api = EtherScanAPI.builder().withNetwork(EthNetworks.MAINNET).withHttpClient(supplier).build();
Balance balance = api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
assertNotNull(balance);
}
@Test
void noTimeoutOnReadGroli() {
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
assertNotNull(balance);
}
@Test
void noTimeoutOnReadTobalala() {
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
assertNotNull(balance);
}
@Test
void noTimeoutUnlimitedAwait() {
Balance balance = getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
assertNotNull(balance);
}
@Test
void timeout() throws InterruptedException {
TimeUnit.SECONDS.sleep(5);
Supplier<EthHttpClient> supplier = () -> new UrlEthHttpClient(Duration.ofMillis(300), Duration.ofMillis(300));
EtherScanAPI api = EtherScanAPI.builder()
.withApiKey(getApiKey())
.withNetwork(() -> URI.create("https://api-unknown.etherscan.io/api"))
.withHttpClient(supplier)
.build();
assertThrows(EtherScanConnectionException.class,
() -> api.account().blocksMined("0x0010f94b296A852aAac52EA6c5Ac72e03afD032D"));
}
}