12
12
*/
13
13
package org .web3j .protocol .scenarios ;
14
14
15
- import java .math .BigDecimal ;
16
- import java .math .BigInteger ;
17
- import java .util .Iterator ;
18
- import java .util .LinkedList ;
19
- import java .util .List ;
20
- import java .util .Map ;
21
- import java .util .concurrent .ConcurrentHashMap ;
22
- import java .util .concurrent .ConcurrentLinkedQueue ;
23
- import java .util .concurrent .Future ;
24
-
25
15
import com .carrotsearch .junitbenchmarks .BenchmarkOptions ;
26
16
import org .junit .jupiter .api .BeforeAll ;
27
17
import org .junit .jupiter .api .Test ;
28
-
29
18
import org .web3j .EVMTest ;
30
19
import org .web3j .NodeType ;
31
20
import org .web3j .protocol .Web3j ;
38
27
import org .web3j .tx .response .QueuingTransactionReceiptProcessor ;
39
28
import org .web3j .utils .Convert ;
40
29
41
- import static org .junit .jupiter .api .Assertions .assertFalse ;
42
- import static org .junit .jupiter .api .Assertions .assertTrue ;
30
+ import java .math .BigDecimal ;
31
+ import java .math .BigInteger ;
32
+ import java .util .Iterator ;
33
+ import java .util .LinkedList ;
34
+ import java .util .List ;
35
+ import java .util .Map ;
36
+ import java .util .concurrent .ConcurrentHashMap ;
37
+ import java .util .concurrent .ConcurrentLinkedQueue ;
38
+ import java .util .concurrent .Future ;
39
+
40
+ import static org .junit .jupiter .api .Assertions .*;
43
41
import static org .web3j .tx .TransactionManager .DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH ;
44
42
45
43
@ EVMTest (type = NodeType .BESU )
@@ -76,11 +74,11 @@ public void testTransactionPolling() throws Exception {
76
74
}
77
75
78
76
for (int i = 0 ;
79
- i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !transactionReceipts .isEmpty ();
80
- i ++) {
77
+ i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !transactionReceipts .isEmpty ();
78
+ i ++) {
81
79
82
80
for (Iterator <Future <TransactionReceipt >> iterator = transactionReceipts .iterator ();
83
- iterator .hasNext (); ) {
81
+ iterator .hasNext (); ) {
84
82
Future <TransactionReceipt > transactionReceiptFuture = iterator .next ();
85
83
86
84
if (transactionReceiptFuture .isDone ()) {
@@ -96,6 +94,32 @@ public void testTransactionPolling() throws Exception {
96
94
assertTrue (transactionReceipts .isEmpty ());
97
95
}
98
96
97
+ @ Test
98
+ public void testTransactionResetNonce () throws Exception {
99
+ FastRawTransactionManager transactionManager =
100
+ new FastRawTransactionManager (
101
+ web3j ,
102
+ ALICE ,
103
+ new PollingTransactionReceiptProcessor (
104
+ web3j , POLLING_FREQUENCY , DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH ));
105
+
106
+ Transfer transfer = new Transfer (web3j , transactionManager );
107
+ BigInteger gasPrice = transfer .requestCurrentGasPrice ();
108
+
109
+ createTransaction (transfer , gasPrice ).send ();
110
+ createTransaction (transfer , gasPrice ).send ();
111
+
112
+ BigInteger expected = transactionManager .getCurrentNonce ();
113
+
114
+ transactionManager .resetNonce ();
115
+
116
+ BigInteger actual = transactionManager .getCurrentNonce ();
117
+
118
+ createTransaction (transfer , gasPrice ).send ();
119
+
120
+ assertEquals (expected , actual );
121
+ }
122
+
99
123
@ Test
100
124
public void testTransactionQueuing () throws Exception {
101
125
@@ -116,7 +140,8 @@ public void accept(TransactionReceipt transactionReceipt) {
116
140
}
117
141
118
142
@ Override
119
- public void exception (Exception exception ) {}
143
+ public void exception (Exception exception ) {
144
+ }
120
145
},
121
146
DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH ,
122
147
POLLING_FREQUENCY ));
@@ -131,8 +156,8 @@ public void exception(Exception exception) {}
131
156
}
132
157
133
158
for (int i = 0 ;
134
- i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !pendingTransactions .isEmpty ();
135
- i ++) {
159
+ i < DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH && !pendingTransactions .isEmpty ();
160
+ i ++) {
136
161
for (TransactionReceipt transactionReceipt : transactionReceipts ) {
137
162
assertFalse (transactionReceipt .getBlockHash ().isEmpty ());
138
163
pendingTransactions .remove (transactionReceipt .getTransactionHash ());
0 commit comments