Repository navigation
test: add functional test for anchors.dat - #21338
Conversation
|
Concept ACK I was thinking this should be a |
|
I added feature_anchors.py in BASE_SCRIPTS |
|
CI Tests are failing for two reasons so far:
|
|
Thanks, @jaonoctus. Fixed! |
|
Concept ACK. |
13762cd to
b1a5e04
Compare
There was a problem hiding this comment.
could make the path a named variable to avoid repeating the join three times?
There was a problem hiding this comment.
Yeah, no problem! thanks!
83b5836 to
5304652
Compare
There was a problem hiding this comment.
Approach ACK.
Tested 5304652 on Ubuntu 20.04.
The test has failed intermittently when run several times.
The reason is the file anchors.dat sometimes has 2 lines, as shown below.
A simple solution for this would be concatenate all line before the validations.
2021-03-02T19:52:13.969000Z TestFramework (INFO): Check the addresses in anchors.dat
item (first line): fabfb5da02fc5a030000e1f505000000000000000000000000000000000000ffff7f0000012b6efc5a030000e1f505000000000000000000000000000000000000ffff7f0000012b6d1c665ef1c1d383c4869170e021306a945bdbfb9f39c12bb2e0
ip_port: 7f0000012b6e
ip_port in item: True
ip_port: 7f0000012b6d
ip_port in item: True
item (second line): 279f548ecaf3
ip_port: 7f0000012b6e
ip_port in item: False
2021-03-02T19:52:13.969000Z TestFramework (ERROR): Assertion failed
|
@leonardojobim Amazing review! I'm working on it at this moment! Thank you! |
05a8912 to
a83908f
Compare
|
@leonardojobim fixed! could you please test it again? |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
leonardojobim
left a comment
There was a problem hiding this comment.
Tested ACK a83908f
The tests were run multiple times successfully.
jonatack
left a comment
There was a problem hiding this comment.
Concept ACK and some very light review, will review a bit more soon.
The file permission of the new test file should be 755 instead of 644.
-rwxr-xr-x 1 1685 Jan 21 20:54 test/functional/feature_abortnode.py*
-rw-r--r-- 1 2902 Mar 6 13:37 test/functional/feature_anchors.py
-rwxr-xr-x 1 4242 Mar 6 13:10 test/functional/feature_asmap.py*
In order to run the test, I had to first run:
sudo chmod 755 test/functional/feature_anchors.py
Nit: in terms of logging and function naming, I prefer "Test" to "Check that/if"
Don't hesitate to try running Python linters on your functional test changes like pycodestyle and black to see their suggestions.
41b10a0 to
9ef15a0
Compare
|
Thanks for the review @jonatack. Just pushed some fixes! |
There was a problem hiding this comment.
Hello Bruno. I think we should concatenate regtest sub directory using the os.path.join() function instead of using + "/regtest" (just to avoid assuming the test is running in a Unix based OS).
node0_anchors_path = os.path.join( self.nodes[0].datadir, "regtest", "anchors.dat" )
There was a problem hiding this comment.
Good point.
In general, don't hesitate to refer to test/functional/feature_asmap.py for an example of a similar kind of test file.
self.datadir = os.path.join(self.node.datadir, self.chain)
self.default_asmap = os.path.join(self.datadir, DEFAULT_ASMAP_FILENAME)
self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP)There was a problem hiding this comment.
Hello, Abel.. Thanks a lot for the review! Just changed it.
87f8dcc to
0605a3c
Compare
There was a problem hiding this comment.
Approach ACK.
Tested 0605a3c on Linux Mint 20.
I tried breaking the test without successing with the following:
- line 29: change range(2) for range(1)
Assertion in check_node_connections(node=self.nodes[0], num_in=5, num_out=2) fails (AssertionError: not(1 == 2)) - line 36: change range(5) for range(6)
Assertion in check_node_connections(node=self.nodes[0], num_in=5, num_out=2) fails as expected (AssertionError: not(6 == 5)) - Added a line to change expected ip address (ip = "7f000002") before line 73
Assertion that block_relay_nodes_port are included in anchors fail as expected - Added a line to change expected ip address (ip = "7f000002") before line 76
Assertion that inbound_nodes_port are not included in anchors still passes as expected - Commented out line 81 (self.start_node(0))
Assertion that anchors file does not exist fails as expected.
Executing the new test alone from command line works correctly (test/functional/feature_anchors.py).
Executing all functional tests with test/functional/test_runner.py includes new test:
187/202 - feature_anchors.py passed, Duration: 4 s
TEST | STATUS | DURATION
example_test.py | ✓ Passed | 11 s
feature_abortnode.py | ✓ Passed | 34 s
feature_anchors.py | ✓ Passed | 4 s
.
.
.
simsbluebox
left a comment
There was a problem hiding this comment.
ACK 0605a3c, I ran tests OK on Debian 10.8 (buster) and reviewed the code and it looks fine for me.
maflcko
left a comment
There was a problem hiding this comment.
Seems fine. Left two comments
There was a problem hiding this comment.
wouldn't it make more sense for this to be an array?
There was a problem hiding this comment.
I don't think so. I am concatenating the lines to verify if the addresses are into this. I don't think an array would be useful here.
There was a problem hiding this comment.
Let's assume ip_port is aa and anchors is ['fa', 'af']
With array:
>>> 'aa' in ['fa', 'af']
False
With string
>>> 'aa' in 'faaf'
True
Am I missing something?
There was a problem hiding this comment.
I'm using string for the reason you're showing with your example. I think the question about using array or string is: how is anchors.dat structured?
Let's suppose:
ip_port is 7f0000013e01 and the file content is:
fabfb5da02fc5a030000e1f505000000000000000000000000000000000000ffff7f0000013e01fc5a030000e1f505000000000000000000000000000000000000ffff7f0000013e0075f7d7cf33e71e42f8add50c305f091fb881b6fa5633932559d86cd9f6141260
but we have:
fabfb5da02fc5a030000e1f505000000000000000000000000000000000000ffff7f00 (breaks line)
00013e01fc5a030000e1f505000000000000000000000000000000000000ffff7f000 (breaks line)
0013e0075f7d7cf33e71e42f8add50c305f091fb881b6fa5633932559d86cd9f6141260 (breaks line)
in this case, my logic using string would be useful.
But how is the file structure for this case?
Anyway, almost 100% of my tests showed me that anchors.dat usually has just one line.
There was a problem hiding this comment.
anchors.dat is binary data, so why would newlines matter and what is the point of rstrip?
There was a problem hiding this comment.
I can remove rstrip I guess, it doesn't affect anything, thanks.
There was a problem hiding this comment.
So, can I read only the first line?
I was using array but the test `was failing, assuming:
item (first line): fabfb5da02fc5a030000e1f505000000000000000000000000000000000000ffff7f0000012b6efc5a030000e1f505000000000000000000000000000000000000ffff7f0000012b6d1c665ef1c1d383c4869170e021306a945bdbfb9f39c12bb2e0
ip_port: 7f0000012b6e
ip_port in item: True
ip_port: 7f0000012b6d
ip_port in item: True
item (second line): 279f548ecaf3
ip_port: 7f0000012b6e
ip_port in item: False`
There was a problem hiding this comment.
If newlines don't have a meaning, they shouldn't be interpreted. You can just use read()?
There was a problem hiding this comment.
Yes, just pushed the changes. It makes sense. Could you please check?
There was a problem hiding this comment.
I think this check can be skipped (will be checked by open already)
There was a problem hiding this comment.
Make sense.
When the file doesn't exit in the node directory the open function will return a FileNotFoundError.
Thanks!
99af51c to
c94f5da
Compare
832f6ad to
e05c42a
Compare
061cc28 to
581791c
Compare
|
Concept ACK 581791c |
| from test_framework.util import assert_equal | ||
|
|
||
|
|
||
| def check_node_connections(*, node, num_in, num_out): |
There was a problem hiding this comment.
This code is used once only. What are benefits of the separated function here?
| # Copyright (c) 2020 The Bitcoin Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| """Test Anchors functionality""" |
There was a problem hiding this comment.
nit:
| """Test Anchors functionality""" | |
| """Test block-relay-only anchors functionality""" |
| self.setup_nodes() | ||
|
|
||
| def run_test(self): | ||
| self.log.info("Add 2 block-relay-only connections to node 0") |
There was a problem hiding this comment.
nit: here and after s/"node 0"/"node"/ as it is the only node in this test.
|
|
||
| def run_test(self): | ||
| self.log.info("Add 2 block-relay-only connections to node 0") | ||
| for i in range(2): |
There was a problem hiding this comment.
nit: Numbers of connections, i.e., 2 and 5, could be named variables.
| self.start_node(0) | ||
|
|
||
| self.log.info("When node starts, check if anchors.dat doesn't exist anymore") | ||
| assert not os.path.exists(node0_anchors_path) |
There was a problem hiding this comment.
The same assertion seems reasonable to place in the test beginning too, no?
… for the first time ef99d03 test: check anchors.dat when node starts for the first time (bruno) Pull request description: See bitcoin/bitcoin#21338 (comment), bitcoin/bitcoin#21338 (comment), bitcoin/bitcoin#21338 (comment). ACKs for top commit: laanwj: Code review ACK ef99d03 Tree-SHA512: 505f1f34fbc0c72a92968883be0f1c5f169a4ba3aa8a56e1ce8bc5e514f49e3a17ce51fd40be0073dc4bc06eaeda36dfe90ace843c181170e34643226afd78ef
581791c test: add functional test for anchors.dat (bruno) Pull request description: This PR adds a functional test for anchors.dat. It creates a node and adds 2 outbound block-relay-only connections and 5 inbound connections. When the node is down, anchors.dat should contain the 2 addresses from the outbound block-relay-only connections. ACKs for top commit: MarcoFalke: Concept ACK 581791c hebasto: ACK 581791c Tree-SHA512: 77038b09e36ee5ae473a26d6f566c0ed283af258c34df8486706a24f72b05abab621a293ac886d03849bc45bc28be7336137252225b25aff393baa6b5238688c
… first time ef99d03 test: check anchors.dat when node starts for the first time (bruno) Pull request description: See bitcoin#21338 (comment), bitcoin#21338 (comment), bitcoin#21338 (comment). ACKs for top commit: laanwj: Code review ACK ef99d03 Tree-SHA512: 505f1f34fbc0c72a92968883be0f1c5f169a4ba3aa8a56e1ce8bc5e514f49e3a17ce51fd40be0073dc4bc06eaeda36dfe90ace843c181170e34643226afd78ef
Summary: ``` It creates a node and adds 2 outbound block-relay-only connections and 5 inbound connections. When the node is down, anchors.dat should contain the 2 addresses from the outbound block-relay-only connections. ``` Backport of [[bitcoin/bitcoin#21338 | core#21338]]. Ref T1696. Test Plan: ./test/functional/test_runner.py feature_anchors Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Maniphest Tasks: T1696 Differential Revision: https://reviews.bitcoinabc.org/D10959

This PR adds a functional test for anchors.dat.
It creates a node and adds 2 outbound block-relay-only connections and 5 inbound connections.
When the node is down, anchors.dat should contain the 2 addresses from the outbound block-relay-only connections.