Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_feefilter.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2016-2019 The Bitcoin Core developers | # Copyright (c) 2016-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test processing of feefilter messages.""" | """Test processing of feefilter messages.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
import time | import time | ||||
from test_framework.messages import MSG_TX, msg_feefilter | from test_framework.messages import MSG_TX, msg_feefilter | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
mininode_lock, | p2p_lock, | ||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
def hashToHex(hash): | def hashToHex(hash): | ||||
return format(hash, '064x') | return format(hash, '064x') | ||||
# Wait up to 60 secs to see if the testnode has received all the expected invs | # Wait up to 60 secs to see if the testnode has received all the expected invs | ||||
def allInvsMatch(invsExpected, testnode): | def allInvsMatch(invsExpected, testnode): | ||||
for x in range(60): | for x in range(60): | ||||
with mininode_lock: | with p2p_lock: | ||||
if (sorted(invsExpected) == sorted(testnode.txinvs)): | if (sorted(invsExpected) == sorted(testnode.txinvs)): | ||||
return True | return True | ||||
time.sleep(1) | time.sleep(1) | ||||
return False | return False | ||||
class FeefilterConn(P2PInterface): | class FeefilterConn(P2PInterface): | ||||
feefilter_received = False | feefilter_received = False | ||||
def on_feefilter(self, message): | def on_feefilter(self, message): | ||||
self.feefilter_received = True | self.feefilter_received = True | ||||
def assert_feefilter_received(self, recv: bool): | def assert_feefilter_received(self, recv: bool): | ||||
with mininode_lock: | with p2p_lock: | ||||
assert_equal(self.feefilter_received, recv) | assert_equal(self.feefilter_received, recv) | ||||
class TestP2PConn(P2PInterface): | class TestP2PConn(P2PInterface): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.txinvs = [] | self.txinvs = [] | ||||
def on_inv(self, message): | def on_inv(self, message): | ||||
for i in message.inv: | for i in message.inv: | ||||
if (i.type == MSG_TX): | if (i.type == MSG_TX): | ||||
self.txinvs.append(hashToHex(i.hash)) | self.txinvs.append(hashToHex(i.hash)) | ||||
def clear_invs(self): | def clear_invs(self): | ||||
with mininode_lock: | with p2p_lock: | ||||
self.txinvs = [] | self.txinvs = [] | ||||
class FeeFilterTest(BitcoinTestFramework): | class FeeFilterTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
# We lower the various required feerates for this test | # We lower the various required feerates for this test | ||||
# to catch a corner-case where feefilter used to slightly undercut | # to catch a corner-case where feefilter used to slightly undercut | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |