@@ -3463,3 +3463,32 @@ async def send_from_node_3() -> None:
34633463 await time_out_assert (5 , lambda : full_node_2_ip in server_1 .banned_peers )
34643464 else :
34653465 await time_out_assert (5 , lambda : full_node_2_ip not in server_1 .banned_peers )
3466+
3467+
3468+ @pytest .mark .anyio
3469+ async def test_new_tx_zero_cost (
3470+ setup_two_nodes_fixture : tuple [list [FullNodeSimulator ], list [tuple [WalletNode , ChiaServer ]], BlockTools ],
3471+ self_hostname : str ,
3472+ ) -> None :
3473+ """
3474+ Tests that a peer gets banned if it sends a `NewTransaction` message with
3475+ zero cost.
3476+ """
3477+ [full_node_1 , full_node_2 ], _ , bt = setup_two_nodes_fixture
3478+ server_1 = full_node_1 .full_node .server
3479+ server_2 = full_node_2 .full_node .server
3480+ await server_2 .start_client (PeerInfo (self_hostname , server_1 .get_port ()), full_node_2 .full_node .on_connect )
3481+ ws_con_1 = next (iter (server_1 .all_connections .values ()))
3482+ ws_con_2 = next (iter (server_2 .all_connections .values ()))
3483+ await full_node_1 .full_node .add_block (bt .get_consecutive_blocks (1 )[0 ])
3484+ # Send a NewTransaction with zero cost
3485+ msg = make_msg (
3486+ ProtocolMessageTypes .new_transaction , NewTransaction (bytes32 .random (), cost = uint64 (0 ), fees = uint64 (42 ))
3487+ )
3488+ # We won't ban localhost, so let's set a different ip address for the
3489+ # second node.
3490+ full_node_2_ip = "1.3.3.7"
3491+ ws_con_1 .peer_info = PeerInfo (full_node_2_ip , ws_con_1 .peer_info .port )
3492+ await ws_con_2 .send_message (msg )
3493+ # Make sure the first full node has banned the second.
3494+ await time_out_assert (3 , lambda : full_node_2_ip in server_1 .banned_peers )
0 commit comments