12
12
using Nethermind . TxPool ;
13
13
using NSubstitute ;
14
14
using NUnit . Framework ;
15
+ using System . Runtime . InteropServices ;
16
+ using Nethermind . Core . Collections ;
17
+ using Nethermind . Core . Extensions ;
15
18
16
19
namespace Nethermind . Network . Test . P2P . Subprotocols . Eth . V65
17
20
{
@@ -20,74 +23,79 @@ public class PooledTxsRequestorTests
20
23
private readonly ITxPool _txPool = Substitute . For < ITxPool > ( ) ;
21
24
private readonly Action < GetPooledTransactionsMessage > _doNothing = static msg => msg . Dispose ( ) ;
22
25
private IPooledTxsRequestor _requestor ;
23
- private IReadOnlyList < Hash256 > _request ;
24
- private IList < Hash256 > _expected ;
25
- private IReadOnlyList < Hash256 > _response ;
26
+ private ArrayPoolList < Hash256 > _response ;
26
27
28
+ [ TearDown ]
29
+ public void TearDown ( )
30
+ {
31
+ _response ? . Dispose ( ) ;
32
+ }
27
33
28
34
[ Test ]
29
35
public void filter_properly_newPooledTxHashes ( )
30
36
{
31
- _response = new List < Hash256 > ( ) ;
32
37
_requestor = new PooledTxsRequestor ( _txPool , new TxPoolConfig ( ) ) ;
33
- _requestor . RequestTransactions ( _doNothing , new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakD } ) ;
38
+ using var skipped = new ArrayPoolList < Hash256 > ( 2 ) { TestItem . KeccakA , TestItem . KeccakD } ;
39
+ _requestor . RequestTransactions ( _doNothing , skipped ) ;
34
40
35
- _request = new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
36
- _expected = new List < Hash256 > { TestItem . KeccakB , TestItem . KeccakC } ;
37
- _requestor . RequestTransactions ( Send , _request ) ;
38
- _response . Should ( ) . BeEquivalentTo ( _expected ) ;
41
+ using var request = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
42
+ using var expected = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakB , TestItem . KeccakC } ;
43
+ _requestor . RequestTransactions ( Send , request ) ;
44
+ _response . Should ( ) . BeEquivalentTo ( expected ) ;
39
45
}
40
46
41
47
[ Test ]
42
48
public void filter_properly_already_pending_hashes ( )
43
49
{
44
- _response = new List < Hash256 > ( ) ;
45
50
_requestor = new PooledTxsRequestor ( _txPool , new TxPoolConfig ( ) ) ;
46
- _requestor . RequestTransactions ( _doNothing , new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ) ;
51
+ using var skipped = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
52
+ _requestor . RequestTransactions ( _doNothing , skipped ) ;
47
53
48
- _request = new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
49
- _requestor . RequestTransactions ( Send , _request ) ;
54
+ using var request = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
55
+ _requestor . RequestTransactions ( Send , request ) ;
50
56
_response . Should ( ) . BeEmpty ( ) ;
51
57
}
52
58
53
59
[ Test ]
54
60
public void filter_properly_discovered_hashes ( )
55
61
{
56
- _response = new List < Hash256 > ( ) ;
57
62
_requestor = new PooledTxsRequestor ( _txPool , new TxPoolConfig ( ) ) ;
58
63
59
- _request = new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
60
- _expected = new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
61
- _requestor . RequestTransactions ( Send , _request ) ;
62
- _response . Should ( ) . BeEquivalentTo ( _expected ) ;
64
+ using var request = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
65
+ using var expected = new ArrayPoolList < Hash256 > ( 3 ) { TestItem . KeccakA , TestItem . KeccakB , TestItem . KeccakC } ;
66
+ _requestor . RequestTransactions ( Send , request ) ;
67
+ _response . Should ( ) . BeEquivalentTo ( expected ) ;
63
68
}
64
69
65
70
[ Test ]
66
71
public void can_handle_empty_argument ( )
67
72
{
68
- _response = new List < Hash256 > ( ) ;
69
73
_requestor = new PooledTxsRequestor ( _txPool , new TxPoolConfig ( ) ) ;
70
- _requestor . RequestTransactions ( Send , new List < Hash256 > ( ) ) ;
74
+ using var skipped = new ArrayPoolList < Hash256 > ( 0 ) ;
75
+ _requestor . RequestTransactions ( Send , skipped ) ;
71
76
_response . Should ( ) . BeEmpty ( ) ;
72
77
}
73
78
74
79
[ Test ]
75
80
public void filter_properly_hashes_present_in_hashCache ( )
76
81
{
77
- _response = new List < Hash256 > ( ) ;
78
82
ITxPool txPool = Substitute . For < ITxPool > ( ) ;
79
83
txPool . IsKnown ( Arg . Any < Hash256 > ( ) ) . Returns ( true ) ;
80
84
_requestor = new PooledTxsRequestor ( txPool , new TxPoolConfig ( ) ) ;
81
85
82
- _request = new List < Hash256 > { TestItem . KeccakA , TestItem . KeccakB } ;
83
- _expected = new List < Hash256 > { } ;
84
- _requestor . RequestTransactions ( Send , _request ) ;
85
- _response . Should ( ) . BeEquivalentTo ( _expected ) ;
86
+ using var request = new ArrayPoolList < Hash256 > ( 2 ) { TestItem . KeccakA , TestItem . KeccakB } ;
87
+ using var expected = new ArrayPoolList < Hash256 > ( 0 ) { } ;
88
+ _requestor . RequestTransactions ( Send , request ) ;
89
+ _response . Should ( ) . BeEquivalentTo ( expected ) ;
86
90
}
87
91
88
92
private void Send ( GetPooledTransactionsMessage msg )
89
93
{
90
- using ( msg ) _response = msg . Hashes . ToList ( ) ;
94
+ _response ? . Dispose ( ) ;
95
+ using ( msg )
96
+ {
97
+ _response = msg . Hashes . ToPooledList ( ) ;
98
+ }
91
99
}
92
100
}
93
101
}
0 commit comments