diff --git a/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java b/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java index 640bcad..c780798 100644 --- a/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java +++ b/src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java @@ -143,7 +143,8 @@ public Optional txSendRaw(final String hexEncodedTx) throws ApiException final StringProxyTO response = postRequest(urlParams, "", StringProxyTO.class); if(response.getError() != null) throw new EtherScanException("Error occurred with code " + response.getError().getCode() - + " with message " + response.getError().getMessage()); + + " with message " + response.getError().getMessage() + + ", error id " + response.getId() + ", jsonRPC " + response.getJsonrpc()); return (BasicUtils.isEmpty(response.getResult())) ? Optional.empty() diff --git a/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java b/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java index 5dd4ddf..058f592 100644 --- a/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java +++ b/src/test/java/io/api/etherscan/logs/LogQueryBuilderTest.java @@ -5,6 +5,7 @@ import io.api.etherscan.model.query.LogOp; import io.api.etherscan.model.query.impl.LogQuery; import io.api.etherscan.model.query.impl.LogQueryBuilder; +import io.api.etherscan.model.query.impl.LogTopicQuadro; import org.junit.Assert; import org.junit.Test; @@ -19,8 +20,8 @@ public class LogQueryBuilderTest extends Assert { @Test public void singleCorrect() { LogQuery single = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") - .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545") - .build(); + .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545") + .build(); assertNotNull(single); assertNotNull(single.getParams()); @@ -107,7 +108,7 @@ public void tripleInCorrectTopic1() { "0x72657075746174696f6e00000000000000000000000000000000000000000000", "0x72657075746174696f6e00000000000000000000000000000000000000000000") .setOpTopic0_1(LogOp.AND) - .setOpTopic0_2(null) + .setOpTopic0_2(LogOp.AND) .setOpTopic1_2(LogOp.AND) .build(); @@ -119,10 +120,10 @@ public void tripleInCorrectTopic1() { public void tripleInCorrectTopic2() { LogQuery triple = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c", 379224, 400000) .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", - "null", + null, "0x72657075746174696f6e00000000000000000000000000000000000000000000") .setOpTopic0_1(LogOp.AND) - .setOpTopic0_2(null) + .setOpTopic0_2(LogOp.AND) .setOpTopic1_2(LogOp.AND) .build(); @@ -135,9 +136,9 @@ public void tripleInCorrectTopic3() { LogQuery triple = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c", 379224, 400000) .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "null") + null) .setOpTopic0_1(LogOp.AND) - .setOpTopic0_2(null) + .setOpTopic0_2(LogOp.AND) .setOpTopic1_2(LogOp.AND) .build(); @@ -209,11 +210,13 @@ public void tupleIncorrectTopic1() { @Test(expected = LogQueryException.class) public void quadroIncorrectOp1() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", - null, + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "0x72657075746174696f6e00000000000000000000000000000000000000000000") + "0x72657075746174696f6e00000000000000000000000000000000000000000000"); + + topicQuadro .setOpTopic0_1(null) .setOpTopic0_2(LogOp.OR) .setOpTopic0_3(LogOp.AND) @@ -221,37 +224,34 @@ public void quadroIncorrectOp1() { .setOpTopic1_3(LogOp.OR) .setOpTopic2_3(LogOp.OR) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) public void quadroIncorrectOp2() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", - null, + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "0x72657075746174696f6e00000000000000000000000000000000000000000000") - .setOpTopic0_1(LogOp.AND) + "0x72657075746174696f6e00000000000000000000000000000000000000000000"); + + topicQuadro.setOpTopic0_1(LogOp.AND) .setOpTopic0_2(null) .setOpTopic0_3(LogOp.AND) .setOpTopic1_2(LogOp.OR) .setOpTopic1_3(LogOp.OR) .setOpTopic2_3(LogOp.OR) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) public void quadroIncorrectOp3() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", - null, + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "0x72657075746174696f6e00000000000000000000000000000000000000000000") + "0x72657075746174696f6e00000000000000000000000000000000000000000000"); + + topicQuadro .setOpTopic0_1(LogOp.AND) .setOpTopic0_2(LogOp.OR) .setOpTopic0_3(null) @@ -259,9 +259,6 @@ public void quadroIncorrectOp3() { .setOpTopic1_3(LogOp.OR) .setOpTopic2_3(LogOp.OR) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) @@ -285,11 +282,13 @@ public void quadroInCorrectAgainTopic() { @Test(expected = LogQueryException.class) public void quadroInCorrectOp4() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "", - "") + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545"); + + topicQuadro .setOpTopic0_1(LogOp.AND) .setOpTopic0_2(LogOp.OR) .setOpTopic0_3(LogOp.AND) @@ -297,18 +296,17 @@ public void quadroInCorrectOp4() { .setOpTopic1_3(LogOp.OR) .setOpTopic2_3(LogOp.OR) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) public void quadroInCorrectOp5() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "", - "") + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545"); + + topicQuadro .setOpTopic0_1(LogOp.AND) .setOpTopic0_2(LogOp.OR) .setOpTopic0_3(LogOp.AND) @@ -316,18 +314,17 @@ public void quadroInCorrectOp5() { .setOpTopic1_3(null) .setOpTopic2_3(LogOp.OR) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) public void quadroInCorrectOp6() { - LogQuery quadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") + LogTopicQuadro topicQuadro = LogQueryBuilder.with("0x33990122638b9132ca29c723bdf037f1a891a70c") .topic("0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", - "", - "") + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", + "0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545"); + + topicQuadro .setOpTopic0_1(LogOp.AND) .setOpTopic0_2(LogOp.OR) .setOpTopic0_3(LogOp.AND) @@ -335,9 +332,6 @@ public void quadroInCorrectOp6() { .setOpTopic1_3(LogOp.OR) .setOpTopic2_3(null) .build(); - - assertNotNull(quadro); - assertNotNull(quadro.getParams()); } @Test(expected = LogQueryException.class) diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java index 6a87b9b..0188789 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java @@ -22,11 +22,14 @@ public class ProxyTxApiTest extends Assert { public void correctByHash() { Optional tx = api.proxy().tx("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertTrue(tx.isPresent()); - assertNotNull(tx.get().getBlockHash()); - assertNotNull(tx.get().getFrom()); - assertNotNull(tx.get().getTo()); - assertNotNull(tx.get().getHash()); - assertNotNull(tx.get().getNonce()); + + TxProxy txProxy = tx.get(); + assertNotNull(txProxy.getBlockHash()); + assertNotNull(txProxy.getBlockNumber()); + assertNotNull(txProxy.getFrom()); + assertNotNull(txProxy.getTo()); + assertNotNull(txProxy.getHash()); + assertNotNull(txProxy.getNonce()); } @Test diff --git a/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java b/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java index fd6e89b..7c9ae0d 100644 --- a/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java +++ b/src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java @@ -22,19 +22,21 @@ public class ProxyTxReceiptApiTest extends Assert { public void correct() { Optional infoProxy = api.proxy().txReceipt("0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1"); assertTrue(infoProxy.isPresent()); - assertNotNull(infoProxy.get().getBlockHash()); - assertNotNull(infoProxy.get().getRoot()); - assertNotNull(infoProxy.get().getFrom()); - assertNotNull(infoProxy.get().getTo()); - assertNotNull(infoProxy.get().getBlockNumber()); - assertNotNull(infoProxy.get().getBlockHash()); - assertNotNull(infoProxy.get().getTransactionHash()); - assertNotNull(infoProxy.get().getTransactionIndex()); - assertNotNull(infoProxy.get().getGasUsed()); - assertNotNull(infoProxy.get().getCumulativeGasUsed()); - assertNotNull(infoProxy.get().getLogs()); - assertNotNull(infoProxy.get().getLogsBloom()); - assertNull(infoProxy.get().getContractAddress()); + + ReceiptProxy receiptProxy = infoProxy.get(); + assertNotNull(receiptProxy.getBlockHash()); + assertNotNull(receiptProxy.getRoot()); + assertNotNull(receiptProxy.getFrom()); + assertNotNull(receiptProxy.getTo()); + assertNotNull(receiptProxy.getBlockNumber()); + assertNotNull(receiptProxy.getBlockHash()); + assertNotNull(receiptProxy.getTransactionHash()); + assertNotNull(receiptProxy.getTransactionIndex()); + assertNotNull(receiptProxy.getGasUsed()); + assertNotNull(receiptProxy.getCumulativeGasUsed()); + assertNotNull(receiptProxy.getLogs()); + assertNotNull(receiptProxy.getLogsBloom()); + assertNull(receiptProxy.getContractAddress()); } @Test(expected = InvalidTxHashException.class) diff --git a/src/test/java/io/api/util/UtilTests.java b/src/test/java/io/api/util/BasicUtilsTests.java similarity index 78% rename from src/test/java/io/api/util/UtilTests.java rename to src/test/java/io/api/util/BasicUtilsTests.java index 4579010..08ef0a5 100644 --- a/src/test/java/io/api/util/UtilTests.java +++ b/src/test/java/io/api/util/BasicUtilsTests.java @@ -8,6 +8,7 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -16,7 +17,7 @@ * @author GoodforGod * @since 13.11.2018 */ -public class UtilTests extends Assert { +public class BasicUtilsTests extends Assert { @Test(expected = EtherScanException.class) public void responseValidateEmpty() { @@ -31,9 +32,16 @@ public void responseValidateNullable() { } @Test - public void partitionEmpty() { + public void partitionNewArrayList() { ArrayList list = new ArrayList<>(); List> lists = BasicUtils.partition(list, 12); assertTrue(lists.isEmpty()); } + + @Test + public void partitionEmpty() { + List list = Collections.emptyList(); + List> lists = BasicUtils.partition(list, 12); + assertTrue(lists.isEmpty()); + } }