Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit268e5e9

Browse files
committed
[1.1.0-SNAPSHOT]
ApiRunner addedAll tests refactored to use ApiRunnerApiRunner correct key retrival and queue set addedAll tests fixed and improved
1 parent664cb72 commit268e5e9

File tree

34 files changed

+266
-366
lines changed

34 files changed

+266
-366
lines changed

‎src/main/java/io/api/etherscan/core/impl/EtherScanApi.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public EtherScanApi(final String apiKey,
6767
finalSupplier<IHttpExecutor>executorSupplier) {
6868
this(apiKey,network,executorSupplier,
6969
DEFAULT_KEY.equals(apiKey)
70-
?newQueueManager(1,6)
70+
?QueueManager.DEFAULT_KEY_QUEUE
7171
:newFakeQueueManager()
7272
);
7373
}

‎src/main/java/io/api/etherscan/manager/impl/QueueManager.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageio.api.etherscan.manager.impl;
22

3+
importio.api.etherscan.core.impl.EtherScanApi;
34
importio.api.etherscan.manager.IQueueManager;
45

56
importjava.util.concurrent.*;
@@ -14,6 +15,9 @@
1415
*/
1516
publicclassQueueManagerimplementsIQueueManager {
1617

18+
publicstaticfinalQueueManagerDEFAULT_KEY_QUEUE =newQueueManager(1,6);
19+
publicstaticfinalQueueManagerPERSONAL_KEY_QUEUE =newQueueManager(5,1);
20+
1721
privatefinalSemaphoresemaphore;
1822

1923
publicQueueManager(intqueueSize,intqueueResetTimeInSec) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
packageio.api;
2+
3+
importio.api.etherscan.core.impl.EtherScanApi;
4+
importio.api.etherscan.manager.impl.QueueManager;
5+
importio.api.etherscan.model.EthNetwork;
6+
importorg.junit.Assert;
7+
8+
publicclassApiRunnerextendsAssert {
9+
10+
privatestaticfinalEtherScanApiapi;
11+
privatestaticfinalEtherScanApiapiRopsten;
12+
privatestaticfinalEtherScanApiapiRinkeby;
13+
privatestaticfinalEtherScanApiapiKovan;
14+
15+
static {
16+
finalStringapiKey =System.getenv("API_KEY");
17+
finalStringkeyOrDefault = (apiKey ==null ||apiKey.isEmpty())
18+
?EtherScanApi.DEFAULT_KEY
19+
:apiKey;
20+
21+
finalQueueManagerqueue =keyOrDefault.equals(EtherScanApi.DEFAULT_KEY)
22+
?QueueManager.DEFAULT_KEY_QUEUE
23+
:QueueManager.PERSONAL_KEY_QUEUE;
24+
25+
api =newEtherScanApi(keyOrDefault,EthNetwork.MAINNET,queue);
26+
apiRopsten =newEtherScanApi(keyOrDefault,EthNetwork.ROPSTEN,queue);
27+
apiRinkeby =newEtherScanApi(keyOrDefault,EthNetwork.RINKEBY,queue);
28+
apiKovan =newEtherScanApi(keyOrDefault,EthNetwork.KOVAN,queue);
29+
}
30+
31+
publicstaticEtherScanApigetApi() {
32+
returnapi;
33+
}
34+
35+
publicstaticEtherScanApigetApiRopsten() {
36+
returnapiRopsten;
37+
}
38+
39+
publicstaticEtherScanApigetApiRinkeby() {
40+
returnapiRinkeby;
41+
}
42+
43+
publicstaticEtherScanApigetApiKovan() {
44+
returnapiKovan;
45+
}
46+
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageio.api.etherscan;
22

3+
importio.api.ApiRunner;
34
importio.api.etherscan.core.impl.EtherScanApi;
45
importio.api.etherscan.error.ApiException;
56
importio.api.etherscan.error.ApiKeyException;
@@ -9,22 +10,19 @@
910
importio.api.etherscan.model.Balance;
1011
importio.api.etherscan.model.Block;
1112
importio.api.etherscan.model.EthNetwork;
12-
importorg.junit.Assert;
1313
importorg.junit.Test;
1414

1515
importjava.util.List;
1616
importjava.util.function.Supplier;
1717

1818
/**
19-
* ! NO DESCRIPTION !
20-
*
2119
* @author GoodforGod
2220
* @since 05.11.2018
2321
*/
24-
publicclassEtherScanApiTestextendsAssert {
22+
publicclassEtherScanApiTestextendsApiRunner {
2523

26-
privateEthNetworknetwork =EthNetwork.KOVAN;
27-
privateStringvalidKey ="YourKey";
24+
privatefinalEthNetworknetwork =EthNetwork.KOVAN;
25+
privatefinalStringvalidKey ="YourKey";
2826

2927
@Test
3028
publicvoidvalidKey() {
@@ -59,24 +57,20 @@ public void noTimeoutOnRead() {
5957
@Test
6058
publicvoidnoTimeoutOnReadGroli() {
6159
Supplier<IHttpExecutor>supplier = () ->newHttpExecutor(300);
62-
EtherScanApiapi =newEtherScanApi(EthNetwork.GORLI,supplier);
63-
Balancebalance =api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
60+
Balancebalance =getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
6461
assertNotNull(balance);
6562
}
6663

6764
@Test
6865
publicvoidnoTimeoutOnReadTobalala() {
6966
Supplier<IHttpExecutor>supplier = () ->newHttpExecutor(30000);
70-
EtherScanApiapi =newEtherScanApi(EthNetwork.TOBALABA,supplier);
71-
Balancebalance =api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
67+
Balancebalance =getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
7268
assertNotNull(balance);
7369
}
7470

7571
@Test
7672
publicvoidnoTimeoutUnlimitedAwait() {
77-
Supplier<IHttpExecutor>supplier = () ->newHttpExecutor(-30, -300);
78-
EtherScanApiapi =newEtherScanApi(EthNetwork.MAINNET,supplier);
79-
Balancebalance =api.account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
73+
Balancebalance =getApi().account().balance("0xF318ABc9A5a92357c4Fea8d082dade4D43e780B7");
8074
assertNotNull(balance);
8175
}
8276

‎src/test/java/io/api/etherscan/account/AccountBalanceListTest.java‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
packageio.api.etherscan.account;
22

3-
importio.api.etherscan.core.impl.EtherScanApi;
3+
importio.api.ApiRunner;
44
importio.api.etherscan.error.InvalidAddressException;
55
importio.api.etherscan.model.Balance;
66
importio.api.support.AddressUtil;
7-
importorg.junit.Assert;
87
importorg.junit.Test;
98

9+
importjava.math.BigInteger;
1010
importjava.util.ArrayList;
1111
importjava.util.List;
1212

@@ -16,31 +16,29 @@
1616
* @author GoodforGod
1717
* @since 03.11.2018
1818
*/
19-
publicclassAccountBalanceListTestextendsAssert {
20-
21-
privateEtherScanApiapi =newEtherScanApi();
19+
publicclassAccountBalanceListTestextendsApiRunner {
2220

2321
@Test
2422
publicvoidcorrect() {
2523
List<String>addresses =newArrayList<>();
2624
addresses.add("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9");
2725
addresses.add("0xC9F32CE1127e44C51cbD182D6364F3D707Fd0d47");
2826

29-
List<Balance>balances =api.account().balances(addresses);
27+
List<Balance>balances =getApi().account().balances(addresses);
3028
assertNotNull(balances);
3129
assertFalse(balances.isEmpty());
3230
assertEquals(2,balances.size());
3331
assertNotEquals(balances.get(0),balances.get(1));
3432
assertNotEquals(balances.get(0).hashCode(),balances.get(1).hashCode());
35-
for(Balancebalance :balances) {
33+
for(Balancebalance :balances) {
3634
assertNotNull(balance.getAddress());
3735
assertNotNull(balance.getGwei());
3836
assertNotNull(balance.getKwei());
3937
assertNotNull(balance.getMwei());
4038
assertNotNull(balance.getEther());
4139
assertNotNull(balance.getGwei());
4240
assertNotNull(balance.getAddress());
43-
assertNotEquals(0,balance.getWei());
41+
assertNotEquals(BigInteger.ZERO,balance.getWei());
4442
assertNotNull(balance.toString());
4543
}
4644
}
@@ -49,20 +47,15 @@ public void correct() {
4947
publicvoidcorrectMoreThat20Addresses() {
5048
List<String>addresses =AddressUtil.genRealAddresses();
5149

52-
List<Balance>balances =api.account().balances(addresses);
50+
List<Balance>balances =getApi().account().balances(addresses);
5351
assertNotNull(balances);
5452
assertFalse(balances.isEmpty());
5553
assertEquals(25,balances.size());
56-
for(Balancebalance :balances) {
54+
for(Balancebalance :balances) {
5755
assertNotNull(balance.getAddress());
58-
assertNotEquals(0,balance.getWei());
59-
assertNotEquals(0,balance.getKwei());
60-
assertNotEquals(0,balance.getMwei());
61-
assertNotEquals(0,balance.getEther());
62-
assertNotEquals(0,balance.getGwei());
6356
}
6457

65-
assertFalse(balances.get(0).equals(balances.get(1)));
58+
assertNotEquals(balances.get(0),balances.get(1));
6659
}
6760

6861
@Test(expected =InvalidAddressException.class)
@@ -71,13 +64,13 @@ public void invalidParamWithError() {
7164
addresses.add("0x9327cb34984c3992ec1EA0eAE98Ccf80A74f95B9");
7265
addresses.add("C9F32CE1127e44C51cbD182D6364F3D707Fd0d47");
7366

74-
api.account().balances(addresses);
67+
getApi().account().balances(addresses);
7568
}
7669

7770
@Test
7871
publicvoidemptyParamList() {
7972
List<String>addresses =newArrayList<>();
80-
List<Balance>balances =api.account().balances(addresses);
73+
List<Balance>balances =getApi().account().balances(addresses);
8174
assertNotNull(balances);
8275
assertTrue(balances.isEmpty());
8376
}
@@ -88,11 +81,11 @@ public void correctParamWithEmptyExpectedResult() {
8881
addresses.add("0x1327cb34984c3992ec1EA0eAE98Ccf80A74f95B9");
8982
addresses.add("0xC1F32CE1127e44C51cbD182D6364F3D707Fd0d47");
9083

91-
List<Balance>balances =api.account().balances(addresses);
84+
List<Balance>balances =getApi().account().balances(addresses);
9285
assertNotNull(balances);
9386
assertFalse(balances.isEmpty());
9487
assertEquals(2,balances.size());
95-
for(Balancebalance :balances) {
88+
for(Balancebalance :balances) {
9689
assertNotNull(balance.getAddress());
9790
assertEquals(0,balance.getWei().intValue());
9891
}

‎src/test/java/io/api/etherscan/account/AccountBalanceTest.java‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
packageio.api.etherscan.account;
22

3+
importio.api.ApiRunner;
34
importio.api.etherscan.core.impl.EtherScanApi;
45
importio.api.etherscan.error.InvalidAddressException;
56
importio.api.etherscan.model.Balance;
6-
importio.api.etherscan.model.EthNetwork;
7-
importorg.junit.Assert;
87
importorg.junit.Test;
98
importorg.junit.runner.RunWith;
109
importorg.junit.runners.Parameterized;
@@ -20,12 +19,12 @@
2019
* @since 03.11.2018
2120
*/
2221
@RunWith(Parameterized.class)
23-
publicclassAccountBalanceTestextendsAssert {
22+
publicclassAccountBalanceTestextendsApiRunner {
2423

25-
privateEtherScanApiapi;
26-
privateStringaddressCorrect;
27-
privateStringaddressInvalid;
28-
privateStringaddressNoResponse;
24+
privatefinalEtherScanApiapi;
25+
privatefinalStringaddressCorrect;
26+
privatefinalStringaddressInvalid;
27+
privatefinalStringaddressNoResponse;
2928

3029
publicAccountBalanceTest(EtherScanApiapi,StringaddressCorrect,StringaddressInvalid,StringaddressNoResponse) {
3130
this.api =api;
@@ -36,31 +35,13 @@ public AccountBalanceTest(EtherScanApi api, String addressCorrect, String addres
3635

3736
@Parameters
3837
publicstaticCollectiondata() {
39-
returnArrays.asList(newObject[][]{
38+
returnArrays.asList(newObject[][]{
4039
{
41-
newEtherScanApi(),
40+
getApi(),
4241
"0x8d4426f94e42f721C7116E81d6688cd935cB3b4F",
4342
"8d4426f94e42f721C7116E81d6688cd935cB3b4F",
4443
"0x1d4426f94e42f721C7116E81d6688cd935cB3b4F"
45-
},
46-
{
47-
newEtherScanApi(EthNetwork.ROPSTEN),
48-
"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
49-
"xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
50-
"0x1dbd2b932c763ba5b1b7ae3b362eac3e8d40121a"
51-
},
52-
{
53-
newEtherScanApi(EthNetwork.RINKEBY),
54-
"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
55-
"xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
56-
"0x1dbd2b932c763ba5b1b7ae3b362eac3e8d40121a"
57-
},
58-
{
59-
newEtherScanApi(EthNetwork.KOVAN),
60-
"0xB9F36EE9df7E2A24B61b1738F4127BFDe8bA1A87",
61-
"xB9F36EE9df7E2A24B61b1738F4127BFDe8bA1A87",
62-
"0xB1F36EE9df7E2A24B61b1738F4127BFDe8bA1A87"
63-
},
44+
}
6445
});
6546
}
6647

@@ -74,13 +55,12 @@ public void correct() {
7455
assertNotNull(balance.getGwei());
7556
assertNotNull(balance.getEther());
7657
assertNotNull(balance.getAddress());
77-
assertNotEquals(0,balance.getWei());
7858
assertNotNull(balance.toString());
7959
}
8060

8161
@Test(expected =InvalidAddressException.class)
8262
publicvoidinvalidParamWithError() {
83-
Balancebalance =api.account().balance(addressInvalid);
63+
Balancebalance =getApi().account().balance(addressInvalid);
8464
}
8565

8666
@Test

‎src/test/java/io/api/etherscan/account/AccountMinedBlocksTest.java‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
packageio.api.etherscan.account;
22

3+
importio.api.ApiRunner;
34
importio.api.etherscan.core.impl.EtherScanApi;
45
importio.api.etherscan.error.InvalidAddressException;
56
importio.api.etherscan.model.Block;
6-
importio.api.etherscan.model.EthNetwork;
7-
importorg.junit.Assert;
87
importorg.junit.Test;
98
importorg.junit.runner.RunWith;
109
importorg.junit.runners.Parameterized;
@@ -21,13 +20,13 @@
2120
* @since 03.11.2018
2221
*/
2322
@RunWith(Parameterized.class)
24-
publicclassAccountMinedBlocksTestextendsAssert {
23+
publicclassAccountMinedBlocksTestextendsApiRunner {
2524

26-
privateEtherScanApiapi;
27-
privateintblocksMined;
28-
privateStringaddressCorrect;
29-
privateStringaddressInvalid;
30-
privateStringaddressNoResponse;
25+
privatefinalEtherScanApiapi;
26+
privatefinalintblocksMined;
27+
privatefinalStringaddressCorrect;
28+
privatefinalStringaddressInvalid;
29+
privatefinalStringaddressNoResponse;
3130

3231
publicAccountMinedBlocksTest(EtherScanApiapi,
3332
intblocksMined,
@@ -43,22 +42,14 @@ public AccountMinedBlocksTest(EtherScanApi api,
4342

4443
@Parameters
4544
publicstaticCollectiondata() {
46-
returnArrays.asList(newObject[][]{
45+
returnArrays.asList(newObject[][]{
4746
{
48-
newEtherScanApi(),
47+
getApi(),
4948
223,
5049
"0xE4C6175183029A0f039bf2DFffa5C6e8F3cA9B23",
5150
"xE4C6175183029A0f039bf2DFffa5C6e8F3cA9B23",
5251
"0xE1C6175183029A0f039bf2DFffa5C6e8F3cA9B23",
53-
},
54-
{
55-
newEtherScanApi(EthNetwork.ROPSTEN),
56-
1,
57-
"0x0923DafEB5A5d11a83E188d5dbCdEd14f9b161a7",
58-
"00923DafEB5A5d11a83E188d5dbCdEd14f9b161a7",
59-
"0x1923DafEB5A5d11a83E188d5dbCdEd14f9b161a7",
6052
}
61-
// Other netWorks not presented due to 30k+ mined blocks, tests runs forever
6253
});
6354
}
6455

@@ -71,15 +62,15 @@ public void correct() {
7162
assertBlocks(blocks);
7263
assertNotNull(blocks.get(0).toString());
7364

74-
if(blocks.size() >1) {
65+
if(blocks.size() >1) {
7566
assertNotEquals(blocks.get(0),blocks.get(1));
7667
assertNotEquals(blocks.get(0).hashCode(),blocks.get(1).hashCode());
7768
}
7869
}
7970

8071
@Test(expected =InvalidAddressException.class)
8172
publicvoidinvalidParamWithError() {
82-
List<Block>txs =api.account().minedBlocks(addressInvalid);
73+
List<Block>txs =getApi().account().minedBlocks(addressInvalid);
8374
}
8475

8576
@Test

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp