Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove duplicated ban test #29688

Merged
merged 1 commit into from Apr 23, 2024
Merged

Conversation

brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Mar 21, 2024

Test the ban list is preserved through restart has been done by both rpc_setban and p2p_disconnect_ban. Since p2p_disconnect_ban does it in a more elegant way, we can keep only it and remove the other one.

self.log.info("setban: test persistence across node restart")
# Set the mocktime so we can control when bans expire
old_time = int(time.time())
self.nodes[1].setmocktime(old_time)
self.nodes[1].setban("127.0.0.0/32", "add")
self.nodes[1].setban("127.0.0.0/24", "add")
self.nodes[1].setban("192.168.0.1", "add", 1) # ban for 1 seconds
self.nodes[1].setban("2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19", "add", 1000) # ban for 1000 seconds
listBeforeShutdown = self.nodes[1].listbanned()
assert_equal("192.168.0.1/32", listBeforeShutdown[2]['address'])
self.log.info("setban: test banning with absolute timestamp")
self.nodes[1].setban("192.168.0.2", "add", old_time + 120, True)
# Move time forward by 3 seconds so the third ban has expired
self.nodes[1].setmocktime(old_time + 3)
assert_equal(len(self.nodes[1].listbanned()), 4)
self.log.info("Test ban_duration and time_remaining")
for ban in self.nodes[1].listbanned():
if ban["address"] in ["127.0.0.0/32", "127.0.0.0/24"]:
assert_equal(ban["ban_duration"], 86400)
assert_equal(ban["time_remaining"], 86397)
elif ban["address"] == "2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19":
assert_equal(ban["ban_duration"], 1000)
assert_equal(ban["time_remaining"], 997)
elif ban["address"] == "192.168.0.2/32":
assert_equal(ban["ban_duration"], 120)
assert_equal(ban["time_remaining"], 117)
self.restart_node(1)
listAfterShutdown = self.nodes[1].listbanned()
assert_equal("127.0.0.0/24", listAfterShutdown[0]['address'])
assert_equal("127.0.0.0/32", listAfterShutdown[1]['address'])
assert_equal("192.168.0.2/32", listAfterShutdown[2]['address'])
assert_equal("/19" in listAfterShutdown[3]['address'], True)

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 21, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK tdb3, hernanmarino, BrandonOdiwuor, alfonsoromanz, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Copy link
Contributor

@tdb3 tdb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work taking a more holistic view of test coverage (avoiding duplicates).

Inline comments provided. In a nutshell, unless it's covered elsewhere (and I'm missing something), I would recommend keeping lines focused on testing banning/unbanning onion addresses. Looks like the removal of restarting/checking lines can be done while keeping onion address banning/unbanning/checking.

This would prevent the preceding lines from false advertising:

self.log.info("Test that a non-IP address can be banned/unbanned")
node = self.nodes[1]
tor_addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
ip_addr = "1.2.3.4"
assert not self.is_banned(node, tor_addr)
assert not self.is_banned(node, ip_addr)

test/functional/rpc_setban.py Outdated Show resolved Hide resolved
test/functional/rpc_setban.py Outdated Show resolved Hide resolved
@brunoerg
Copy link
Contributor Author

Thanks, @tdb3 for reviewing it. Just changed it to keep the ban/unban of an onion addresses and moved the test persistence across node restart to p2p_disconnect_ban.

Copy link
Contributor

@tdb3 tdb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled, built, and ran all unit and functional tests (all passed).
Updated comments for new commit 605b1a8.

test/functional/p2p_disconnect_ban.py Outdated Show resolved Hide resolved
test/functional/p2p_disconnect_ban.py Show resolved Hide resolved
test/functional/p2p_disconnect_ban.py Show resolved Hide resolved
@brunoerg
Copy link
Contributor Author

brunoerg commented Mar 25, 2024

Force-pushed addressing #29688 (comment) and #29688 (comment)

Copy link
Contributor

@tdb3 tdb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comment left for 7cdef4b.
Pulled and re-ran p2p_disconnect_ban (passed).

test/functional/p2p_disconnect_ban.py Show resolved Hide resolved
Test the ban list is preserved through restart has been
done by both `rpc_setban` and `p2p_disconnect_ban`.
Since `p2p_disconnect_ban` does it in a more elegant
way, we can keep only it and remove the duplicated one.
@brunoerg
Copy link
Contributor Author

Force-pushed addressing #29688 (comment)

Copy link
Contributor

@tdb3 tdb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK for e30e862.
Comments addressed. Pulled latest commit and ran p2p_disconnect_ban (v1 and v2 variants). Passed.

Copy link
Contributor

@hernanmarino hernanmarino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested ACK e30e862

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e30e862

Looks good to me

Copy link
Contributor

@alfonsoromanz alfonsoromanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e30e862

@achow101
Copy link
Member

It seems like these two tests primarily revolve around the setban RPC and do a couple of the same things, so perhaps they can be consolidated into one test?

@brunoerg
Copy link
Contributor Author

It seems like these two tests primarily revolve around the setban RPC and do a couple of the same things, so perhaps they can be consolidated into one test?

See #26863. Closed due to lack of interest.

@achow101
Copy link
Member

ACK e30e862

@achow101 achow101 merged commit 7c17f20 into bitcoin:master Apr 23, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants