Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-invalid-message.py
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/usr/bin/env python3 | |||||
# Copyright (c) 2019 The Bitcoin developers | |||||
# Distributed under the MIT software license, see the accompanying | |||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
"""ABC Invalid Message Test | |||||
Test that invalid messages get rejected and/or ban the sender as expected for | |||||
each case. | |||||
""" | |||||
import struct | |||||
from test_framework.mininode import ( | |||||
NetworkThread, | |||||
NodeConn, | |||||
NodeConnCB, | |||||
) | |||||
from test_framework.test_framework import BitcoinTestFramework | |||||
from test_framework.util import ( | |||||
p2p_port, | |||||
) | |||||
def msg_bad_checksum(connection): | |||||
command = b"badcommand" | |||||
data = b"" | |||||
tmsg = connection.MAGIC_BYTES[connection.network] | |||||
tmsg += command | |||||
tmsg += b"\x00" * (12 - len(command)) | |||||
tmsg += struct.pack("<I", len(data)) | |||||
#th = sha256(data) | |||||
#h = sha256(th) | |||||
#tmsg += h[:4] | |||||
tmsg += b"1234" | |||||
tmsg += data | |||||
return tmsg | |||||
class InvalidMessageTest(BitcoinTestFramework): | |||||
def set_test_params(self): | |||||
self.setup_clean_chain = False | |||||
self.num_nodes = 1 | |||||
def run_test(self): | |||||
# Create a P2P connection to one of the nodes | |||||
node0 = NodeConnCB() | |||||
connections = [] | |||||
connections.append( | |||||
NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0)) | |||||
node0.add_connection(connections[0]) | |||||
NetworkThread().start() | |||||
node0.wait_for_verack() | |||||
node0.send_raw_message(msg_bad_checksum(connections[0])) | |||||
node0.wait_for_disconnect() | |||||
if __name__ == '__main__': | |||||
InvalidMessageTest().main() |