diff --git a/core/src/main/java/org/web3j/tx/FastRawTransactionManager.java b/core/src/main/java/org/web3j/tx/FastRawTransactionManager.java index bb35c9440..994c0e1a7 100644 --- a/core/src/main/java/org/web3j/tx/FastRawTransactionManager.java +++ b/core/src/main/java/org/web3j/tx/FastRawTransactionManager.java @@ -73,7 +73,7 @@ public BigInteger getCurrentNonce() { } public synchronized void resetNonce() throws IOException { - nonce = super.getNonce().subtract(BigInteger.ONE); + nonce = super.getNonce(); //.subtract(BigInteger.ONE); } public synchronized void clearNonce() { diff --git a/integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java b/integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java index c84c6e92e..c437f6145 100644 --- a/integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java +++ b/integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java @@ -96,6 +96,57 @@ public void testTransactionPolling() throws Exception { assertTrue(transactionReceipts.isEmpty()); } + @Test + public void testTransactionPollingResetNonce() throws Exception { + + List> transactionReceipts = new LinkedList<>(); + FastRawTransactionManager transactionManager = + new FastRawTransactionManager( + web3j, + ALICE, + new PollingTransactionReceiptProcessor( + web3j, POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH)); + + Transfer transfer = new Transfer(web3j, transactionManager); + BigInteger gasPrice = transfer.requestCurrentGasPrice(); + + for (int i = 0; i < COUNT; i++) { + + Future transactionReceiptFuture = + createTransaction(transfer, gasPrice).sendAsync(); + transactionReceipts.add(transactionReceiptFuture); + } + + transactionManager.resetNonce(); + + for (int i = 0; i < COUNT; i++) { + + Future transactionReceiptFuture = + createTransaction(transfer, gasPrice).sendAsync(); + transactionReceipts.add(transactionReceiptFuture); + } + + for (int i = 0; + i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !transactionReceipts.isEmpty(); + i++) { + + for (Iterator> iterator = transactionReceipts.iterator(); + iterator.hasNext(); ) { + Future transactionReceiptFuture = iterator.next(); + + if (transactionReceiptFuture.isDone()) { + TransactionReceipt transactionReceipt = transactionReceiptFuture.get(); + assertFalse(transactionReceipt.getBlockHash().isEmpty()); + iterator.remove(); + } + } + + Thread.sleep(POLLING_FREQUENCY); + } + + assertTrue(transactionReceipts.isEmpty()); + } + @Test public void testTransactionQueuing() throws Exception {