@@ -37,21 +37,21 @@ func TestInvalidTransactions(t *testing.T) {
37
37
}
38
38
39
39
from , _ := tx .From ()
40
- pool .state .AddBalance (from , big .NewInt (1 ))
40
+ pool .currentState () .AddBalance (from , big .NewInt (1 ))
41
41
err = pool .Add (tx )
42
42
if err != ErrInsufficientFunds {
43
43
t .Error ("expected" , ErrInsufficientFunds )
44
44
}
45
45
46
46
balance := new (big.Int ).Add (tx .Value (), new (big.Int ).Mul (tx .Gas (), tx .GasPrice ()))
47
- pool .state .AddBalance (from , balance )
47
+ pool .currentState () .AddBalance (from , balance )
48
48
err = pool .Add (tx )
49
49
if err != ErrIntrinsicGas {
50
50
t .Error ("expected" , ErrIntrinsicGas , "got" , err )
51
51
}
52
52
53
- pool .state .SetNonce (from , 1 )
54
- pool .state .AddBalance (from , big .NewInt (0xffffffffffffff ))
53
+ pool .currentState () .SetNonce (from , 1 )
54
+ pool .currentState () .AddBalance (from , big .NewInt (0xffffffffffffff ))
55
55
tx .GasLimit = big .NewInt (100000 )
56
56
tx .Price = big .NewInt (1 )
57
57
tx .SignECDSA (key )
@@ -67,7 +67,7 @@ func TestTransactionQueue(t *testing.T) {
67
67
tx := transaction ()
68
68
tx .SignECDSA (key )
69
69
from , _ := tx .From ()
70
- pool .state .AddBalance (from , big .NewInt (1 ))
70
+ pool .currentState () .AddBalance (from , big .NewInt (1 ))
71
71
pool .queueTx (tx .Hash (), tx )
72
72
73
73
pool .checkQueue ()
@@ -79,7 +79,7 @@ func TestTransactionQueue(t *testing.T) {
79
79
tx .SetNonce (1 )
80
80
tx .SignECDSA (key )
81
81
from , _ = tx .From ()
82
- pool .state .SetNonce (from , 2 )
82
+ pool .currentState () .SetNonce (from , 2 )
83
83
pool .queueTx (tx .Hash (), tx )
84
84
pool .checkQueue ()
85
85
if _ , ok := pool .pending [tx .Hash ()]; ok {
@@ -117,7 +117,7 @@ func TestRemoveTx(t *testing.T) {
117
117
tx := transaction ()
118
118
tx .SignECDSA (key )
119
119
from , _ := tx .From ()
120
- pool .state .AddBalance (from , big .NewInt (1 ))
120
+ pool .currentState () .AddBalance (from , big .NewInt (1 ))
121
121
pool .queueTx (tx .Hash (), tx )
122
122
pool .addTx (tx .Hash (), from , tx )
123
123
if len (pool .queue ) != 1 {
@@ -146,7 +146,7 @@ func TestNegativeValue(t *testing.T) {
146
146
tx .Value ().Set (big .NewInt (- 1 ))
147
147
tx .SignECDSA (key )
148
148
from , _ := tx .From ()
149
- pool .state .AddBalance (from , big .NewInt (1 ))
149
+ pool .currentState () .AddBalance (from , big .NewInt (1 ))
150
150
err := pool .Add (tx )
151
151
if err != ErrNegativeValue {
152
152
t .Error ("expected" , ErrNegativeValue , "got" , err )
@@ -156,7 +156,15 @@ func TestNegativeValue(t *testing.T) {
156
156
func TestTransactionChainFork (t * testing.T ) {
157
157
pool , key := setupTxPool ()
158
158
addr := crypto .PubkeyToAddress (key .PublicKey )
159
- pool .currentState ().AddBalance (addr , big .NewInt (100000000000000 ))
159
+ resetState := func () {
160
+ db , _ := ethdb .NewMemDatabase ()
161
+ statedb := state .New (common.Hash {}, db )
162
+ pool .currentState = func () * state.StateDB { return statedb }
163
+ pool .currentState ().AddBalance (addr , big .NewInt (100000000000000 ))
164
+ pool .resetState ()
165
+ }
166
+ resetState ()
167
+
160
168
tx := transaction ()
161
169
tx .GasLimit = big .NewInt (100000 )
162
170
tx .SignECDSA (key )
@@ -168,7 +176,7 @@ func TestTransactionChainFork(t *testing.T) {
168
176
pool .RemoveTransactions ([]* types.Transaction {tx })
169
177
170
178
// reset the pool's internal state
171
- pool . resetState ()
179
+ resetState ()
172
180
err = pool .add (tx )
173
181
if err != nil {
174
182
t .Error ("didn't expect error" , err )
@@ -178,7 +186,15 @@ func TestTransactionChainFork(t *testing.T) {
178
186
func TestTransactionDoubleNonce (t * testing.T ) {
179
187
pool , key := setupTxPool ()
180
188
addr := crypto .PubkeyToAddress (key .PublicKey )
181
- pool .currentState ().AddBalance (addr , big .NewInt (100000000000000 ))
189
+ resetState := func () {
190
+ db , _ := ethdb .NewMemDatabase ()
191
+ statedb := state .New (common.Hash {}, db )
192
+ pool .currentState = func () * state.StateDB { return statedb }
193
+ pool .currentState ().AddBalance (addr , big .NewInt (100000000000000 ))
194
+ pool .resetState ()
195
+ }
196
+ resetState ()
197
+
182
198
tx := transaction ()
183
199
tx .GasLimit = big .NewInt (100000 )
184
200
tx .SignECDSA (key )
0 commit comments