Skip to content

Commit 14ccb53

Browse files
committed
[2.0.0-SNAPSHOT]
Test asserts fixed Log contract improved Tests reinforced
1 parent 1416a23 commit 14ccb53

File tree

7 files changed

+138
-27
lines changed

7 files changed

+138
-27
lines changed

Diff for: src/main/java/io/goodforgod/api/etherscan/model/EthSupply.java

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.util.Objects;
55

66
/**
7-
* Please Add Description Here.
8-
*
97
* @author Anton Kurako (GoodforGod)
108
* @since 14.05.2023
119
*/
@@ -100,10 +98,26 @@ public EthSupplyBuilder withWithdrawnTotal(Wei withdrawnTotal) {
10098

10199
public EthSupply build() {
102100
EthSupply ethSupply = new EthSupply();
103-
ethSupply.BurntFees = this.burntFees.toString();
104-
ethSupply.Eth2Staking = this.eth2Staking.toString();
105-
ethSupply.EthSupply = this.ethSupply.toString();
106-
ethSupply.WithdrawnTotal = this.withdrawnTotal.toString();
101+
if (this.burntFees != null) {
102+
ethSupply.BurntFees = this.burntFees.toString();
103+
} else {
104+
ethSupply.BurntFees = BigInteger.ZERO.toString();
105+
}
106+
if (this.eth2Staking != null) {
107+
ethSupply.Eth2Staking = this.eth2Staking.toString();
108+
} else {
109+
ethSupply.Eth2Staking = BigInteger.ZERO.toString();
110+
}
111+
if (this.ethSupply != null) {
112+
ethSupply.EthSupply = this.ethSupply.toString();
113+
} else {
114+
ethSupply.EthSupply = BigInteger.ZERO.toString();
115+
}
116+
if (this.withdrawnTotal != null) {
117+
ethSupply.WithdrawnTotal = this.withdrawnTotal.toString();
118+
} else {
119+
ethSupply.WithdrawnTotal = BigInteger.ZERO.toString();
120+
}
107121
return ethSupply;
108122
}
109123
}

