2 # Copyright (c) 2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test processing of feefilter messages."""
7 from test_framework
.mininode
import *
8 from test_framework
.test_framework
import BitcoinTestFramework
9 from test_framework
.util
import *
14 return format(hash, '064x')
16 # Wait up to 60 secs to see if the testnode has received all the expected invs
17 def allInvsMatch(invsExpected
, testnode
):
20 if (sorted(invsExpected
) == sorted(testnode
.txinvs
)):
25 class TestNode(NodeConnCB
):
30 def on_inv(self
, conn
, message
):
33 self
.txinvs
.append(hashToHex(i
.hash))
39 class FeeFilterTest(BitcoinTestFramework
):
44 self
.setup_clean_chain
= False
51 sync_blocks(self
.nodes
)
53 # Setup the p2p connections and start up the network thread.
54 test_node
= TestNode()
55 connection
= NodeConn('127.0.0.1', p2p_port(0), self
.nodes
[0], test_node
)
56 test_node
.add_connection(connection
)
57 NetworkThread().start()
58 test_node
.wait_for_verack()
60 # Test that invs are received for all txs at feerate of 20 sat/byte
61 node1
.settxfee(Decimal("0.00020000"))
62 txids
= [node1
.sendtoaddress(node1
.getnewaddress(), 1) for x
in range(3)]
63 assert(allInvsMatch(txids
, test_node
))
64 test_node
.clear_invs()
66 # Set a filter of 15 sat/byte
67 test_node
.send_and_ping(msg_feefilter(15000))
69 # Test that txs are still being received (paying 20 sat/byte)
70 txids
= [node1
.sendtoaddress(node1
.getnewaddress(), 1) for x
in range(3)]
71 assert(allInvsMatch(txids
, test_node
))
72 test_node
.clear_invs()
74 # Change tx fee rate to 10 sat/byte and test they are no longer received
75 node1
.settxfee(Decimal("0.00010000"))
76 [node1
.sendtoaddress(node1
.getnewaddress(), 1) for x
in range(3)]
77 sync_mempools(self
.nodes
) # must be sure node 0 has received all txs
79 # Send one transaction from node0 that should be received, so that we
80 # we can sync the test on receipt (if node1's txs were relayed, they'd
81 # be received by the time this node0 tx is received). This is
82 # unfortunately reliant on the current relay behavior where we batch up
83 # to 35 entries in an inv, which means that when this next transaction
84 # is eligible for relay, the prior transactions from node1 are eligible
86 node0
.settxfee(Decimal("0.00020000"))
87 txids
= [node0
.sendtoaddress(node0
.getnewaddress(), 1)]
88 assert(allInvsMatch(txids
, test_node
))
89 test_node
.clear_invs()
91 # Remove fee filter and check that txs are received again
92 test_node
.send_and_ping(msg_feefilter(0))
93 txids
= [node1
.sendtoaddress(node1
.getnewaddress(), 1) for x
in range(3)]
94 assert(allInvsMatch(txids
, test_node
))
95 test_node
.clear_invs()
97 if __name__
== '__main__':
98 FeeFilterTest().main()