Skip to content

Conversation

robot-dreams
Copy link
Contributor

@robot-dreams robot-dreams commented Sep 17, 2020

util.py defines global helper functions connect_nodes and disconnect_nodes; however, these functions are confusing because they take a node and an index (instead of two indexes).

The TestFramework object has enough context to convert from i to self.nodes[i], so we can replace all instances of connect_nodes(self.nodes[a], b) with self.connect_nodes(a, b). Similarly, we can replace instances of disconnect_nodes.

The approach taken in this PR builds on #19945 but uses a scripted-diff for the majority of the changes.

Fixes: #19821

@robot-dreams
Copy link
Contributor Author

Since many existing files contain an import that looks like this:

from test_framework.util import (
    assert_equal,
)

I think it makes more sense to address these in a separate PR (e.g. with a scripted-diff), instead of trying to manually fix the newly created ones in this PR.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

ACK 85fa2ec

I have reviewed it and it looks okay.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

ACK bef7f3b

Reviewed it and changes made in two files look okay.

@robot-dreams robot-dreams force-pushed the connect-nodes branch 2 times, most recently from ccfbc86 to 2f62edc Compare September 18, 2020 04:04
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 19, 2020

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

Conflicts

Reviewers, 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.

@amitiuttarwar
Copy link
Contributor

concept ACK!

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

ACK 2f62edc

This is much cleaner, thanks!

Copy link
Contributor

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Concept ACK 18e6ed0.

The scripted-diff script needs adjustment, see comment below.
I can confirm the code move in 18e6ed0 doesn't contain any change in its behavior. In fact the only diff is the logger.warning -> self.log.warning change.

@maflcko
Copy link
Member

maflcko commented Oct 19, 2020

@robot-dreams Are you still working on this?

robot-dreams and others added 3 commits October 20, 2020 00:27
A later scripted-diff commit replaces the majority of uses, which all
follow this pattern:

    (dis)?connect_nodes(self.nodes[a], b)

This commit replaces the few "special cases".
-BEGIN VERIFY SCRIPT-

 # max-depth=0 excludes test/functional/test_framework/...
 FILES=$(git grep -l --max-depth 0 "connect_nodes" test/functional)

 # Replace (dis)?connect_nodes(self.nodes[a], b) with self.(dis)?connect_nodes(a, b)
 sed -i 's/\b\(dis\)\?connect_nodes(self\.nodes\[\(.*\)\]/self.\1connect_nodes(\2/g' $FILES

 # Remove imports in the middle of a line
 sed -i 's/\(dis\)\?connect_nodes, //g' $FILES
 sed -i 's/, \(dis\)\?connect_nodes//g' $FILES

 # Remove imports on a line by themselves
 sed -i '/^\s*\(dis\)\?connect_nodes,\?$/d' $FILES
 sed -i '/^from test_framework\.util import connect_nodes$/d' $FILES

-END VERIFY SCRIPT-

Co-authored-by: Elliott Jin <elliott.jin@gmail.com>
Copy link
Contributor

@guggero guggero left a comment

Choose a reason for hiding this comment

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

ACK 3c7d9ab

@maflcko
Copy link
Member

maflcko commented Oct 21, 2020

ACK 3c7d9ab

@maflcko maflcko merged commit 47fc883 into bitcoin:master Oct 21, 2020
@robot-dreams robot-dreams deleted the connect-nodes branch October 21, 2020 12:51
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 21, 2020
…estFramework methods

3c7d9ab test: Move (dis)?connect_nodes globals into TestFramework as helpers (Elliott Jin)
4b16c61 scripted-diff: test: Replace uses of (dis)?connect_nodes global (Prayank)
be38684 test: Replace use of (dis)?connect_nodes globals (Elliott Jin)

Pull request description:

  `util.py` defines global helper functions `connect_nodes` and `disconnect_nodes`; however, these functions are confusing because they take a node and an index (instead of two indexes).

  The `TestFramework` object has enough context to convert from `i` to `self.nodes[i]`, so we can replace all instances of `connect_nodes(self.nodes[a], b)` with `self.connect_nodes(a, b)`. Similarly, we can replace instances of `disconnect_nodes`.

  The approach taken in this PR builds on bitcoin#19945 but uses a scripted-diff for the majority of the changes.

  Fixes: bitcoin#19821

ACKs for top commit:
  MarcoFalke:
    ACK 3c7d9ab
  guggero:
    ACK 3c7d9ab

Tree-SHA512: e027092748602904abcd986d7299624c8754c3236314b6d8e392e306741c212f266c2207e385adfb194f67ae6559a585ee7b15d639b1d65c4651dbf503e5931a
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 29, 2021
Summary:
This is a semi-automatic regex text replacement (excluding files in the `test_framework/` directory):
`(dis)?connect_nodes\(self\.nodes\[(\d)\], self\.nodes\[(\d)\]\)` `-->`  `self.$1connect_nodes($2, $3)`

This is a backport of [[bitcoin/bitcoin#19967 | core#19967]] [2/3]
bitcoin/bitcoin@4b16c61

Test Plan: `ninja check-functional-extended`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10559
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 29, 2021
Summary:
There is now only one callsite for these functions, so we can just move the code where it is needed.

I deviated from the original commit by not creating the `..._helper` functions. It doesn't make much sense to define local functions that are used only once and immediately after being defined.

This is a backport of [[bitcoin/bitcoin#19967 | core#19967]] [3/3]
bitcoin/bitcoin@3c7d9ab

Depends on D10558 and D10559

Test Plan: `ninja check-functional-extended`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10560
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: Remove confusing connect_nodes global
7 participants