Skip to content

Commit d13f5a4

Browse files
committed
[1.1.0-SNAPSHOT]
Rest before timeout check for api not exceed rate
1 parent 315ef5f commit d13f5a4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/test/java/io/api/ApiRunner.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ public class ApiRunner extends Assert {
1111
private static final EtherScanApi apiRopsten;
1212
private static final EtherScanApi apiRinkeby;
1313
private static final EtherScanApi apiKovan;
14+
private static final String key;
1415

1516
static {
1617
final String apiKey = System.getenv("API_KEY");
17-
final String keyOrDefault = (apiKey == null || apiKey.isEmpty())
18+
key = (apiKey == null || apiKey.isEmpty())
1819
? EtherScanApi.DEFAULT_KEY
1920
: apiKey;
2021

21-
final QueueManager queue = keyOrDefault.equals(EtherScanApi.DEFAULT_KEY)
22+
final QueueManager queue = key.equals(EtherScanApi.DEFAULT_KEY)
2223
? QueueManager.DEFAULT_KEY_QUEUE
2324
: new QueueManager(1, 2);
2425

25-
api = new EtherScanApi(keyOrDefault, EthNetwork.MAINNET, queue);
26-
apiRopsten = new EtherScanApi(keyOrDefault, EthNetwork.ROPSTEN, queue);
27-
apiRinkeby = new EtherScanApi(keyOrDefault, EthNetwork.RINKEBY, queue);
28-
apiKovan = new EtherScanApi(keyOrDefault, EthNetwork.KOVAN, queue);
26+
api = new EtherScanApi(key, EthNetwork.MAINNET, queue);
27+
apiRopsten = new EtherScanApi(key, EthNetwork.ROPSTEN, queue);
28+
apiRinkeby = new EtherScanApi(key, EthNetwork.RINKEBY, queue);
29+
apiKovan = new EtherScanApi(key, EthNetwork.KOVAN, queue);
30+
}
31+
32+
public static String getKey() {
33+
return key;
2934
}
3035

3136
public static EtherScanApi getApi() {

src/test/java/io/api/etherscan/EtherScanApiTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.Test;
1414

1515
import java.util.List;
16+
import java.util.concurrent.TimeUnit;
1617
import java.util.function.Supplier;
1718

1819
/**
@@ -75,9 +76,10 @@ public void noTimeoutUnlimitedAwait() {
7576
}
7677

7778
@Test(expected = ApiTimeoutException.class)
78-
public void timeout() {
79+
public void timeout() throws InterruptedException {
80+
TimeUnit.SECONDS.sleep(5);
7981
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(300, 300);
80-
EtherScanApi api = new EtherScanApi(EthNetwork.KOVAN, supplier);
82+
EtherScanApi api = new EtherScanApi(getKey(), EthNetwork.KOVAN, supplier);
8183
List<Block> blocks = api.account().minedBlocks("0x0010f94b296A852aAac52EA6c5Ac72e03afD032D");
8284
assertNotNull(blocks);
8385
}

0 commit comments

Comments
 (0)