Diff for: src/main/java/io/goodforgod/api/etherscan/model/Log.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.gson.annotations.Expose;
44
import io.goodforgod.api.etherscan.util.BasicUtils;
5-
import java.math.BigInteger;
65
import java.time.LocalDateTime;
76
import java.time.ZoneOffset;
87
import java.util.List;
@@ -28,10 +27,10 @@ public class Log {
2827
private String data;
2928
private String gasPrice;
3029
@Expose(deserialize = false, serialize = false)
31-
private BigInteger _gasPrice;
30+
private Wei _gasPrice;
3231
private String gasUsed;
3332
@Expose(deserialize = false, serialize = false)
34-
private BigInteger _gasUsed;
33+
private Wei _gasUsed;
3534
private List<String> topics;
3635
private String logIndex;
3736
@Expose(deserialize = false, serialize = false)
@@ -93,17 +92,17 @@ public String getData() {
9392
return data;
9493
}
9594

96-
public BigInteger getGasPrice() {
95+
public Wei getGasPrice() {
9796
if (!BasicUtils.isEmpty(gasPrice)) {
98-
_gasPrice = BasicUtils.parseHex(gasPrice);
97+
_gasPrice = Wei.ofWei(BasicUtils.parseHex(gasPrice));
9998
}
10099

101100
return _gasPrice;
102101
}
103102

104-
public BigInteger getGasUsed() {
103+
public Wei getGasUsed() {
105104
if (!BasicUtils.isEmpty(gasUsed)) {
106-
_gasUsed = BasicUtils.parseHex(gasUsed);
105+
_gasUsed = Wei.ofWei(BasicUtils.parseHex(gasUsed));
107106
}
108107

109108
return _gasUsed;
@@ -172,8 +171,8 @@ public static final class LogBuilder {
172171
private Long transactionIndex;
173172
private LocalDateTime timeStamp;
174173
private String data;
175-
private BigInteger gasPrice;
176-
private BigInteger gasUsed;
174+
private Wei gasPrice;
175+
private Wei gasUsed;
177176
private List<String> topics;
178177
private Long logIndex;
179178

@@ -209,12 +208,12 @@ public LogBuilder withData(String data) {
209208
return this;
210209
}
211210

212-
public LogBuilder withGasPrice(BigInteger gasPrice) {
211+
public LogBuilder withGasPrice(Wei gasPrice) {
213212
this.gasPrice = gasPrice;
214213
return this;
215214
}
216215

217-
public LogBuilder withGasUsed(BigInteger gasUsed) {
216+
public LogBuilder withGasUsed(Wei gasUsed) {
218217
this.gasUsed = gasUsed;
219218
return this;
220219
}
@@ -233,7 +232,6 @@ public Log build() {
233232
Log log = new Log();
234233
log.address = this.address;
235234
if (this.gasPrice != null) {
236-
log.gasPrice = String.valueOf(this.gasPrice);
237235
log._gasPrice = this.gasPrice;
238236
}
239237
log._logIndex = this.logIndex;
@@ -246,7 +244,6 @@ public Log build() {
246244
}
247245
log.data = this.data;
248246
if (this.gasUsed != null) {
249-
log.gasUsed = String.valueOf(this.gasUsed);
250247
log._gasUsed = this.gasUsed;
251248
}
252249
log.logIndex = String.valueOf(this.logIndex);

Diff for: src/test/java/io/goodforgod/api/etherscan/account/AccountTxErc20Tests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void assertTxs(List<TxErc20> txs) {
7171
assertNotNull(tx.getTokenDecimal());
7272
assertNotEquals(-1, (tx.getConfirmations()));
7373
assertNotNull(tx.getGasUsed());
74-
assertNotEquals(-1, tx.getGasUsedCumulative());
74+
assertNotEquals(-1, tx.getGasUsedCumulative().asWei().intValue());
7575
assertNotEquals(-1, tx.getTransactionIndex());
7676
}
7777
}

Diff for: src/test/java/io/goodforgod/api/etherscan/account/AccountTxRc1155TokenTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void correct() {
1818
assertNotNull(txs);
1919
assertFalse(txs.isEmpty());
2020
assertTxs(txs);
21-
assertNotEquals(0, txs.get(0).getGasPrice());
21+
assertNotEquals(0, txs.get(0).getGasPrice().asWei().intValue());
2222
assertNotEquals(-1, txs.get(0).getNonce());
2323

2424
assertNotNull(txs.get(0).toString());
@@ -75,7 +75,7 @@ private void asserTx(TxErc1155 tx) {
7575
assertNotNull(tx.getTokenValue());
7676
assertNotEquals(-1, (tx.getConfirmations()));
7777
assertNotNull(tx.getGasUsed());
78-
assertNotEquals(-1, tx.getGasUsedCumulative());
78+
assertNotEquals(-1, tx.getGasUsedCumulative().asWei().intValue());
7979
assertNotEquals(-1, tx.getTransactionIndex());
8080
}
8181
}

Diff for: src/test/java/io/goodforgod/api/etherscan/account/AccountTxRc721TokenTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void correct() {
1818
assertNotNull(txs);
1919
assertEquals(16, txs.size());
2020
assertTxs(txs);
21-
assertNotEquals(0, txs.get(0).getGasPrice());
21+
assertNotEquals(0, txs.get(0).getGasPrice().asWei().intValue());
2222
assertNotEquals(-1, txs.get(0).getNonce());
2323

2424
assertNotNull(txs.get(0).toString());
@@ -73,7 +73,7 @@ private void assertTxs(List<TxErc721> txs) {
7373
assertNotNull(tx.getTokenDecimal());
7474
assertNotEquals(-1, (tx.getConfirmations()));
7575
assertNotNull(tx.getGasUsed());
76-
assertNotEquals(-1, tx.getGasUsedCumulative());
76+
assertNotEquals(-1, tx.getGasUsedCumulative().asWei().intValue());
7777
assertNotEquals(-1, tx.getTransactionIndex());
7878
}
7979
}

Diff for: src/test/java/io/goodforgod/api/etherscan/model/ModelBuilderTests.java

+102-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.goodforgod.api.etherscan.model;
22

3+
import io.goodforgod.api.etherscan.model.proxy.BlockProxy;
4+
import io.goodforgod.api.etherscan.model.proxy.ReceiptProxy;
5+
import io.goodforgod.api.etherscan.model.proxy.TxProxy;
36
import java.math.BigDecimal;
47
import java.math.BigInteger;
58
import java.time.LocalDateTime;
9+
import java.util.Arrays;
610
import java.util.Collections;
711
import org.junit.jupiter.api.Assertions;
812
import org.junit.jupiter.api.Test;
@@ -84,8 +88,8 @@ void logBuilder() {
8488
.withAddress("1")
8589
.withBlockNumber(1L)
8690
.withData("1")
87-
.withGasPrice(BigInteger.ONE)
88-
.withGasUsed(BigInteger.ONE)
91+
.withGasPrice(Wei.ofWei(1))
92+
.withGasUsed(Wei.ofWei(1))
8993
.withLogIndex(1L)
9094
.withTimeStamp(timestamp)
9195
.withTransactionHash("1")
@@ -268,4 +272,100 @@ void txInternalBuilder() {
268272
assertEquals("1", value.getTo());
269273
assertEquals("1", value.getFrom());
270274
}
275+
276+
@Test
277+
void ethSupplyBuilder() {
278+
EthSupply value = EthSupply.builder()
279+
.withBurntFees(Wei.ofWei(1))
280+
.withEth2Staking(Wei.ofWei(1))
281+
.withEthSupply(Wei.ofWei(1))
282+
.withWithdrawnTotal(Wei.ofWei(1))
283+
.build();
284+
285+
assertNotNull(value);
286+
assertEquals(BigInteger.valueOf(1), value.getTotal().asWei());
287+
288+
EthSupply valueEmpty = EthSupply.builder()
289+
.build();
290+
assertNotNull(valueEmpty);
291+
assertEquals(BigInteger.ZERO, valueEmpty.getTotal().asWei());
292+
}
293+
294+
@Test
295+
void receiptProxyBuilder() {
296+
LocalDateTime timestamp = LocalDateTime.now();
297+
ReceiptProxy value = ReceiptProxy.builder()
298+
.withBlockHash("1")
299+
.withBlockNumber(1L)
300+
.withContractAddress("1")
301+
.withCumulativeGasUsed(Wei.ofWei(1))
302+
.withFrom("1")
303+
.withTo("1")
304+
.withGasUsed(Wei.ofWei(1))
305+
.withRoot("1")
306+
.withLogsBloom("1")
307+
.withTransactionHash("1")
308+
.withTransactionIndex(1L)
309+
.withLogs(Arrays.asList(Log.builder()
310+
.withTopics(Arrays.asList("1"))
311+
.withTransactionIndex(1L)
312+
.withTransactionHash("1")
313+
.withTimeStamp(timestamp)
314+
.withLogIndex(1L)
315+
.withGasUsed(Wei.ofWei(1))
316+
.withGasPrice(Wei.ofWei(1))
317+
.withData("1")
318+
.withAddress("1")
319+
.build()))
320+
.build();
321+
322+
assertNotNull(value);
323+
assertEquals(BigInteger.valueOf(1), value.getGasUsed().asWei());
324+
}
325+
326+
@Test
327+
void blockProxyBuilder() {
328+
LocalDateTime timestamp = LocalDateTime.now();
329+
BlockProxy value = BlockProxy.builder()
330+
.withGasUsed(Wei.ofWei(1))
331+
.withLogsBloom("1")
332+
.withDifficulty("1")
333+
.withExtraData("1")
334+
.withGasLimit(Wei.ofWei(1))
335+
.withHash("1")
336+
.withMiner("1")
337+
.withMixHash("1")
338+
.withNonce("1")
339+
.withNumber(1L)
340+
.withParentHash("1")
341+
.withReceiptsRoot("1")
342+
.withSha3Uncles("1")
343+
.withSize(1L)
344+
.withStateRoot("1")
345+
.withTimestamp(timestamp)
346+
.withTotalDifficulty("1")
347+
.withTransactionsRoot("1")
348+
.withUncles(Arrays.asList("1"))
349+
.withTransactions(Arrays.asList(TxProxy.builder()
350+
.withBlockHash("1")
351+
.withBlockNumber(1L)
352+
.withFrom("1")
353+
.withGas(Wei.ofWei(1))
354+
.withGasPrice(Wei.ofWei(1))
355+
.withHash("1")
356+
.withInput("1")
357+
.withNonce(1L)
358+
.withR("1")
359+
.withS("1")
360+
.withTo("1")
361+
.withTransactionIndex(1L)
362+
.withV("1")
363+
.withValue("1")
364+
.withV("1")
365+
.build()))
366+
.build();
367+
368+
assertNotNull(value);
369+
assertEquals(BigInteger.valueOf(1), value.getGasUsed().asWei());
370+
}
271371
}

Diff for: src/test/java/io/goodforgod/api/etherscan/statistic/StatisticTokenSupplyApiTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StatisticTokenSupplyApiTests extends ApiRunner {
1616
void correct() {
1717
Wei supply = getApi().stats().supply("0x57d90b64a1a57749b0f932f1a3395792e12e7055");
1818
assertNotNull(supply);
19-
assertNotEquals(BigInteger.ZERO, supply);
19+
assertNotEquals(BigInteger.ZERO, supply.asWei());
2020
}
2121

2222
@Test

0 commit comments

Comments
 (0)