Skip to content

Commit 2d666bc

Browse files
committed
[2.0.0-SNAPSHOT]
Log simplified Tests reinforced
1 parent 3a3e409 commit 2d666bc

File tree

2 files changed

+77
-7
lines changed

2 files changed

+77
-7
lines changed

src/main/java/io/goodforgod/api/etherscan/model/Log.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,26 @@ public Long getTransactionIndex() {
6464

6565
public LocalDateTime getTimeStamp() {
6666
if (_timeStamp == null && !BasicUtils.isEmpty(timeStamp)) {
67-
long formatted = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
68-
? BasicUtils.parseHex(timeStamp).longValue()
69-
: Long.parseLong(timeStamp);
67+
long formatted = getTimeStampAsSeconds();
7068
_timeStamp = LocalDateTime.ofEpochSecond(formatted, 0, ZoneOffset.UTC);
7169
}
7270
return _timeStamp;
7371
}
7472

7573
/**
76-
* Return the "timeStamp" field of the event record as a long-int representing the milliseconds
74+
* Return the "timeStamp" field of the event record as a long-int representing the seconds
7775
* since the Unix epoch (1970-01-01 00:00:00).
7876
*
7977
* @return milliseconds between Unix epoch and `timeStamp`. If field is empty or null, returns null
8078
*/
81-
public Long getTimeStampAsMillis() {
79+
public Long getTimeStampAsSeconds() {
8280
if (BasicUtils.isEmpty(timeStamp)) {
8381
return null;
8482
}
85-
long tsSecs = (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
83+
84+
return (timeStamp.charAt(0) == '0' && timeStamp.charAt(1) == 'x')
8685
? BasicUtils.parseHex(timeStamp).longValue()
8786
: Long.parseLong(timeStamp);
88-
return tsSecs * 1000;
8987
}
9088

9189
public String getData() {

src/test/java/io/goodforgod/api/etherscan/model/ModelBuilderTests.java

+72
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,31 @@ void txBuilder() {
168168
assertTrue(value.haveError());
169169
assertEquals("1", value.getTo());
170170
assertEquals("1", value.getFrom());
171+
172+
Tx value2 = Tx.builder()
173+
.withBlockHash("1")
174+
.withBlockNumber(1L)
175+
.withConfirmations(1L)
176+
.withContractAddress("1")
177+
.withFrom("1")
178+
.withTo("1")
179+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
180+
.withGas(Wei.ofWei(BigInteger.ONE))
181+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
182+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
183+
.withHash("1")
184+
.withInput("1")
185+
.withIsError("1")
186+
.withNonce(1L)
187+
.withTimeStamp(timestamp)
188+
.withValue(BigInteger.ONE)
189+
.withTransactionIndex(1)
190+
.withTxReceiptStatus("1")
191+
.build();
192+
193+
assertEquals(value, value2);
194+
assertEquals(value.hashCode(), value2.hashCode());
195+
assertEquals(value.toString(), value2.toString());
171196
}
172197

173198
@Test
@@ -258,6 +283,32 @@ void txErc1155Builder() {
258283
assertNotNull(value);
259284
assertEquals("1", value.getTo());
260285
assertEquals("1", value.getFrom());
286+
287+
TxErc1155 value2 = TxErc1155.builder()
288+
.withBlockHash("1")
289+
.withBlockNumber(1L)
290+
.withConfirmations(1L)
291+
.withContractAddress("1")
292+
.withFrom("1")
293+
.withTo("1")
294+
.withCumulativeGasUsed(Wei.ofWei(BigInteger.ONE))
295+
.withGas(Wei.ofWei(BigInteger.ONE))
296+
.withGasPrice(Wei.ofWei(BigInteger.ONE))
297+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
298+
.withHash("1")
299+
.withInput("1")
300+
.withTokenName("1")
301+
.withTokenSymbol("1")
302+
.withTokenDecimal("1")
303+
.withTokenID("1")
304+
.withNonce(1L)
305+
.withTimeStamp(timestamp)
306+
.withTransactionIndex(1)
307+
.build();
308+
309+
assertEquals(value, value2);
310+
assertEquals(value.hashCode(), value2.hashCode());
311+
assertEquals(value.toString(), value2.toString());
261312
}
262313

263314
@Test
@@ -283,6 +334,27 @@ void txInternalBuilder() {
283334
assertNotNull(value);
284335
assertEquals("1", value.getTo());
285336
assertEquals("1", value.getFrom());
337+
338+
TxInternal value2 = TxInternal.builder()
339+
.withBlockNumber(1L)
340+
.withContractAddress("1")
341+
.withFrom("1")
342+
.withTo("1")
343+
.withValue(BigInteger.ONE)
344+
.withGas(Wei.ofWei(BigInteger.ONE))
345+
.withGasUsed(Wei.ofWei(BigInteger.ONE))
346+
.withHash("1")
347+
.withInput("1")
348+
.withTimeStamp(timestamp)
349+
.withErrCode("1")
350+
.withIsError(1)
351+
.withTraceId("1")
352+
.withType("1")
353+
.build();
354+
355+
assertEquals(value, value2);
356+
assertEquals(value.hashCode(), value2.hashCode());
357+
assertEquals(value.toString(), value2.toString());
286358
}
287359

288360
@Test

0 commit comments

Comments
 (0)