@@ -12,7 +12,6 @@ import (
12
12
"github.com/NethermindEth/juno/mempool"
13
13
"github.com/NethermindEth/juno/mocks"
14
14
"github.com/NethermindEth/juno/utils"
15
- "github.com/stretchr/testify/assert"
16
15
"github.com/stretchr/testify/require"
17
16
"go.uber.org/mock/gomock"
18
17
)
@@ -50,7 +49,7 @@ func TestMempool(t *testing.T) {
50
49
require .NoError (t , err )
51
50
52
51
l := pool .Len ()
53
- assert .Equal (t , uint16 (0 ), l )
52
+ require .Equal (t , uint16 (0 ), l )
54
53
55
54
_ , err = pool .Pop ()
56
55
require .Equal (t , err .Error (), "transaction pool is empty" )
@@ -59,7 +58,7 @@ func TestMempool(t *testing.T) {
59
58
for i := uint64 (1 ); i < 4 ; i ++ {
60
59
senderAddress := new (felt.Felt ).SetUint64 (i )
61
60
state .EXPECT ().ContractNonce (senderAddress ).Return (new (felt.Felt ).SetUint64 (0 ), nil )
62
- assert .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
61
+ require .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
63
62
Transaction : & core.InvokeTransaction {
64
63
TransactionHash : new (felt.Felt ).SetUint64 (i ),
65
64
Nonce : new (felt.Felt ).SetUint64 (1 ),
@@ -68,23 +67,23 @@ func TestMempool(t *testing.T) {
68
67
},
69
68
}))
70
69
l := pool .Len ()
71
- assert .Equal (t , uint16 (i ), l )
70
+ require .Equal (t , uint16 (i ), l )
72
71
}
73
72
// consume some (remove 1,2, keep 3)
74
73
for i := uint64 (1 ); i < 3 ; i ++ {
75
74
txn , err := pool .Pop ()
76
75
require .NoError (t , err )
77
- assert .Equal (t , i , txn .Transaction .Hash ().Uint64 ())
76
+ require .Equal (t , i , txn .Transaction .Hash ().Uint64 ())
78
77
79
78
l := pool .Len ()
80
- assert .Equal (t , uint16 (3 - i ), l )
79
+ require .Equal (t , uint16 (3 - i ), l )
81
80
}
82
81
83
82
// push multiple to non empty (push 4,5. now have 3,4,5)
84
83
for i := uint64 (4 ); i < 6 ; i ++ {
85
84
senderAddress := new (felt.Felt ).SetUint64 (i )
86
85
state .EXPECT ().ContractNonce (senderAddress ).Return (new (felt.Felt ).SetUint64 (0 ), nil )
87
- assert .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
86
+ require .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
88
87
Transaction : & core.InvokeTransaction {
89
88
TransactionHash : new (felt.Felt ).SetUint64 (i ),
90
89
Nonce : new (felt.Felt ).SetUint64 (1 ),
@@ -93,11 +92,11 @@ func TestMempool(t *testing.T) {
93
92
},
94
93
}))
95
94
l := pool .Len ()
96
- assert .Equal (t , uint16 (i - 2 ), l )
95
+ require .Equal (t , uint16 (i - 2 ), l )
97
96
}
98
97
99
98
// push more than max
100
- assert .ErrorIs (t , pool .Push (& mempool.BroadcastedTransaction {
99
+ require .ErrorIs (t , pool .Push (& mempool.BroadcastedTransaction {
101
100
Transaction : & core.InvokeTransaction {
102
101
TransactionHash : new (felt.Felt ).SetUint64 (123 ),
103
102
},
@@ -107,9 +106,9 @@ func TestMempool(t *testing.T) {
107
106
for i := uint64 (3 ); i < 6 ; i ++ {
108
107
txn , err := pool .Pop ()
109
108
require .NoError (t , err )
110
- assert .Equal (t , i , txn .Transaction .Hash ().Uint64 ())
109
+ require .Equal (t , i , txn .Transaction .Hash ().Uint64 ())
111
110
}
112
- assert .Equal (t , uint16 (0 ), l )
111
+ require .Equal (t , uint16 (0 ), l )
113
112
114
113
_ , err = pool .Pop ()
115
114
require .Equal (t , err .Error (), "transaction pool is empty" )
@@ -122,51 +121,50 @@ func TestRestoreMempool(t *testing.T) {
122
121
mockCtrl := gomock .NewController (t )
123
122
t .Cleanup (mockCtrl .Finish )
124
123
state := mocks .NewMockStateHistoryReader (mockCtrl )
125
- testDB , _ , err := setupDatabase ("testrestoremempool" , true )
124
+ testDB , dbCloser , err := setupDatabase ("testrestoremempool" , true )
126
125
require .NoError (t , err )
126
+ defer dbCloser ()
127
127
128
128
pool , closer , err := mempool .New (testDB , state , 1024 , log )
129
129
require .NoError (t , err )
130
130
131
131
// Check both pools are empty
132
132
lenDB , err := pool .LenDB ()
133
133
require .NoError (t , err )
134
- assert .Equal (t , uint16 (0 ), lenDB )
135
- assert .Equal (t , uint16 (0 ), pool .Len ())
134
+ require .Equal (t , uint16 (0 ), lenDB )
135
+ require .Equal (t , uint16 (0 ), pool .Len ())
136
136
137
137
// push multiple transactions to empty mempool (1,2,3)
138
138
for i := uint64 (1 ); i < 4 ; i ++ {
139
139
senderAddress := new (felt.Felt ).SetUint64 (i )
140
140
state .EXPECT ().ContractNonce (senderAddress ).Return (new (felt.Felt ).SetUint64 (0 ), nil )
141
- assert .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
141
+ require .NoError (t , pool .Push (& mempool.BroadcastedTransaction {
142
142
Transaction : & core.InvokeTransaction {
143
143
TransactionHash : new (felt.Felt ).SetUint64 (i ),
144
144
Version : new (core.TransactionVersion ).SetUint64 (1 ),
145
145
SenderAddress : senderAddress ,
146
146
Nonce : new (felt.Felt ).SetUint64 (0 ),
147
147
},
148
148
}))
149
- assert .Equal (t , uint16 (i ), pool .Len ())
149
+ require .Equal (t , uint16 (i ), pool .Len ())
150
150
}
151
151
152
152
// check the db has stored the transactions
153
- time .Sleep (100 * time .Millisecond )
153
+ time .Sleep (4000 * time .Millisecond )
154
154
lenDB , err = pool .LenDB ()
155
155
require .NoError (t , err )
156
- assert .Equal (t , uint16 (3 ), lenDB )
157
-
156
+ require .Equal (t , uint16 (3 ), lenDB )
158
157
// Close the mempool
159
158
require .NoError (t , closer ())
160
- testDB , dbCloser , err : = setupDatabase ("testrestoremempool" , false )
159
+ testDB , _ , err = setupDatabase ("testrestoremempool" , false )
161
160
require .NoError (t , err )
162
- defer dbCloser ()
163
161
164
162
poolRestored , closer2 , err := mempool .New (testDB , state , 1024 , log )
165
163
require .NoError (t , err )
166
164
lenDB , err = poolRestored .LenDB ()
167
165
require .NoError (t , err )
168
- assert .Equal (t , uint16 (3 ), lenDB )
169
- assert .Equal (t , uint16 (3 ), poolRestored .Len ())
166
+ require .Equal (t , uint16 (3 ), lenDB )
167
+ require .Equal (t , uint16 (3 ), poolRestored .Len ())
170
168
171
169
// Remove transactions
172
170
_ , err = poolRestored .Pop ()
@@ -175,15 +173,14 @@ func TestRestoreMempool(t *testing.T) {
175
173
require .NoError (t , err )
176
174
lenDB , err = poolRestored .LenDB ()
177
175
require .NoError (t , err )
178
- assert .Equal (t , uint16 (3 ), lenDB )
179
- assert .Equal (t , uint16 (1 ), poolRestored .Len ())
176
+ require .Equal (t , uint16 (3 ), lenDB )
177
+ require .Equal (t , uint16 (1 ), poolRestored .Len ())
180
178
181
179
require .NoError (t , closer2 ())
182
180
}
183
181
184
182
func TestWait (t * testing.T ) {
185
183
log := utils .NewNopZapLogger ()
186
-
187
184
testDB := pebble .NewMemTest (t )
188
185
mockCtrl := gomock .NewController (t )
189
186
t .Cleanup (mockCtrl .Finish )
0 commit comments