@@ -40,17 +40,19 @@ def peek(self, num=None):
40
40
41
41
def diff (self , txs ):
42
42
remove_hashes = [tx .hash for tx in txs ]
43
- keep = [tx for tx in self .txs if tx .hash not in remove_hashes ]
43
+ keep = [( prio , tx ) for ( prio , tx ) in self .txs if tx .hash not in remove_hashes ]
44
44
q = TransactionQueue ()
45
- for tx in keep :
46
- q .add_transaction (tx )
45
+ q .txs = keep
47
46
return q
48
47
49
- def test ():
48
+
49
+ def make_test_tx (s = 100000 , g = 50 , data = '' ):
50
50
from ethereum .transactions import Transaction
51
- def tx (s , g ):
52
- return Transaction (nonce = 0 , startgas = s , gasprice = g ,
53
- value = 0 , data = '' , to = '\x35 ' * 20 )
51
+ return Transaction (nonce = 0 , startgas = s , gasprice = g ,
52
+ value = 0 , data = data , to = '\x35 ' * 20 )
53
+
54
+
55
+ def test ():
54
56
q = TransactionQueue ()
55
57
# (startgas, gasprice) pairs
56
58
params = [(100000 , 81 ), (50000 , 74 ), (40000 , 65 ),
@@ -66,7 +68,7 @@ def tx(s, g):
66
68
(999999 , 50000 , 74 )]
67
69
# Add transactions to queue
68
70
for param in params :
69
- q .add_transaction (tx ( param [0 ], param [1 ]))
71
+ q .add_transaction (make_test_tx ( s = param [0 ], g = param [1 ]))
70
72
# Attempt pops from queue
71
73
for (maxgas , expected_s , expected_g ) in operations :
72
74
tx = q .pop_transaction (max_gas = maxgas )
@@ -75,3 +77,23 @@ def tx(s, g):
75
77
else :
76
78
assert expected_s is expected_g is None
77
79
print ('Test successful' )
80
+
81
+
82
+ def test_diff ():
83
+ tx1 = make_test_tx (data = 'foo' )
84
+ tx2 = make_test_tx (data = 'bar' )
85
+ tx3 = make_test_tx (data = 'baz' )
86
+ tx4 = make_test_tx (data = 'foobar' )
87
+ q1 = TransactionQueue ()
88
+ for tx in [tx1 , tx2 , tx3 , tx4 ]:
89
+ q1 .add_transaction (tx )
90
+ q2 = q1 .diff ([tx2 ])
91
+ assert len (q2 ) == 3
92
+ assert tx1 in [tx for (_ , tx ) in q2 .txs ]
93
+ assert tx3 in [tx for (_ , tx ) in q2 .txs ]
94
+ assert tx4 in [tx for (_ , tx ) in q2 .txs ]
95
+
96
+ q3 = q2 .diff ([tx4 ])
97
+ assert len (q3 ) == 2
98
+ assert tx1 in [tx for (_ , tx ) in q3 .txs ]
99
+ assert tx3 in [tx for (_ , tx ) in q3 .txs ]
0 commit comments