This is an automated email from the ASF dual-hosted git repository.
bibryam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 9da3f5a CAMEL-12530 Refactoring, integration tests for web3j Ethereum
client
9da3f5a is described below
commit 9da3f5af0db4bbc04c7e29beaf9e8ebb27ae894f
Author: Bilgin Ibryam <[email protected]>
AuthorDate: Sun Jun 3 23:50:48 2018 +0100
CAMEL-12530 Refactoring, integration tests for web3j Ethereum client
---
.../camel-web3j/src/main/docs/web3j-component.adoc | 4 +-
.../camel/component/web3j/Web3jConfiguration.java | 12 +-
.../camel/component/web3j/Web3jConstants.java | 12 +-
.../camel/component/web3j/Web3jConsumer.java | 79 +--
.../camel/component/web3j/Web3jProducer.java | 154 +++--
...a => Web3jConsumerBlockObservableMockTest.java} | 2 +-
...AndSubscribeToNewBlocksObservableMockTest.java} | 3 +-
...scribeToNewTransactionsObservableMockTest.java} | 2 +-
...erCatchUpToLatestBlocksObservableMockTest.java} | 3 +-
...hUpToLatestTransactionsObservableMockTest.java} | 3 +-
...b3jConsumerEthBlockHashObservableMockTest.java} | 2 +-
... => Web3jConsumerEthLogObservableMockTest.java} | 2 +-
...hPendingTransactionHashObservableMockTest.java} | 3 +-
...sumerPendingTransactionObservableMockTest.java} | 3 +-
...eb3jConsumerReplyBlocksObservableMockTest.java} | 2 +-
...nsumerReplyTransactionsObservableMockTest.java} | 4 +-
.../component/web3j/Web3jConsumerTestSupport.java | 29 -
...eb3jConsumerTransactionObservableMockTest.java} | 2 +-
...jTestSupport.java => Web3jMockTestSupport.java} | 14 +-
.../camel/component/web3j/Web3jProducerTest.java | 39 +-
.../Web3jConsumerBlockHashTest.java} | 39 +-
.../Web3jConsumerBlockTest.java} | 39 +-
.../Web3jConsumerLogTest.java} | 43 +-
.../integration/Web3jConsumerMainnetTest.java | 76 +++
.../Web3jConsumerReplayBlockTest.java} | 45 +-
.../Web3jConsumerTransactionsTest.java} | 40 +-
.../Web3jIntegrationTestSupport.java} | 57 +-
.../integration/Web3jProducerGanacheTest.java | 756 +++++++++++++++++++++
.../Web3jProducerMainnetTest.java} | 26 +-
.../springboot/Web3jComponentConfiguration.java | 12 +-
30 files changed, 1110 insertions(+), 397 deletions(-)
diff --git a/components/camel-web3j/src/main/docs/web3j-component.adoc
b/components/camel-web3j/src/main/docs/web3j-component.adoc
index 5650536..846de62 100644
--- a/components/camel-web3j/src/main/docs/web3j-component.adoc
+++ b/components/camel-web3j/src/main/docs/web3j-component.adoc
@@ -80,6 +80,7 @@ with the following path and query parameters:
| *gasPrice* (producer) | Gas price used for each paid gas. | | BigInteger
| *hashrate* (producer) | A hexadecimal string representation (32 bytes) of
the hash rate. | | String
| *headerPowHash* (producer) | The header's pow-hash (256 bits) used for
submitting a proof-of-work solution. | | String
+| *index* (producer) | The transactions/uncle index position in the block. |
| BigInteger
| *keyName* (producer) | The key name in the database. | | String
| *mixDigest* (producer) | The mix digest (256 bits) used for submitting a
proof-of-work solution. | | String
| *nonce* (producer) | The nonce found (64 bits) used for submitting a
proof-of-work solution. | | String
@@ -90,9 +91,8 @@ with the following path and query parameters:
| *signedTransactionData* (producer) | The signed transaction data for a new
message call transaction or a contract creation for signed transactions. | |
String
| *sourceCode* (producer) | The source code to compile. | | String
| *transactionHash* (producer) | The information about a transaction requested
by transaction hash. | | String
-| *transactionIndex* (producer) | The transactions index position in the
block. | | BigInteger
| *ttl* (producer) | The time to live in seconds of a whisper message. | |
BigInteger
| *value* (producer) | The value sent within a transaction. | | BigInteger
| *synchronous* (advanced) | Sets whether synchronous processing should be
strictly used, or Camel is allowed to use asynchronous processing (if
supported). | false | boolean
|===
-// endpoint options: END
\ No newline at end of file
+// endpoint options: END
diff --git
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConfiguration.java
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConfiguration.java
index 95a1cbf..a4c78ae 100644
---
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConfiguration.java
+++
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConfiguration.java
@@ -63,7 +63,7 @@ public class Web3jConfiguration implements Cloneable {
private String signedTransactionData;
@UriParam(label = "producer")
- private BigInteger transactionIndex;
+ private BigInteger index;
@UriParam(label = "producer")
private BigInteger filterId;
@@ -334,15 +334,15 @@ public class Web3jConfiguration implements Cloneable {
this.filterId = filterId;
}
- public BigInteger getTransactionIndex() {
- return transactionIndex;
+ public BigInteger getIndex() {
+ return index;
}
/**
- * The transactions index position in the block.
+ * The transactions/uncle index position in the block.
*/
- public void setTransactionIndex(BigInteger transactionIndex) {
- this.transactionIndex = transactionIndex;
+ public void setIndex(BigInteger index) {
+ this.index = index;
}
public String getSignedTransactionData() {
diff --git
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConstants.java
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConstants.java
index 53eee65..1830372 100644
---
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConstants.java
+++
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConstants.java
@@ -104,17 +104,17 @@ public interface Web3jConstants {
String POSITION = "POSITION";
String BLOCK_HASH = "BLOCK_HASH";
String TRANSACTION_HASH = "TRANSACTION_HASH";
- String SHA3_HASH_OF_DATA_TO_SIGN = "sha3HashOfDataToSign";
- String SIGNED_TRANSACTION_DATA = "signedTransactionData";
- String FULL_TRANSACTION_OBJECTS = "fullTransactionObjects";
- String TRANSACTION_INDEX = "fullTransactionObjects";
+ String SHA3_HASH_OF_DATA_TO_SIGN = "SHA3_HASH_OF_DATA_TO_SIGN";
+ String SIGNED_TRANSACTION_DATA = "SIGNED_TRANSACTION_DATA";
+ String FULL_TRANSACTION_OBJECTS = "FULL_TRANSACTION_OBJECTS";
+ String INDEX = "INDEX";
String SOURCE_CODE = "SOURCE_CODE";
String FILTER_ID = "FILTER_ID";
String DATABASE_NAME = "DATABASE_NAME";
String KEY_NAME = "KEY_NAME";
String NONCE = "NONCE";
- String HEADER_POW_HASH = "headerPowHash";
- String MIX_DIGEST = "mixDigest";
+ String HEADER_POW_HASH = "HEADER_POW_HASH";
+ String MIX_DIGEST = "MIX_DIGEST";
String CLIENT_ID = "CLIENT_ID";
String GAS_PRICE = "GAS_PRICE";
String GAS_LIMIT = "GAS_LIMIT";
diff --git
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConsumer.java
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConsumer.java
index 4c1eb13..f283151 100644
---
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConsumer.java
+++
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jConsumer.java
@@ -53,106 +53,105 @@ public class Web3jConsumer extends DefaultConsumer {
@Override
protected void doStart() throws Exception {
super.doStart();
- LOG.info("Subscribing: " + this.configuration);
+ LOG.info("Subscribing to: " + endpoint.getNodeAddress());
switch (configuration.getOperation()) {
case Web3jConstants.ETH_LOG_OBSERVABLE:
EthFilter ethFilter =
endpoint.buildEthFilter(configuration.getFromBlock(),
configuration.getToBlock(), configuration.getAddresses(),
configuration.getTopics());
subscription = web3j.ethLogObservable(ethFilter).subscribe(
x -> ethLogObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t, Web3jConstants.ETH_LOG_OBSERVABLE),
+ () -> processDone(Web3jConstants.ETH_LOG_OBSERVABLE)
);
break;
case Web3jConstants.ETH_BLOCK_HASH_OBSERVABLE:
subscription = web3j.ethBlockHashObservable().subscribe(
x -> ethBlockHashObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t, Web3jConstants.ETH_BLOCK_HASH_OBSERVABLE),
+ () -> processDone(Web3jConstants.ETH_BLOCK_HASH_OBSERVABLE)
);
break;
case Web3jConstants.ETH_PENDING_TRANSACTION_HASH_OBSERVABLE:
subscription =
web3j.ethPendingTransactionHashObservable().subscribe(
x -> ethPendingTransactionHashObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.ETH_PENDING_TRANSACTION_HASH_OBSERVABLE),
+ () ->
processDone(Web3jConstants.ETH_PENDING_TRANSACTION_HASH_OBSERVABLE)
);
break;
case Web3jConstants.TRANSACTION_OBSERVABLE:
subscription = web3j.transactionObservable().subscribe(
x -> processTransaction(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t, Web3jConstants.TRANSACTION_OBSERVABLE),
+ () -> processDone(Web3jConstants.TRANSACTION_OBSERVABLE)
);
break;
case Web3jConstants.PENDING_TRANSACTION_OBSERVABLE:
subscription = web3j.pendingTransactionObservable().subscribe(
x -> processTransaction(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.PENDING_TRANSACTION_OBSERVABLE),
+ () ->
processDone(Web3jConstants.PENDING_TRANSACTION_OBSERVABLE)
);
break;
case Web3jConstants.BLOCK_OBSERVABLE:
subscription =
web3j.blockObservable(configuration.isFullTransactionObjects()).subscribe(
x -> blockObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t, Web3jConstants.BLOCK_OBSERVABLE),
+ () -> processDone(Web3jConstants.BLOCK_OBSERVABLE)
);
break;
case Web3jConstants.REPLAY_BLOCKS_OBSERVABLE:
subscription =
web3j.replayBlocksObservable(configuration.getFromBlock(),
configuration.getToBlock(), configuration.isFullTransactionObjects()).subscribe(
x -> blockObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t, Web3jConstants.REPLAY_BLOCKS_OBSERVABLE),
+ () -> processDone(Web3jConstants.REPLAY_BLOCKS_OBSERVABLE)
);
break;
case Web3jConstants.REPLAY_TRANSACTIONS_OBSERVABLE:
subscription =
web3j.replayTransactionsObservable(configuration.getFromBlock(),
configuration.getToBlock()).subscribe(
x -> processTransaction(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.REPLAY_TRANSACTIONS_OBSERVABLE),
+ () ->
processDone(Web3jConstants.REPLAY_TRANSACTIONS_OBSERVABLE)
);
break;
case Web3jConstants.CATCH_UP_TO_LATEST_BLOCK_OBSERVABLE:
subscription =
web3j.catchUpToLatestBlockObservable(configuration.getFromBlock(),
configuration.isFullTransactionObjects()).subscribe(
x -> blockObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.CATCH_UP_TO_LATEST_BLOCK_OBSERVABLE),
+ () ->
processDone(Web3jConstants.CATCH_UP_TO_LATEST_BLOCK_OBSERVABLE)
);
break;
case Web3jConstants.CATCH_UP_TO_LATEST_TRANSACTION_OBSERVABLE:
subscription =
web3j.catchUpToLatestTransactionObservable(configuration.getFromBlock()).subscribe(
x -> processTransaction(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.CATCH_UP_TO_LATEST_TRANSACTION_OBSERVABLE),
+ () ->
processDone(Web3jConstants.CATCH_UP_TO_LATEST_TRANSACTION_OBSERVABLE)
);
break;
case
Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_BLOCKS_OBSERVABLE:
subscription =
web3j.catchUpToLatestAndSubscribeToNewBlocksObservable(configuration.getFromBlock(),
configuration.isFullTransactionObjects()).subscribe(
x -> blockObservable(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_BLOCKS_OBSERVABLE),
+ () ->
processDone(Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_BLOCKS_OBSERVABLE)
);
break;
case
Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_TRANSACTIONS_OBSERVABLE:
subscription =
web3j.catchUpToLatestAndSubscribeToNewTransactionsObservable(configuration.getFromBlock()).subscribe(
x -> processTransaction(x),
- t -> processError(t),
- () -> processDone()
+ t -> processError(t,
Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_TRANSACTIONS_OBSERVABLE),
+ () ->
processDone(Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_TRANSACTIONS_OBSERVABLE)
);
break;
-
default:
throw new IllegalArgumentException("Unsupported operation " +
configuration.getOperation());
}
@@ -174,13 +173,6 @@ public class Web3jConsumer extends DefaultConsumer {
return ethFilter;
}
- private void ethLogObservable(Log x) {
- LOG.debug("processLogObservable " + x);
- Exchange exchange = this.getEndpoint().createExchange();
- exchange.getIn().setBody(x);
- processEvent(exchange);
- }
-
private void ethBlockHashObservable(String x) {
LOG.debug("processEthBlock " + x);
Exchange exchange = this.getEndpoint().createExchange();
@@ -196,9 +188,10 @@ public class Web3jConsumer extends DefaultConsumer {
}
private void blockObservable(EthBlock x) {
- LOG.debug("processEthBlock " + x);
+ EthBlock.Block block = x.getBlock();
+ LOG.debug("processEthBlock " + block);
Exchange exchange = this.getEndpoint().createExchange();
- exchange.getIn().setBody(x);
+ exchange.getIn().setBody(block);
processEvent(exchange);
}
@@ -209,6 +202,13 @@ public class Web3jConsumer extends DefaultConsumer {
processEvent(exchange);
}
+ private void ethLogObservable(Log x) {
+ LOG.debug("processLogObservable " + x);
+ Exchange exchange = this.getEndpoint().createExchange();
+ exchange.getIn().setBody(x);
+ processEvent(exchange);
+ }
+
public void processEvent(Exchange exchange) {
LOG.debug("processEvent " + exchange);
try {
@@ -218,15 +218,16 @@ public class Web3jConsumer extends DefaultConsumer {
}
}
- private void processDone() {
- LOG.debug("processDone ");
+ private void processDone(String operation) {
+ LOG.debug("processDone for operation: " + operation);
Exchange exchange = this.getEndpoint().createExchange();
exchange.getIn().setHeader("status", "done");
+ exchange.getIn().setHeader("operation", operation);
processEvent(exchange);
}
- private void processError(Throwable throwable) {
- LOG.debug("processError " + throwable);
+ private void processError(Throwable throwable, String operation) {
+ LOG.debug("processError for operation: " + operation + " " +
throwable);
Exchange exchange = this.getEndpoint().createExchange();
exchange.setException(throwable);
processEvent(exchange);
diff --git
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jProducer.java
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jProducer.java
index 7e5a7c5..6312394 100644
---
a/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jProducer.java
+++
b/components/camel-web3j/src/main/java/org/apache/camel/component/web3j/Web3jProducer.java
@@ -30,7 +30,6 @@ import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;
-import org.web3j.protocol.core.methods.request.ShhFilter;
import org.web3j.protocol.core.methods.response.DbGetHex;
import org.web3j.protocol.core.methods.response.DbGetString;
@@ -81,7 +80,6 @@ import
org.web3j.protocol.core.methods.response.ShhNewIdentity;
import org.web3j.protocol.core.methods.response.ShhPost;
import org.web3j.protocol.core.methods.response.ShhUninstallFilter;
import org.web3j.protocol.core.methods.response.ShhVersion;
-import org.web3j.protocol.core.methods.response.Transaction;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;
import org.web3j.protocol.core.methods.response.Web3Sha3;
@@ -150,7 +148,6 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
- //new
@InvokeOnHeader(Web3jConstants.NET_LISTENING)
void netListening(Message message) throws IOException {
Request<?, NetListening> netListeningRequest = web3j.netListening();
@@ -158,7 +155,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
NetListening response = netListeningRequest.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getResult());
+ message.setBody(response.isListening());
}
}
@@ -169,7 +166,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
NetPeerCount response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getResult());
+ message.setBody(response.getQuantity());
}
}
@@ -180,29 +177,29 @@ public class Web3jProducer extends HeaderSelectorProducer
{
EthProtocolVersion response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getResult());
+ message.setBody(response.getProtocolVersion());
}
}
- @InvokeOnHeader(Web3jConstants.ETH_COINBASE)
- void ethCoinbase(Message message) throws IOException {
- Request<?, EthCoinbase> request = web3j.ethCoinbase();
+ @InvokeOnHeader(Web3jConstants.ETH_SYNCING)
+ void ethSyncing(Message message) throws IOException {
+ Request<?, EthSyncing> request = web3j.ethSyncing();
setRequestId(message, request);
- EthCoinbase response = request.send();
+ EthSyncing response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getResult());
+ message.setBody(response.isSyncing());
}
}
- @InvokeOnHeader(Web3jConstants.ETH_SYNCING)
- void ethSyncing(Message message) throws IOException {
- Request<?, EthSyncing> request = web3j.ethSyncing();
+ @InvokeOnHeader(Web3jConstants.ETH_COINBASE)
+ void ethCoinbase(Message message) throws IOException {
+ Request<?, EthCoinbase> request = web3j.ethCoinbase();
setRequestId(message, request);
- EthSyncing response = request.send();
+ EthCoinbase response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.isSyncing());
+ message.setBody(response.getAddress());
}
}
@@ -247,7 +244,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
message.setBody(response.getAccounts());
boolean hasError = checkForError(message, response);
if (!hasError) {
-
+ message.setBody(response.getAccounts());
}
}
@@ -264,9 +261,10 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_BALANCE)
void ethGetBalance(Message message) throws IOException {
- String atBlock = message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, String.class);
String address = message.getHeader(Web3jConstants.ADDRESS,
configuration::getAddress, String.class);
- Request<?, EthGetBalance> request = web3j.ethGetBalance(address,
DefaultBlockParameter.valueOf(atBlock));
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
+
+ Request<?, EthGetBalance> request = web3j.ethGetBalance(address,
atBlock);
setRequestId(message, request);
EthGetBalance response = request.send();
boolean hasError = checkForError(message, response);
@@ -278,7 +276,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_STORAGE_AT)
void ethGetStorageAt(Message message) throws IOException {
String address = message.getHeader(Web3jConstants.ADDRESS,
configuration::getAddress, String.class);
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
BigInteger position = message.getHeader(Web3jConstants.POSITION,
configuration::getPosition, BigInteger.class);
Request<?, EthGetStorageAt> request = web3j.ethGetStorageAt(address,
position, atBlock);
setRequestId(message, request);
@@ -292,7 +290,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_COUNT)
void ethGetTransactionCount(Message message) throws IOException {
String address = message.getHeader(Web3jConstants.ADDRESS,
configuration::getAddress, String.class);
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
Request<?, EthGetTransactionCount> request =
web3j.ethGetTransactionCount(address, atBlock);
setRequestId(message, request);
EthGetTransactionCount response = request.send();
@@ -316,7 +314,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER)
void ethGetBlockTransactionCountByNumber(Message message) throws
IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
Request<?, EthGetBlockTransactionCountByNumber> request =
web3j.ethGetBlockTransactionCountByNumber(atBlock);
setRequestId(message, request);
EthGetBlockTransactionCountByNumber response = request.send();
@@ -340,7 +338,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_UNCLE_COUNT_BY_BLOCK_NUMBER)
void ethGetUncleCountByBlockNumber(Message message) throws IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
Request<?, EthGetUncleCountByBlockNumber> request =
web3j.ethGetUncleCountByBlockNumber(atBlock);
setRequestId(message, request);
EthGetUncleCountByBlockNumber response = request.send();
@@ -352,7 +350,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_CODE)
void ethGetCode(Message message) throws IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
String address = message.getHeader(Web3jConstants.ADDRESS,
configuration::getAddress, String.class);
Request<?, EthGetCode> request = web3j.ethGetCode(address, atBlock);
setRequestId(message, request);
@@ -414,11 +412,15 @@ public class Web3jProducer extends HeaderSelectorProducer
{
void ethCall(Message message) throws IOException {
String fromAddress = message.getHeader(Web3jConstants.FROM_ADDRESS,
configuration::getFromAddress, String.class);
String toAddress = message.getHeader(Web3jConstants.TO_ADDRESS,
configuration::getToAddress, String.class);
+ BigInteger nonce = message.getHeader(Web3jConstants.NONCE,
configuration::getNonce, BigInteger.class);
+ BigInteger gasPrice = message.getHeader(Web3jConstants.GAS_PRICE,
configuration::getGasPrice, BigInteger.class);
+ BigInteger gasLimit = message.getHeader(Web3jConstants.GAS_LIMIT,
configuration::getGasLimit, BigInteger.class);
+ BigInteger value = message.getHeader(Web3jConstants.VALUE,
configuration::getValue, BigInteger.class);
String data = message.getHeader(Web3jConstants.DATA,
configuration::getData, String.class);
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
org.web3j.protocol.core.methods.request.Transaction transaction = new
org.web3j.protocol.core.methods.request.Transaction(
- fromAddress, null, null, null, toAddress, null, data);
+ fromAddress, nonce, gasPrice, gasLimit, toAddress, value,
data);
Request<?, EthCall> request = web3j.ethCall(transaction, atBlock);
setRequestId(message, request);
@@ -462,7 +464,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_BLOCK_BY_NUMBER)
void ethGetBlockByNumber(Message message) throws IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
Boolean fullTransactionObjects =
message.getHeader(Web3jConstants.FULL_TRANSACTION_OBJECTS,
configuration::isFullTransactionObjects, Boolean.class);
Request<?, EthBlock> request = web3j.ethGetBlockByNumber(atBlock,
fullTransactionObjects);
setRequestId(message, request);
@@ -481,53 +483,41 @@ public class Web3jProducer extends HeaderSelectorProducer
{
EthTransaction response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getTransaction());
+ message.setBody(response.getTransaction().isPresent() ?
response.getTransaction().get() : null);
}
}
@InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX)
void ethGetTransactionByBlockHashAndIndex(Message message) throws
IOException {
String blockHash = message.getHeader(Web3jConstants.BLOCK_HASH,
configuration::getBlockHash, String.class);
- BigInteger transactionIndex =
message.getHeader(Web3jConstants.TRANSACTION_INDEX,
configuration::getTransactionIndex, BigInteger.class);
+ BigInteger transactionIndex = message.getHeader(Web3jConstants.INDEX,
configuration::getIndex, BigInteger.class);
Request<?, EthTransaction> request =
web3j.ethGetTransactionByBlockHashAndIndex(blockHash, transactionIndex);
setRequestId(message, request);
EthTransaction response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getTransaction());
+ message.setBody(response.getTransaction().isPresent() ?
response.getTransaction().get() : null);
}
}
@InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX)
void ethGetTransactionByBlockNumberAndIndex(Message message) throws
IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
- BigInteger transactionIndex =
message.getHeader(Web3jConstants.TRANSACTION_INDEX,
configuration::getTransactionIndex, BigInteger.class);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
+ BigInteger transactionIndex = message.getHeader(Web3jConstants.INDEX,
configuration::getIndex, BigInteger.class);
Request<?, EthTransaction> request =
web3j.ethGetTransactionByBlockNumberAndIndex(atBlock, transactionIndex);
setRequestId(message, request);
EthTransaction response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getTransaction());
- }
- }
-
- @InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_RECEIPT)
- void ethGetTransactionReceipt(Message message) throws IOException {
- String transactionHash =
message.getHeader(Web3jConstants.TRANSACTION_HASH,
configuration::getTransactionHash, String.class);
- Request<?, EthGetTransactionReceipt> request =
web3j.ethGetTransactionReceipt(transactionHash);
- setRequestId(message, request);
- EthGetTransactionReceipt response = request.send();
- boolean hasError = checkForError(message, response);
- if (!hasError) {
- message.setBody(response.getTransactionReceipt());
+ message.setBody(response.getTransaction().isPresent() ?
response.getTransaction().get() : null);
}
}
@InvokeOnHeader(Web3jConstants.ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX)
void ethGetUncleByBlockHashAndIndex(Message message) throws IOException {
String blockHash = message.getHeader(Web3jConstants.BLOCK_HASH,
configuration::getBlockHash, String.class);
- BigInteger transactionIndex =
message.getHeader(Web3jConstants.TRANSACTION_INDEX,
configuration::getTransactionIndex, BigInteger.class);
- Request<?, EthBlock> request =
web3j.ethGetUncleByBlockHashAndIndex(blockHash, transactionIndex);
+ BigInteger uncleIndex = message.getHeader(Web3jConstants.INDEX,
configuration::getIndex, BigInteger.class);
+ Request<?, EthBlock> request =
web3j.ethGetUncleByBlockHashAndIndex(blockHash, uncleIndex);
setRequestId(message, request);
EthBlock response = request.send();
boolean hasError = checkForError(message, response);
@@ -538,9 +528,9 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX)
void ethGetUncleByBlockNumberAndIndex(Message message) throws IOException {
- DefaultBlockParameter atBlock =
message.getHeader(Web3jConstants.AT_BLOCK, configuration::getAtBlock,
DefaultBlockParameter.class);
- BigInteger transactionIndex =
message.getHeader(Web3jConstants.TRANSACTION_INDEX,
configuration::getTransactionIndex, BigInteger.class);
- Request<?, EthBlock> request =
web3j.ethGetUncleByBlockNumberAndIndex(atBlock, transactionIndex);
+ DefaultBlockParameter atBlock =
toBlockParameter(message.getHeader(Web3jConstants.AT_BLOCK,
configuration::getAtBlock, Object.class));
+ BigInteger uncleIndex = message.getHeader(Web3jConstants.INDEX,
configuration::getIndex, BigInteger.class);
+ Request<?, EthBlock> request =
web3j.ethGetUncleByBlockNumberAndIndex(atBlock, uncleIndex);
setRequestId(message, request);
EthBlock response = request.send();
boolean hasError = checkForError(message, response);
@@ -549,6 +539,18 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
+ @InvokeOnHeader(Web3jConstants.ETH_GET_TRANSACTION_RECEIPT)
+ void ethGetTransactionReceipt(Message message) throws IOException {
+ String transactionHash =
message.getHeader(Web3jConstants.TRANSACTION_HASH,
configuration::getTransactionHash, String.class);
+ Request<?, EthGetTransactionReceipt> request =
web3j.ethGetTransactionReceipt(transactionHash);
+ setRequestId(message, request);
+ EthGetTransactionReceipt response = request.send();
+ boolean hasError = checkForError(message, response);
+ if (!hasError) {
+ message.setBody(response.getTransactionReceipt());
+ }
+ }
+
@InvokeOnHeader(Web3jConstants.ETH_GET_COMPILERS)
void ethGetCompilers(Message message) throws IOException {
Request<?, EthGetCompilers> request = web3j.ethGetCompilers();
@@ -598,10 +600,11 @@ public class Web3jProducer extends HeaderSelectorProducer
{
@InvokeOnHeader(Web3jConstants.ETH_NEW_FILTER)
void ethNewFilter(Message message) throws IOException {
- DefaultBlockParameter fromBlock =
message.getHeader(Web3jConstants.FROM_BLOCK, configuration::getFromBlock,
DefaultBlockParameter.class);
- DefaultBlockParameter toBlock =
message.getHeader(Web3jConstants.TO_BLOCK, configuration::getToBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter fromBlock =
toBlockParameter(message.getHeader(Web3jConstants.FROM_BLOCK,
configuration::getFromBlock, Object.class));
+ DefaultBlockParameter toBlock =
toBlockParameter(message.getHeader(Web3jConstants.TO_BLOCK,
configuration::getToBlock, Object.class));
List<String> addresses = message.getHeader(Web3jConstants.ADDRESSES,
configuration::getAddresses, List.class);
List<String> topics = message.getHeader(Web3jConstants.TOPICS,
configuration::getTopics, List.class);
+
org.web3j.protocol.core.methods.request.EthFilter ethFilter =
endpoint.buildEthFilter(fromBlock, toBlock, addresses, topics);
Request<?, EthFilter> request = web3j.ethNewFilter(ethFilter);
@@ -673,8 +676,8 @@ public class Web3jProducer extends HeaderSelectorProducer {
@InvokeOnHeader(Web3jConstants.ETH_GET_LOGS)
void ethGetLogs(Message message) throws IOException {
- DefaultBlockParameter fromBlock =
message.getHeader(Web3jConstants.FROM_BLOCK, configuration::getFromBlock,
DefaultBlockParameter.class);
- DefaultBlockParameter toBlock =
message.getHeader(Web3jConstants.TO_BLOCK, configuration::getToBlock,
DefaultBlockParameter.class);
+ DefaultBlockParameter fromBlock =
toBlockParameter(message.getHeader(Web3jConstants.FROM_BLOCK,
configuration::getFromBlock, Object.class));
+ DefaultBlockParameter toBlock =
toBlockParameter(message.getHeader(Web3jConstants.TO_BLOCK,
configuration::getToBlock, Object.class));
List<String> addresses = message.getHeader(Web3jConstants.ADDRESSES,
configuration::getAddresses, List.class);
List<String> topics = message.getHeader(Web3jConstants.TOPICS,
configuration::getTopics, List.class);
org.web3j.protocol.core.methods.request.EthFilter ethFilter =
endpoint.buildEthFilter(fromBlock, toBlock, addresses, topics);
@@ -695,7 +698,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
EthGetWork response = request.send();
boolean hasError = checkForError(message, response);
if (!hasError) {
- message.setBody(response.getBoundaryCondition());
+ message.setBody(response.getResult());
}
}
@@ -726,6 +729,7 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
+ //deprecated operations
@InvokeOnHeader(Web3jConstants.DB_PUT_STRING)
void dbPutString(Message message) throws IOException {
String databaseName = message.getHeader(Web3jConstants.DATABASE_NAME,
configuration::getDatabaseName, String.class);
@@ -778,6 +782,17 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
+ @InvokeOnHeader(Web3jConstants.SHH_VERSION)
+ void shhVersion(Message message) throws IOException {
+ Request<?, ShhVersion> request = web3j.shhVersion();
+ setRequestId(message, request);
+ ShhVersion response = request.send();
+ boolean hasError = checkForError(message, response);
+ if (!hasError) {
+ message.setBody(response.getVersion());
+ }
+ }
+
@InvokeOnHeader(Web3jConstants.SHH_POST)
void shhPost(Message message) throws IOException {
String fromAddress = message.getHeader(Web3jConstants.FROM_ADDRESS,
configuration::getFromAddress, String.class);
@@ -797,17 +812,6 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
- @InvokeOnHeader(Web3jConstants.SHH_VERSION)
- void shhVersion(Message message) throws IOException {
- Request<?, ShhVersion> request = web3j.shhVersion();
- setRequestId(message, request);
- ShhVersion response = request.send();
- boolean hasError = checkForError(message, response);
- if (!hasError) {
- message.setBody(response.getVersion());
- }
- }
-
@InvokeOnHeader(Web3jConstants.SHH_NEW_IDENTITY)
void shhNewIdentity(Message message) throws IOException {
Request<?, ShhNewIdentity> request = web3j.shhNewIdentity();
@@ -913,6 +917,24 @@ public class Web3jProducer extends HeaderSelectorProducer {
}
}
+ private DefaultBlockParameter toBlockParameter(Object o) {
+ DefaultBlockParameter defaultBlockParameter = null;
+ if (o != null) {
+ try {
+ defaultBlockParameter =
DefaultBlockParameter.valueOf(o.toString());
+ } catch (Throwable e) {
+ //not one of: "latest", "earliest" or "pending"
+ }
+
+ if (defaultBlockParameter == null) {
+ defaultBlockParameter = DefaultBlockParameter.valueOf(new
BigInteger(o.toString()));
+ }
+ }
+
+ return defaultBlockParameter;
+ }
+
+
private boolean checkForError(Message message, Response response) {
if (response.hasError()) {
int code = response.getError().getCode();
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableMockTest.java
similarity index 98%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableMockTest.java
index fc80bfc..6d987da 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerBlockObservableMockTest.java
@@ -32,7 +32,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.BLOCK_OBSERVABLE;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerBlockObservableTest extends Web3jTestSupport {
+public class Web3jConsumerBlockObservableMockTest extends Web3jMockTestSupport
{
@Mock
private Observable<EthBlock> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableMockTest.java
similarity index 96%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableMockTest.java
index c8848dc..a25891a 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableMockTest.java
@@ -30,11 +30,10 @@ import rx.functions.Action0;
import rx.functions.Action1;
import static
org.apache.camel.component.web3j.Web3jConstants.CATCH_UP_TO_LATEST_AND_SUBSCRIBE_TO_NEW_BLOCKS_OBSERVABLE;
-import static
org.apache.camel.component.web3j.Web3jConstants.CATCH_UP_TO_LATEST_BLOCK_OBSERVABLE;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableTest
extends Web3jTestSupport {
+public class
Web3jConsumerCatchUpToLatestAndSubscribeToNewBlocksObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<EthBlock> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableMockTest.java
similarity index 98%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableMockTest.java
index e66e1ae..d4a1f3b 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableMockTest.java
@@ -33,7 +33,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.CATCH_UP_TO_LATEST
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class
Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableTest extends
Web3jTestSupport {
+public class
Web3jConsumerCatchUpToLatestAndSubscribeToNewTransactionsObservableMockTest
extends Web3jMockTestSupport {
@Mock
private Observable<Transaction> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableMockTest.java
similarity index 96%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableMockTest.java
index 858539f..e71a0cf 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestBlocksObservableMockTest.java
@@ -31,10 +31,9 @@ import rx.functions.Action1;
import static
org.apache.camel.component.web3j.Web3jConstants.CATCH_UP_TO_LATEST_BLOCK_OBSERVABLE;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_BLOCKS_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerCatchUpToLatestBlocksObservableTest extends
Web3jTestSupport {
+public class Web3jConsumerCatchUpToLatestBlocksObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<EthBlock> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableMockTest.java
similarity index 95%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableMockTest.java
index 444d3d9..8d889c3 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerCatchUpToLatestTransactionsObservableMockTest.java
@@ -31,10 +31,9 @@ import rx.functions.Action1;
import static
org.apache.camel.component.web3j.Web3jConstants.CATCH_UP_TO_LATEST_TRANSACTION_OBSERVABLE;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_TRANSACTIONS_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerCatchUpToLatestTransactionsObservableTest extends
Web3jTestSupport {
+public class Web3jConsumerCatchUpToLatestTransactionsObservableMockTest
extends Web3jMockTestSupport {
@Mock
private Observable<Transaction> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableMockTest.java
similarity index 97%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableMockTest.java
index 877eac3..f6ea886 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthBlockHashObservableMockTest.java
@@ -31,7 +31,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.ETH_BLOCK_HASH_OBS
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerEthBlockHashObservableTest extends Web3jTestSupport {
+public class Web3jConsumerEthBlockHashObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<String> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableMockTest.java
similarity index 98%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableMockTest.java
index ae38b8c..4c39de4 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthLogObservableMockTest.java
@@ -33,7 +33,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.ETH_LOG_OBSERVABLE
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerEthLogObservableTest extends Web3jTestSupport {
+public class Web3jConsumerEthLogObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<Log> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableMockTest.java
similarity index 95%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableMockTest.java
index 8fb2552..cd8ae6a 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerEthPendingTransactionHashObservableMockTest.java
@@ -27,12 +27,11 @@ import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
-import static
org.apache.camel.component.web3j.Web3jConstants.ETH_BLOCK_HASH_OBSERVABLE;
import static
org.apache.camel.component.web3j.Web3jConstants.ETH_PENDING_TRANSACTION_HASH_OBSERVABLE;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerEthPendingTransactionHashObservableTest extends
Web3jTestSupport {
+public class Web3jConsumerEthPendingTransactionHashObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<String> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableMockTest.java
similarity index 95%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableMockTest.java
index 9dbb6cc..605e2ac 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerPendingTransactionObservableMockTest.java
@@ -30,10 +30,9 @@ import rx.functions.Action1;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static
org.apache.camel.component.web3j.Web3jConstants.PENDING_TRANSACTION_OBSERVABLE;
-import static
org.apache.camel.component.web3j.Web3jConstants.TRANSACTION_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerPendingTransactionObservableTest extends
Web3jTestSupport {
+public class Web3jConsumerPendingTransactionObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<Transaction> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableMockTest.java
similarity index 98%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableMockTest.java
index 7f381c1..5894a32 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyBlocksObservableMockTest.java
@@ -33,7 +33,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_BLOCKS_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerReplyBlocksObservableTest extends Web3jTestSupport {
+public class Web3jConsumerReplyBlocksObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<EthBlock> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableMockTest.java
similarity index 94%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableMockTest.java
index 153592c..e597e61 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerReplyTransactionsObservableMockTest.java
@@ -23,7 +23,6 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.web3j.protocol.core.DefaultBlockParameter;
-import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.Transaction;
import rx.Observable;
import rx.Subscription;
@@ -31,11 +30,10 @@ import rx.functions.Action0;
import rx.functions.Action1;
import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_BLOCKS_OBSERVABLE;
import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_TRANSACTIONS_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerReplyTransactionsObservableTest extends
Web3jTestSupport {
+public class Web3jConsumerReplyTransactionsObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<Transaction> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTestSupport.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTestSupport.java
deleted file mode 100644
index 01f9f54..0000000
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTestSupport.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.web3j;
-
-import org.apache.camel.EndpointInject;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.JndiRegistry;
-import org.mockito.Mock;
-import org.web3j.protocol.Web3j;
-import rx.Subscription;
-
-public class Web3jConsumerTestSupport extends Web3jTestSupport {
-
-
-}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableMockTest.java
similarity index 97%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableMockTest.java
index 64ddcae..4ab4c31 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerTransactionObservableMockTest.java
@@ -32,7 +32,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static
org.apache.camel.component.web3j.Web3jConstants.TRANSACTION_OBSERVABLE;
import static org.mockito.ArgumentMatchers.any;
-public class Web3jConsumerTransactionObservableTest extends Web3jTestSupport {
+public class Web3jConsumerTransactionObservableMockTest extends
Web3jMockTestSupport {
@Mock
private Observable<Transaction> observable;
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jMockTestSupport.java
similarity index 84%
copy from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
copy to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jMockTestSupport.java
index 00b4f95..688dfea 100755
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jMockTestSupport.java
@@ -31,7 +31,7 @@ import org.mockito.MockitoAnnotations;
import org.web3j.protocol.Web3j;
import rx.Subscription;
-public class Web3jTestSupport extends CamelTestSupport {
+public class Web3jMockTestSupport extends CamelTestSupport {
@EndpointInject(uri = "mock:result")
protected MockEndpoint mockResult;
@@ -45,14 +45,6 @@ public class Web3jTestSupport extends CamelTestSupport {
@Mock
protected Subscription subscription;
-
- public Web3jTestSupport() {
- System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
-
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
-
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire",
"DEBUG");
- }
-
-
@Override
public boolean isUseAdviceWith() {
return true;
@@ -69,10 +61,6 @@ public class Web3jTestSupport extends CamelTestSupport {
return "web3j://http://127.0.0.1:8545?web3j=#mockWeb3j&";
}
-// protected String getUrl() {
-// return "web3j://http://127.0.0.1:8545?";
-// }
-
protected Exchange createExchangeWithBodyAndHeader(Object body, String
key, Object value) {
DefaultExchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(body);
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerTest.java
index dfa8fd1..e86fe66 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerTest.java
@@ -90,7 +90,7 @@ import static
org.apache.camel.component.web3j.Web3jConstants.OPERATION;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
-public class Web3jProducerTest extends Web3jTestSupport {
+public class Web3jProducerTest extends Web3jMockTestSupport {
@Produce(uri = "direct:start")
protected ProducerTemplate template;
@@ -148,7 +148,7 @@ public class Web3jProducerTest extends Web3jTestSupport {
NetListening response = Mockito.mock(NetListening.class);
Mockito.when(mockWeb3j.netListening()).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
- Mockito.when(response.getResult()).thenReturn(true);
+ Mockito.when(response.isListening()).thenReturn(true);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.NET_LISTENING);
template.send(exchange);
@@ -158,15 +158,16 @@ public class Web3jProducerTest extends Web3jTestSupport {
@Test
public void netPeerCountTest() throws Exception {
+ BigInteger peerCount = BigInteger.valueOf(1L);
NetPeerCount response = Mockito.mock(NetPeerCount.class);
Mockito.when(mockWeb3j.netPeerCount()).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
- Mockito.when(response.getResult()).thenReturn("123");
+ Mockito.when(response.getQuantity()).thenReturn(peerCount);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.NET_PEER_COUNT);
template.send(exchange);
- String body = exchange.getIn().getBody(String.class);
- assertTrue(body.equals("123"));
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body.equals(peerCount));
}
@Test
@@ -174,7 +175,7 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthProtocolVersion response = Mockito.mock(EthProtocolVersion.class);
Mockito.when(mockWeb3j.ethProtocolVersion()).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
- Mockito.when(response.getResult()).thenReturn("123");
+ Mockito.when(response.getProtocolVersion()).thenReturn("123");
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_PROTOCOL_VERSION);
template.send(exchange);
@@ -187,7 +188,7 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthCoinbase response = Mockito.mock(EthCoinbase.class);
Mockito.when(mockWeb3j.ethCoinbase()).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
- Mockito.when(response.getResult()).thenReturn("123");
+ Mockito.when(response.getAddress()).thenReturn("123");
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_COINBASE);
template.send(exchange);
@@ -478,11 +479,13 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthTransaction response = Mockito.mock(EthTransaction.class);
Mockito.when(mockWeb3j.ethGetTransactionByHash(any())).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
-
Mockito.when(response.getTransaction()).thenReturn(Mockito.mock(Optional.class));
+ Transaction transaction = Mockito.mock(Transaction.class);
+ Optional<Transaction> optional = Optional.ofNullable(transaction);
+ Mockito.when(response.getTransaction()).thenReturn(optional);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_GET_TRANSACTION_BY_HASH);
template.send(exchange);
- Optional<Transaction> body = exchange.getIn().getBody(Optional.class);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
assertTrue(body != null);
}
@@ -491,11 +494,13 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthTransaction response = Mockito.mock(EthTransaction.class);
Mockito.when(mockWeb3j.ethGetTransactionByBlockHashAndIndex(any(),
any())).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
-
Mockito.when(response.getTransaction()).thenReturn(Mockito.mock(Optional.class));
+ Transaction transaction = Mockito.mock(Transaction.class);
+ Optional<Transaction> optional = Optional.ofNullable(transaction);
+ Mockito.when(response.getTransaction()).thenReturn(optional);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX);
template.send(exchange);
- Optional<Transaction> body = exchange.getIn().getBody(Optional.class);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
assertTrue(body != null);
}
@@ -504,11 +509,13 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthTransaction response = Mockito.mock(EthTransaction.class);
Mockito.when(mockWeb3j.ethGetTransactionByBlockNumberAndIndex(any(),
any())).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
-
Mockito.when(response.getTransaction()).thenReturn(Mockito.mock(Optional.class));
+ Transaction transaction = Mockito.mock(Transaction.class);
+ Optional<Transaction> optional = Optional.ofNullable(transaction);
+ Mockito.when(response.getTransaction()).thenReturn(optional);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX);
template.send(exchange);
- Optional<Transaction> body = exchange.getIn().getBody(Optional.class);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
assertTrue(body != null);
}
@@ -686,12 +693,12 @@ public class Web3jProducerTest extends Web3jTestSupport {
EthGetWork response = Mockito.mock(EthGetWork.class);
Mockito.when(mockWeb3j.ethGetWork()).thenReturn(request);
Mockito.when(request.send()).thenReturn(response);
- Mockito.when(response.getBoundaryCondition()).thenReturn("test");
+ Mockito.when(response.getResult()).thenReturn(Collections.EMPTY_LIST);
Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
Web3jConstants.ETH_GET_WORK);
template.send(exchange);
- String body = exchange.getIn().getBody(String.class);
- assertTrue(body.equals("test"));
+ List body = exchange.getIn().getBody(List.class);
+ assertTrue(body.equals(Collections.EMPTY_LIST));
}
@Test
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockHashTest.java
similarity index 52%
copy from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
copy to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockHashTest.java
index e30cd64..a9aff9c 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockHashTest.java
@@ -14,50 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
-import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_BLOCK_HASH_OBSERVABLE;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jConsumerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires Ganache instance with few transactions")
+public class Web3jConsumerBlockHashTest extends Web3jIntegrationTestSupport {
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Override
- protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
- }
-
- @Test(timeout = 600000L)
- public void consumerTest() throws InterruptedException {
- mockResult.setResultWaitTime(600000L);
+ @Test
+ public void consumerTest() throws Exception {
mockResult.expectedMinimumMessageCount(1);
- mockResult.assertIsSatisfied();
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
- .to("mock:result");
+ errorHandler(deadLetterChannel("mock:error"));
- from(getUrl() + OPERATION.toLowerCase() + "=" +
ETH_LOG_OBSERVABLE)
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" +
ETH_BLOCK_HASH_OBSERVABLE)
.to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
PENDING_TRANSACTION_OBSERVABLE)
- .to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
BLOCK_OBSERVABLE)
- .to("mock:result");
-
}
};
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockTest.java
similarity index 52%
copy from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
copy to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockTest.java
index e30cd64..5672835 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerBlockTest.java
@@ -14,50 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
-import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static org.apache.camel.component.web3j.Web3jConstants.BLOCK_OBSERVABLE;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jConsumerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires Ganache instance with few transactions")
+public class Web3jConsumerBlockTest extends Web3jIntegrationTestSupport {
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Override
- protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
- }
-
- @Test(timeout = 600000L)
- public void consumerTest() throws InterruptedException {
- mockResult.setResultWaitTime(600000L);
+ @Test
+ public void consumerTest() throws Exception {
mockResult.expectedMinimumMessageCount(1);
- mockResult.assertIsSatisfied();
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
- .to("mock:result");
+ errorHandler(deadLetterChannel("mock:error"));
- from(getUrl() + OPERATION.toLowerCase() + "=" +
ETH_LOG_OBSERVABLE)
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" + BLOCK_OBSERVABLE)
.to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
PENDING_TRANSACTION_OBSERVABLE)
- .to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
BLOCK_OBSERVABLE)
- .to("mock:result");
-
}
};
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerLogTest.java
similarity index 52%
copy from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
copy to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerLogTest.java
index e30cd64..6583d26 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerLogTest.java
@@ -14,51 +14,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
-import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_LOG_OBSERVABLE;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jConsumerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires Ganache instance with few transactions")
+public class Web3jConsumerLogTest extends Web3jIntegrationTestSupport {
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Override
- protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
- }
-
- @Test(timeout = 600000L)
- public void consumerTest() throws InterruptedException {
- mockResult.setResultWaitTime(600000L);
+ @Test
+ public void consumerTest() throws Exception {
mockResult.expectedMinimumMessageCount(1);
- mockResult.assertIsSatisfied();
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
- .to("mock:result");
+ errorHandler(deadLetterChannel("mock:error"));
- from(getUrl() + OPERATION.toLowerCase() + "=" +
ETH_LOG_OBSERVABLE)
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" + ETH_LOG_OBSERVABLE +
"&"
+ + "fromBlock=earliest&"
+ + "toBlock=latest&"
+ + "address=0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952")
.to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
PENDING_TRANSACTION_OBSERVABLE)
- .to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
BLOCK_OBSERVABLE)
- .to("mock:result");
-
}
};
}
+
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerMainnetTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerMainnetTest.java
new file mode 100644
index 0000000..4877d5e
--- /dev/null
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerMainnetTest.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.web3j.integration;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.web3j.protocol.core.methods.response.EthBlock;
+
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
+import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_BLOCKS_OBSERVABLE;
+
+@Ignore("Requires a local node or registration at Infura")
+public class Web3jConsumerMainnetTest extends Web3jIntegrationTestSupport {
+
+ protected String getUrl() {
+ return "https://mainnet.infura.io/YOUR_INFURA_ID?";
+ }
+
+ @Test
+ public void consumerTest() throws Exception {
+ mockResult.expectedMinimumMessageCount(261); // block 5713030 and
5713031 have 261 transactions in total
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ errorHandler(deadLetterChannel("mock:error"));
+
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" +
REPLAY_BLOCKS_OBSERVABLE + "&"
+ + "fromBlock=5713030&"
+ + "toBlock=5713031&"
+ + "fullTransactionObjects=false")
+ .choice()
+ .when(simple("${in.header.status} != 'done'"))
+
.to("log:foo?showAll=true&multiline=true&level=INFO")
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws
Exception {
+ EthBlock.Block body =
exchange.getIn().getBody(EthBlock.Block.class);
+ List<EthBlock.TransactionResult>
transactions = body.getTransactions();
+ exchange.getIn().setBody(transactions);
+ }
+ })
+ .split(body())
+ .to("mock:result")
+ .endChoice()
+ .otherwise()
+ .log("DONE");
+ }
+ };
+ }
+}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerReplayBlockTest.java
similarity index 50%
copy from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
copy to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerReplayBlockTest.java
index e30cd64..4323a07 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerReplayBlockTest.java
@@ -14,51 +14,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
-import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
+import static
org.apache.camel.component.web3j.Web3jConstants.REPLAY_BLOCKS_OBSERVABLE;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jConsumerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires Ganache instance with 10 transactions")
+public class Web3jConsumerReplayBlockTest extends Web3jIntegrationTestSupport {
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Override
- protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
- }
-
- @Test(timeout = 600000L)
- public void consumerTest() throws InterruptedException {
- mockResult.setResultWaitTime(600000L);
- mockResult.expectedMinimumMessageCount(1);
- mockResult.assertIsSatisfied();
+ @Test
+ public void consumerTest() throws Exception {
+ mockResult.expectedMinimumMessageCount(4); // 3 blocks + DONE exchange
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
- .to("mock:result");
+ errorHandler(deadLetterChannel("mock:error"));
- from(getUrl() + OPERATION.toLowerCase() + "=" +
ETH_LOG_OBSERVABLE)
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" +
REPLAY_BLOCKS_OBSERVABLE + "&"
+ + "fromBlock=0&"
+ + "toBlock=2&"
+ + "fullTransactionObjects=false")
.to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
PENDING_TRANSACTION_OBSERVABLE)
- .to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
BLOCK_OBSERVABLE)
- .to("mock:result");
-
}
};
}
+
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerTransactionsTest.java
similarity index 52%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerTransactionsTest.java
index e30cd64..cc3c5f2 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jConsumerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jConsumerTransactionsTest.java
@@ -14,51 +14,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
-import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
+import static
org.apache.camel.component.web3j.Web3jConstants.TRANSACTION_OBSERVABLE;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jConsumerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires Ganache instance with few transactions")
+public class Web3jConsumerTransactionsTest extends Web3jIntegrationTestSupport
{
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Override
- protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
- }
-
- @Test(timeout = 600000L)
- public void consumerTest() throws InterruptedException {
- mockResult.setResultWaitTime(600000L);
+ @Test
+ public void consumerTest() throws Exception {
mockResult.expectedMinimumMessageCount(1);
- mockResult.assertIsSatisfied();
+ mockError.expectedMessageCount(0);
+ MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
- .to("mock:result");
+ errorHandler(deadLetterChannel("mock:error"));
- from(getUrl() + OPERATION.toLowerCase() + "=" +
ETH_LOG_OBSERVABLE)
+ from("web3j://" + getUrl()
+ + OPERATION.toLowerCase() + "=" +
TRANSACTION_OBSERVABLE)
.to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
PENDING_TRANSACTION_OBSERVABLE)
- .to("mock:result");
-
- from(getUrl() + OPERATION.toLowerCase() + "=" +
BLOCK_OBSERVABLE)
- .to("mock:result");
-
}
};
}
+
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jIntegrationTestSupport.java
old mode 100755
new mode 100644
similarity index 58%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jIntegrationTestSupport.java
index 00b4f95..729ab01
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jTestSupport.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jIntegrationTestSupport.java
@@ -14,24 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.web3j.protocol.Web3j;
-import rx.Subscription;
-public class Web3jTestSupport extends CamelTestSupport {
+public class Web3jIntegrationTestSupport extends CamelTestSupport {
+
@EndpointInject(uri = "mock:result")
protected MockEndpoint mockResult;
@@ -39,59 +31,20 @@ public class Web3jTestSupport extends CamelTestSupport {
@EndpointInject(uri = "mock:error")
protected MockEndpoint mockError;
- @Mock
- protected Web3j mockWeb3j;
-
- @Mock
- protected Subscription subscription;
-
-
- public Web3jTestSupport() {
+ public Web3jIntegrationTestSupport() {
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire",
"DEBUG");
}
-
- @Override
- public boolean isUseAdviceWith() {
- return true;
- }
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- registry.bind("mockWeb3j", mockWeb3j);
- return registry;
- }
-
protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?web3j=#mockWeb3j&";
+ return "http://127.0.0.1:7545?";
}
-// protected String getUrl() {
-// return "web3j://http://127.0.0.1:8545?";
-// }
-
protected Exchange createExchangeWithBodyAndHeader(Object body, String
key, Object value) {
DefaultExchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(body);
exchange.getIn().setHeader(key, value);
return exchange;
}
-
- @BeforeClass
- public static void startServer() throws Exception {
- }
-
- @AfterClass
- public static void stopServer() throws Exception {
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- super.setUp();
- }
}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerGanacheTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerGanacheTest.java
new file mode 100644
index 0000000..ee8146a
--- /dev/null
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerGanacheTest.java
@@ -0,0 +1,756 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.web3j.integration;
+
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.web3j.protocol.core.methods.response.EthBlock;
+import org.web3j.protocol.core.methods.response.EthCompileSolidity;
+import org.web3j.protocol.core.methods.response.EthLog;
+import org.web3j.protocol.core.methods.response.ShhMessages;
+import org.web3j.protocol.core.methods.response.Transaction;
+
+import static org.apache.camel.component.web3j.Web3jConstants.ADDRESS;
+import static org.apache.camel.component.web3j.Web3jConstants.ADDRESSES;
+import static org.apache.camel.component.web3j.Web3jConstants.AT_BLOCK;
+import static org.apache.camel.component.web3j.Web3jConstants.BLOCK_HASH;
+import static org.apache.camel.component.web3j.Web3jConstants.CLIENT_ID;
+import static org.apache.camel.component.web3j.Web3jConstants.DATA;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_ACCOUNTS;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_BLOCK_NUMBER;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_CALL;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_COINBASE;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_COMPILE_LLL;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_COMPILE_SERPENT;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_COMPILE_SOLIDITY;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_ESTIMATE_GAS;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_GAS_PRICE;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_GET_BALANCE;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_BLOCK_BY_HASH;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_BLOCK_BY_NUMBER;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_GET_CODE;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_COMPILERS;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_FILTER_CHANGES;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_FILTER_LOGS;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_GET_LOGS;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_STORAGE_AT;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_TRANSACTION_BY_HASH;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_TRANSACTION_COUNT;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_GET_WORK;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_HASHRATE;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_MINING;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_NEW_BLOCK_FILTER;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_NEW_FILTER;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_NEW_PENDING_TRANSACTION_FILTER;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_PROTOCOL_VERSION;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_SEND_RAW_TRANSACTION;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_SEND_TRANSACTION;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_SIGN;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_SUBMIT_HASHRATE;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_SUBMIT_WORK;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_SYNCING;
+import static
org.apache.camel.component.web3j.Web3jConstants.ETH_UNINSTALL_FILTER;
+import static org.apache.camel.component.web3j.Web3jConstants.FILTER_ID;
+import static org.apache.camel.component.web3j.Web3jConstants.FROM_ADDRESS;
+import static org.apache.camel.component.web3j.Web3jConstants.FROM_BLOCK;
+import static
org.apache.camel.component.web3j.Web3jConstants.FULL_TRANSACTION_OBJECTS;
+import static org.apache.camel.component.web3j.Web3jConstants.GAS_LIMIT;
+import static org.apache.camel.component.web3j.Web3jConstants.GAS_PRICE;
+import static org.apache.camel.component.web3j.Web3jConstants.HEADER_POW_HASH;
+import static org.apache.camel.component.web3j.Web3jConstants.INDEX;
+import static org.apache.camel.component.web3j.Web3jConstants.MIX_DIGEST;
+import static org.apache.camel.component.web3j.Web3jConstants.NET_LISTENING;
+import static org.apache.camel.component.web3j.Web3jConstants.NET_PEER_COUNT;
+import static org.apache.camel.component.web3j.Web3jConstants.NET_VERSION;
+import static org.apache.camel.component.web3j.Web3jConstants.NONCE;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
+import static org.apache.camel.component.web3j.Web3jConstants.POSITION;
+import static org.apache.camel.component.web3j.Web3jConstants.PRIORITY;
+import static
org.apache.camel.component.web3j.Web3jConstants.SHA3_HASH_OF_DATA_TO_SIGN;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_ADD_TO_GROUP;
+import static
org.apache.camel.component.web3j.Web3jConstants.SHH_GET_FILTER_CHANGES;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_GET_MESSAGES;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_HAS_IDENTITY;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_NEW_FILTER;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_NEW_GROUP;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_NEW_IDENTITY;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_POST;
+import static
org.apache.camel.component.web3j.Web3jConstants.SHH_UNINSTALL_FILTER;
+import static org.apache.camel.component.web3j.Web3jConstants.SHH_VERSION;
+import static
org.apache.camel.component.web3j.Web3jConstants.SIGNED_TRANSACTION_DATA;
+import static org.apache.camel.component.web3j.Web3jConstants.SOURCE_CODE;
+import static org.apache.camel.component.web3j.Web3jConstants.TOPICS;
+import static org.apache.camel.component.web3j.Web3jConstants.TO_ADDRESS;
+import static org.apache.camel.component.web3j.Web3jConstants.TO_BLOCK;
+import static org.apache.camel.component.web3j.Web3jConstants.TRANSACTION;
+import static org.apache.camel.component.web3j.Web3jConstants.TRANSACTION_HASH;
+import static org.apache.camel.component.web3j.Web3jConstants.TTL;
+import static org.apache.camel.component.web3j.Web3jConstants.VALUE;
+import static
org.apache.camel.component.web3j.Web3jConstants.WEB3_CLIENT_VERSION;
+import static org.apache.camel.component.web3j.Web3jConstants.WEB3_SHA3;
+
+@Ignore("Requires a locally running Ganache instance")
+public class Web3jProducerGanacheTest extends Web3jIntegrationTestSupport {
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Test
+ public void ethClientVersionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
WEB3_CLIENT_VERSION);
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethNetWeb3Sha3Test() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
WEB3_SHA3);
+ exchange.getIn().setBody("0x68656c6c6f20776f726c64");
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+
assertTrue(body.equals("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"));
+ }
+
+ @Test
+ public void ethNetVersionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
NET_VERSION);
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethNetListeningTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
NET_LISTENING);
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ //a bug in Ganache returns wrong formatted data
+ @Ignore
+ @Test
+ public void ethNetPeerCountTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
NET_PEER_COUNT);
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethProtocolVersionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_PROTOCOL_VERSION);
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethSyncingTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SYNCING);
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethCoinbaseTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_COINBASE);
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethMiningTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_MINING);
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethHashrateTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_HASHRATE);
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGasPriceTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GAS_PRICE);
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethAccountsTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_ACCOUNTS);
+ template.send(exchange);
+ List<String> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethBlockNumberTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_BLOCK_NUMBER);
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetBalanceTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_BALANCE);
+ exchange.getIn().setHeader(ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(AT_BLOCK, "0");
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+// Given this contract created at address
0x3B558E3a9ae7944FEe7a3A1010DD10f05a01034B:
+// pragma solidity ^0.4.23;
+// contract Storage {
+// uint pos0;
+// function Storage() {
+// pos0 = 5;
+// }
+// }
+ @Test
+ public void ethGetStorageAtTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_STORAGE_AT);
+ exchange.getIn().setHeader(ADDRESS,
"0x3B558E3a9ae7944FEe7a3A1010DD10f05a01034B");
+ exchange.getIn().setHeader(AT_BLOCK, "6");
+ exchange.getIn().setHeader(POSITION, BigInteger.ZERO);
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetTransactionCountTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_TRANSACTION_COUNT);
+ exchange.getIn().setHeader(ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ //a bug in Ganache returns wrong formatted data
+ @Ignore
+ @Test
+ public void ethGetBlockTransactionCountByHashTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_BLOCK_TRANSACTION_COUNT_BY_HASH);
+ exchange.getIn().setHeader(BLOCK_HASH,
"0x1fab3a1cc7f016029e41e72363362caf9bd09388ba94070d6ada37b8757ab19a"); //
Ganache block 0
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ //a bug in Ganache returns wrong formatted data
+ @Ignore
+ @Test
+ public void ethGetBlockTransactionCountByNumberTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER);
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethGetUncleCountByBlockHashTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH);
+ exchange.getIn().setHeader(BLOCK_HASH,
"0x1fab3a1cc7f016029e41e72363362caf9bd09388ba94070d6ada37b8757ab19a"); //
Ganache block 0
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethGetUncleCountByBlockNumberTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_UNCLE_COUNT_BY_BLOCK_HASH);
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetCodeTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_CODE);
+ exchange.getIn().setHeader(ADDRESS,
"0x3B558E3a9ae7944FEe7a3A1010DD10f05a01034B");
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethSignTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SIGN);
+ exchange.getIn().setHeader(ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(SHA3_HASH_OF_DATA_TO_SIGN, "hello");
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethSendTransactionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SEND_TRANSACTION);
+ exchange.getIn().setHeader(FROM_ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(TO_ADDRESS,
"0x883E97F42e3cfC2b233DC684574F33B96a0329C4");
+ exchange.getIn().setHeader(NONCE, BigInteger.valueOf(9L));
+ exchange.getIn().setHeader(GAS_PRICE,
BigInteger.valueOf(10000000000000L));
+ exchange.getIn().setHeader(GAS_LIMIT, BigInteger.valueOf(30400L));
+ exchange.getIn().setHeader(VALUE, BigInteger.valueOf(50000000000000L));
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ //wrong reminder
+ @Ignore
+ @Test
+ public void ethSendRawTransactionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SEND_RAW_TRANSACTION);
+ exchange.getIn().setHeader(SIGNED_TRANSACTION_DATA,
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675");
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethCallTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_CALL);
+ exchange.getIn().setHeader(FROM_ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(TO_ADDRESS,
"0x3B558E3a9ae7944FEe7a3A1010DD10f05a01034B");
+ exchange.getIn().setHeader(NONCE, BigInteger.valueOf(9L));
+ exchange.getIn().setHeader(GAS_PRICE,
BigInteger.valueOf(10000000000000L));
+ exchange.getIn().setHeader(GAS_LIMIT, BigInteger.valueOf(30400L));
+ exchange.getIn().setHeader(VALUE, BigInteger.valueOf(50000000000000L));
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethEstimateGasTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_ESTIMATE_GAS);
+ exchange.getIn().setHeader(FROM_ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(TO_ADDRESS,
"0x3B558E3a9ae7944FEe7a3A1010DD10f05a01034B");
+ exchange.getIn().setHeader(NONCE, BigInteger.valueOf(9L));
+ exchange.getIn().setHeader(GAS_PRICE,
BigInteger.valueOf(10000000000000L));
+ exchange.getIn().setHeader(GAS_LIMIT, BigInteger.valueOf(30400L));
+ exchange.getIn().setHeader(VALUE, BigInteger.valueOf(50000000000000L));
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetBlockByHashTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_BLOCK_BY_HASH);
+ exchange.getIn().setHeader(FULL_TRANSACTION_OBJECTS, true);
+ exchange.getIn().setHeader(BLOCK_HASH,
"0x1fab3a1cc7f016029e41e72363362caf9bd09388ba94070d6ada37b8757ab19a");
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetBlockByNumberTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_BLOCK_BY_NUMBER);
+ exchange.getIn().setHeader(FULL_TRANSACTION_OBJECTS, true);
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetTransactionByHashTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_TRANSACTION_BY_HASH);
+ exchange.getIn().setHeader(TRANSACTION_HASH,
"0xb082f44cb2faa0f33056d5a341d1a7be73ecfcc6eb3bcb643ab03016ce4b6772");
+
+ template.send(exchange);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetTransactionByBlockHashAndIndexTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX);
+ exchange.getIn().setHeader(BLOCK_HASH,
"0x226aa81c5a7c86caff96af0bdb58739491d4730b629932ca80f3530558282e1d");
+ exchange.getIn().setHeader(INDEX, BigInteger.ZERO);
+
+ template.send(exchange);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetTransactionByBlockNumberAndIndexTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX);
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ exchange.getIn().setHeader(INDEX, BigInteger.ZERO);
+
+ template.send(exchange);
+ Transaction body = exchange.getIn().getBody(Transaction.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethGetUncleByBlockHashAndIndexTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_UNCLE_BY_BLOCK_HASH_AND_INDEX);
+ exchange.getIn().setHeader(BLOCK_HASH,
"0x226aa81c5a7c86caff96af0bdb58739491d4730b629932ca80f3530558282e1d");
+ exchange.getIn().setHeader(INDEX, BigInteger.ZERO);
+
+ template.send(exchange);
+ EthBlock.Block body = exchange.getIn().getBody(EthBlock.Block.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethGetUncleByBlockNumberAndIndexTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX);
+ exchange.getIn().setHeader(AT_BLOCK, "latest");
+ exchange.getIn().setHeader(INDEX, BigInteger.ZERO);
+
+ template.send(exchange);
+ EthBlock.Block body = exchange.getIn().getBody(EthBlock.Block.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetCompilers() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_COMPILERS);
+
+ template.send(exchange);
+ List<String> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethCompileSolidityTest() throws Exception {
+ String soliditySample =
+ "pragma solidity ^0.4.23;"
+ + "contract Storage {"
+ + " uint pos0;"
+ + " function Storage() {"
+ + " pos0 = 5;"
+ + " }"
+ + "}";
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_COMPILE_SOLIDITY);
+ exchange.getIn().setHeader(SOURCE_CODE, soliditySample);
+ template.send(exchange);
+ Map<String, EthCompileSolidity.Code> body =
exchange.getIn().getBody(Map.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethCompileLLLTest() throws Exception {
+ String sampleCode = "(returnlll (suicide (caller)))";
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_COMPILE_LLL);
+ exchange.getIn().setHeader(SOURCE_CODE, sampleCode);
+ template.send(exchange);
+ Map<String, EthCompileSolidity.Code> body =
exchange.getIn().getBody(Map.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void ethCompileSerpentTest() throws Exception {
+ String serpentSample = "(returnlll (suicide (caller)))";
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_COMPILE_SERPENT);
+ exchange.getIn().setHeader(SOURCE_CODE, serpentSample);
+ template.send(exchange);
+ Map<String, EthCompileSolidity.Code> body =
exchange.getIn().getBody(Map.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethNewFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_NEW_FILTER);
+ exchange.getIn().setHeader(FROM_BLOCK, "earliest");
+ exchange.getIn().setHeader(TO_BLOCK, "latest");
+ exchange.getIn().setHeader(ADDRESSES,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+ exchange.getIn().setHeader(TOPICS,
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
+
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethNewBlockFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_NEW_BLOCK_FILTER);
+
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethNewPendingTransactionFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_NEW_PENDING_TRANSACTION_FILTER);
+
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethUninstallFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_UNINSTALL_FILTER);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(8));
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetFilterChangesTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_FILTER_CHANGES);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(7));
+
+ template.send(exchange);
+ List<EthLog.LogResult> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetFilterLogsTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_FILTER_LOGS);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(6));
+
+ template.send(exchange);
+ List<EthLog.LogResult> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetLogsTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_LOGS);
+ exchange.getIn().setHeader(FROM_BLOCK, "earliest");
+ exchange.getIn().setHeader(TO_BLOCK, "latest");
+// exchange.getIn().setHeader(ADDRESSES,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+// exchange.getIn().setHeader(TOPICS,
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
+
+ template.send(exchange);
+ List<EthLog.LogResult> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethGetWorkTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_GET_WORK);
+
+ template.send(exchange);
+ List<String> body = exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethSubmitWorkTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SUBMIT_WORK);
+ exchange.getIn().setHeader(NONCE, "0x0000000000000001");
+ exchange.getIn().setHeader(HEADER_POW_HASH,
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef");
+ exchange.getIn().setHeader(MIX_DIGEST,
"0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000");
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void ethSubmitHashrateTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_SUBMIT_HASHRATE);
+ exchange.getIn().setHeader(ETH_HASHRATE,
"0x0000000000000000000000000000000000000000000000000000000000500000");
+ exchange.getIn().setHeader(CLIENT_ID,
"0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c");
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void shhVersionTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_VERSION);
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhPostTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_POST);
+ exchange.getIn().setHeader(FROM_ADDRESS,
"0x04f96a5e25610293e42a73908e93ccc8c4d4dc0edcfa9fa872f50cb214e08ebf61a03e245533f97284d442460f2998cd41858798ddfd4d661997d3940272b717b1");
+ exchange.getIn().setHeader(TO_ADDRESS,
"0x3e245533f97284d442460f2998cd41858798ddf04f96a5e25610293e42a73908e93ccc8c4d4dc0edcfa9fa872f50cb214e08ebf61a0d4d661997d3940272b717b1");
+ exchange.getIn().setHeader(TOPICS,
"0x776869737065722d636861742d636c69656e74");
+ exchange.getIn().setHeader(DATA, "0x7b2274797065223a226d6");
+ exchange.getIn().setHeader(PRIORITY, BigInteger.valueOf(64));
+ exchange.getIn().setHeader(TTL, BigInteger.valueOf(64));
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhNewIdentityTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_NEW_IDENTITY);
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhHasIdentityTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_HAS_IDENTITY);
+ exchange.getIn().setHeader(ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhNewGroupTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_NEW_GROUP);
+
+ template.send(exchange);
+ String body = exchange.getIn().getBody(String.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhAddToGroupTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_ADD_TO_GROUP);
+ exchange.getIn().setHeader(ADDRESS,
"0xc8CDceCE5d006dAB638029EBCf6Dd666efF5A952");
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhNewFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_NEW_FILTER);
+ exchange.getIn().setHeader(DATA,
"0x04f96a5e25610293e42a73908e93ccc8c4d4dc0edcfa9fa872f50cb214e08ebf61a03e245533f97284d442460f2998cd41858798ddfd4d661997d3940272b717b1");
+ exchange.getIn().setHeader(TOPICS, "0x12341234bf4b564f");
+
+ template.send(exchange);
+ BigInteger body = exchange.getIn().getBody(BigInteger.class);
+ assertTrue(body != null);
+ }
+
+ //not supported operation by Ganache
+ @Ignore
+ @Test
+ public void shhUninstallFilterTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_UNINSTALL_FILTER);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(123));
+
+ template.send(exchange);
+ Boolean body = exchange.getIn().getBody(Boolean.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void shhGetFilterChangesTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_GET_FILTER_CHANGES);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(123));
+
+ template.send(exchange);
+ List<ShhMessages.SshMessage> body =
exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Test
+ public void shhGetMessagesTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
SHH_GET_MESSAGES);
+ exchange.getIn().setHeader(FILTER_ID, BigInteger.valueOf(123));
+
+ template.send(exchange);
+ List<ShhMessages.SshMessage> body =
exchange.getIn().getBody(List.class);
+ assertTrue(body != null);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("web3j://" + getUrl() + OPERATION.toLowerCase() +
"=" + TRANSACTION);
+ }
+ };
+ }
+}
diff --git
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerIntegrationTest.java
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerMainnetTest.java
similarity index 67%
rename from
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerIntegrationTest.java
rename to
components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerMainnetTest.java
index ef4a557..d26280d 100644
---
a/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/Web3jProducerIntegrationTest.java
+++
b/components/camel-web3j/src/test/java/org/apache/camel/component/web3j/integration/Web3jProducerMainnetTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.web3j;
+package org.apache.camel.component.web3j.integration;
import org.apache.camel.Exchange;
import org.apache.camel.Produce;
@@ -23,17 +23,21 @@ import org.apache.camel.builder.RouteBuilder;
import org.junit.Ignore;
import org.junit.Test;
-import static org.apache.camel.component.web3j.Web3jConstants.*;
+import static org.apache.camel.component.web3j.Web3jConstants.ETH_BLOCK_NUMBER;
+import static org.apache.camel.component.web3j.Web3jConstants.NET_VERSION;
+import static org.apache.camel.component.web3j.Web3jConstants.OPERATION;
+import static org.apache.camel.component.web3j.Web3jConstants.TRANSACTION;
+import static
org.apache.camel.component.web3j.Web3jConstants.WEB3_CLIENT_VERSION;
+import static org.apache.camel.component.web3j.Web3jConstants.WEB3_SHA3;
-@Ignore("Integration test that requires a locally running synced ethereum
node")
-public class Web3jProducerIntegrationTest extends Web3jTestSupport {
+@Ignore("Requires a local node or registration at Infura")
+public class Web3jProducerMainnetTest extends Web3jIntegrationTestSupport {
@Produce(uri = "direct:start")
protected ProducerTemplate template;
- @Override
protected String getUrl() {
- return "web3j://http://127.0.0.1:8545?";
+ return "https://mainnet.infura.io/YOUR_INFURA_ID?";
}
@Test
@@ -61,12 +65,20 @@ public class Web3jProducerIntegrationTest extends
Web3jTestSupport {
assertTrue(body.equals("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"));
}
+ @Test
+ public void ethBlockNumberTest() throws Exception {
+ Exchange exchange = createExchangeWithBodyAndHeader(null, OPERATION,
ETH_BLOCK_NUMBER);
+ template.send(exchange);
+ Long body = exchange.getIn().getBody(Long.class);
+ assertTrue(body.longValue() > 5714225); // latest block at time of
writing
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
from("direct:start")
- .to(getUrl() + OPERATION.toLowerCase() + "=" +
TRANSACTION);
+ .to("web3j://" + getUrl() + OPERATION.toLowerCase() +
"=" + TRANSACTION);
}
};
}
diff --git
a/platforms/spring-boot/components-starter/camel-web3j-starter/src/main/java/org/apache/camel/component/web3j/springboot/Web3jComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-web3j-starter/src/main/java/org/apache/camel/component/web3j/springboot/Web3jComponentConfiguration.java
index ec085a7..ac2f9e2 100644
---
a/platforms/spring-boot/components-starter/camel-web3j-starter/src/main/java/org/apache/camel/component/web3j/springboot/Web3jComponentConfiguration.java
+++
b/platforms/spring-boot/components-starter/camel-web3j-starter/src/main/java/org/apache/camel/component/web3j/springboot/Web3jComponentConfiguration.java
@@ -147,9 +147,9 @@ public class Web3jComponentConfiguration
*/
private BigInteger filterId;
/**
- * The transactions index position in the block.
+ * The transactions/uncle index position in the block.
*/
- private BigInteger transactionIndex;
+ private BigInteger index;
/**
* The signed transaction data for a new message call transaction or a
* contract creation for signed transactions.
@@ -341,12 +341,12 @@ public class Web3jComponentConfiguration
this.filterId = filterId;
}
- public BigInteger getTransactionIndex() {
- return transactionIndex;
+ public BigInteger getIndex() {
+ return index;
}
- public void setTransactionIndex(BigInteger transactionIndex) {
- this.transactionIndex = transactionIndex;
+ public void setIndex(BigInteger index) {
+ this.index = index;
}
public String getSignedTransactionData() {
--
To stop receiving notification emails like this one, please contact
[email protected].