Skip to content

Commit

Permalink
Add test for FastRawTransactionManager.resetNonce
Browse files Browse the repository at this point in the history
Signed-off-by: Junsung Cho <[email protected]>
  • Loading branch information
junsung-cho committed Aug 8, 2024
1 parent f34ea4b commit 2582953
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,57 @@ public void testTransactionPolling() throws Exception {
assertTrue(transactionReceipts.isEmpty());
}

@Test
public void testTransactionPollingResetNonce() throws Exception {

List<Future<TransactionReceipt>> 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<TransactionReceipt> transactionReceiptFuture =
createTransaction(transfer, gasPrice).sendAsync();
transactionReceipts.add(transactionReceiptFuture);
}

transactionManager.resetNonce();

for (int i = 0; i < COUNT; i++) {

Future<TransactionReceipt> transactionReceiptFuture =
createTransaction(transfer, gasPrice).sendAsync();
transactionReceipts.add(transactionReceiptFuture);
}

for (int i = 0;
i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !transactionReceipts.isEmpty();
i++) {

for (Iterator<Future<TransactionReceipt>> iterator = transactionReceipts.iterator();
iterator.hasNext(); ) {
Future<TransactionReceipt> 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 {

Expand Down

0 comments on commit 2582953

Please sign in to comment.