Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented May 28, 2020

Qt tests currently are currently using two NodeContext structs at the same time, one in interfaces::NodeImpl::m_context, and the other in BasicTestingSetup::m_node, and the tests have hacks transferring state between them.

Fix this by getting rid of the NodeImpl::m_context struct and making it a pointer. This way a common BitcoinApplication object can be used for all qt tests, but they can still have their own testing setups.

Non-test code is changing but non-test behavior is still the same as before.

Motivation for this PR is to be able to remove the "std::move(test.m_node.connman)" and mempool hacks for swapping individual NodeContext members in Qt tests, because followup PR #19099 adds yet another member (wallet_client) that needs to be swapped. After this change, the whole NodeContext struct can be swapped instead of individual members, so the workarounds are less fragile and invasive.

@@ -63,6 +64,7 @@ void AppTests::appTests()
#endif

BasicTestingSetup test{CBaseChainParams::REGTEST}; // Create a temp data directory to backup the gui settings to
Copy link
Member

Choose a reason for hiding this comment

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

Duplicate testing setups are illegal anyway. Have you seen fa5f7fa which is a massively smaller diff, potentially fixing the issue you ran into.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

Duplicate testing setups are illegal anyway. Have you seen fa5f7fa which is a massively smaller diff, potentially fixing the issue you ran into.

Acked other PR, and this PR overlaps a little bit with another part of it, but this PR is solving a different problem: not duplicate test setups but duplicate NodeContext (and WalletContext) instances inside a single test setup and confusion and fragility created by this. I added more motivation to PR description above.

Also, the diff isn't very big here, it's mostly just replacing . with ->

@DrahtBot
Copy link
Contributor

DrahtBot commented May 29, 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.

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 09569ff -> 8569817 (pr/qtx.1 -> pr/qtx.2, compare) with fix for address book asan error https://travis-ci.org/github/bitcoin/bitcoin/jobs/692330030#L4304
Updated 8569817 -> 934a8ae (pr/qtx.2 -> pr/qtx.3, compare) fixing pedantic asan null reference error https://travis-ci.org/github/bitcoin/bitcoin/jobs/692528901#L4294
Rebased 934a8ae -> d2c9cd7 (pr/qtx.3 -> pr/qtx.4, compare) due to conflict with #19176
Rebased d2c9cd7 -> ab1736c (pr/qtx.4 -> pr/qtx.5, compare) due to conflict with #19310

@@ -63,6 +64,7 @@ void AppTests::appTests()
#endif

BasicTestingSetup test{CBaseChainParams::REGTEST}; // Create a temp data directory to backup the gui settings to
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

Duplicate testing setups are illegal anyway. Have you seen fa5f7fa which is a massively smaller diff, potentially fixing the issue you ran into.

Acked other PR, and this PR overlaps a little bit with another part of it, but this PR is solving a different problem: not duplicate test setups but duplicate NodeContext (and WalletContext) instances inside a single test setup and confusion and fragility created by this. I added more motivation to PR description above.

Also, the diff isn't very big here, it's mostly just replacing . with ->

@tarboss
Copy link

tarboss commented May 30, 2020

good approach,
in wallettests.cpp the function TestGui() uses the codeline: "make CWallet()" to create the CWallet.
The chain parameter is from 1. Test (Apptests) in the current master branch, and not from Wallettest setup!!!!.

I tried this (dont wanna break whole top node interface):

test.m_node.chain = interfaces::MakeChain(test.m_node);
//node.context()->connman = std::move(test.m_node.connman);
//node.context()->mempool = std::move(test.m_node.mempool);
cwallet = std::make_shared(test.m_node.chain.get(), location L"", WalletDBmock)

btw: walletlocation is empty, but the wallettest run thru, even if u use QApplication app(argc, argv) & comment all other tests out.

@ryanofsky
Copy link
Contributor Author

re: tarboss #19098 (comment)

i tried this

It sounds like you tried this and got expected result, but let me know if I'm misunderstanding. Thanks for the feedback

@ryanofsky ryanofsky force-pushed the pr/qtx branch 3 times, most recently from fa522f9 to 12135dd Compare July 8, 2020 17:18
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Rebased ab1736c -> fa522f9 (pr/qtx.5 -> pr/qtx.6, compare) due to conflict with #19219
Updated fa522f9 -> 12135dd (pr/qtx.6 -> pr/qtx.7, compare) with suggested include fix
Rebased 12135dd -> 2dbdb43 (pr/qtx.7 -> pr/qtx.8, compare) due to conflict with #18923

Qt tests currently are currently using two NodeContext structs at the same
time, one in interfaces::NodeImpl::m_context, and the other in
BasicTestingSetup::m_node, and the tests have hacks transferring state between
them.

Fix this by getting rid of the NodeImpl::m_context struct and making it a
pointer. This way a common BitcoinApplication object can be used for all qt
tests, but they can still have their own testing setups.

Non-test code is changing but non-test behavior is still the same as before.

Motivation for this PR is to be able to remove the
"std::move(test.m_node.connman)" and mempool hacks for swapping individual
NodeContext members in Qt tests, because followup PR bitcoin#19099 adds yet another
member (wallet_client) that needs to be swapped. After this change, the whole
NodeContext struct can be swapped instead of individual members, so the
workarounds are less fragile and invasive.
@@ -10,6 +10,7 @@
#include <consensus/params.h>
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <interfaces/chain.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, sort 🙊 🏃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

nit, sort

Thanks, fixed

src/qt/bitcoin.h Outdated
@@ -90,6 +90,8 @@ class BitcoinApplication: public QApplication
/// Setup platform style
void setupPlatformStyle();

interfaces::Node& node() { return m_node; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Add only when needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

Add only when needed?

Thanks, removed here. It's added in bitcoin-core/gui#35

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Thanks for review! Updated with suggestions

Updated 2dbdb43 -> edc3160 (pr/qtx.8 -> pr/qtx.9, compare)

src/qt/bitcoin.h Outdated
@@ -90,6 +90,8 @@ class BitcoinApplication: public QApplication
/// Setup platform style
void setupPlatformStyle();

interfaces::Node& node() { return m_node; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

Add only when needed?

Thanks, removed here. It's added in bitcoin-core/gui#35

@@ -10,6 +10,7 @@
#include <consensus/params.h>
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <interfaces/chain.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #19098 (comment)

nit, sort

Thanks, fixed

@maflcko
Copy link
Member

maflcko commented Jul 31, 2020

crACK edc3160 🌮

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

crACK edc316020e8270dafc5e31465d532baebdafd3dd 🌮
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgNVQv/Rp1DWQ63V3hRrPG3/Uu713VE7nYlG/B4T37Jkj0PVR5vKFj0pkT45s9Y
3yDHFDhP+yTQjH5e+mCATQNs9+60D/1f6776O7CLIkiZ2Mh+K+g6Q807feo+AVTu
R7Ra56ZgXADrIvICWu7N7AOElNh/gwA+JHX13DcS4abLo13c+Xa9X5ILAB3L2uV+
Vv8LxivWpo/yF6pNifVsj6rMuvpNzjvKimYM2gu8zPKuXhRye+KqM6KkuFUgiY2B
TY/c0MGzhbxNTXhiCnYqfgNRT4s6ZO35W3CzReX72Y6g3LsjQ4sTp+pi67vkkP84
vo5OhC6XgFvX8/ZS66eyPmaOtkmxP7ehydr16NDosACfnnI7SDTGeSApICTyn00i
ynEE2kcXL/KY1wKhcGKq0J6mbXuzTPL5GGOJTkxyXeFdJCYe1PEPv0E1wvt0f7vR
AKeEjSlf7J3Wv4PT+1OdcrFVSZ19YC27z1mQ1q/UMNTZvwqLfMIm7rTcFpKjHESs
3zxlj4ev
=9d77
-----END PGP SIGNATURE-----

Timestamp of file with hash e4953628661a432a6114bf785c7dd10e546b98aee3b7f032fe9b6cd632fd6334 -

@maflcko maflcko closed this Jul 31, 2020
@maflcko maflcko reopened this Jul 31, 2020
@maflcko maflcko removed the GUI label Jul 31, 2020
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

ACK edc3160.

@maflcko maflcko merged commit 4b705b1 into bitcoin:master Aug 7, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 7, 2020
edc3160 test: Remove duplicate NodeContext hacks (Russell Yanofsky)

Pull request description:

  Qt tests currently are currently using two NodeContext structs at the same time, one in interfaces::NodeImpl::m_context, and the other in BasicTestingSetup::m_node, and the tests have hacks transferring state between them.

  Fix this by getting rid of the NodeImpl::m_context struct and making it a pointer. This way a common BitcoinApplication object can be used for all qt tests, but they can still have their own testing setups.

  Non-test code is changing but non-test behavior is still the same as before.

  Motivation for this PR is to be able to remove the "std::move(test.m_node.connman)" and mempool hacks for swapping individual NodeContext members in Qt tests, because followup PR bitcoin#19099 adds yet another member (wallet_client) that needs to be swapped. After this change, the whole NodeContext struct can be swapped instead of individual members, so the workarounds are less fragile and invasive.

ACKs for top commit:
  MarcoFalke:
    crACK edc3160 🌮
  promag:
    ACK edc3160.

Tree-SHA512: c1650e4127f43a4020304ca7c13b5d9122fb5723aacd8fa1cf855d03c6052fcfb7685810aa2a5ef708561015f0022fecaacbad479295104ca45d2c17579466a4
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 20, 2020
Summary:
```
Qt tests currently are currently using two NodeContext structs at the
same
time, one in interfaces::NodeImpl::m_context, and the other in
BasicTestingSetup::m_node, and the tests have hacks transferring state
between
them.

Fix this by getting rid of the NodeImpl::m_context struct and making it
a
pointer. This way a common BitcoinApplication object can be used for all
qt
tests, but they can still have their own testing setups.

Non-test code is changing but non-test behavior is still the same as
before.

Motivation for this PR is to be able to remove the
"std::move(test.m_node.connman)" and mempool hacks for swapping
individual
NodeContext members in Qt tests, because followup PR #19099 adds yet
another
member (wallet_client) that needs to be swapped. After this change, the
whole
NodeContext struct can be swapped instead of individual members, so the
workarounds are less fragile and invasive.
```

Backport of core [[bitcoin/bitcoin#19098 | PR19098]].

Depends on D7992.

Test Plan:
  ninja all check-all
  ./contrib/teamcity/build-configurations.py build-ubsan

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7993
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 8, 2020
These calls are no longer needed after edc3160
from bitcoin#19098 which started instantiating BasicTestingSetup.m_node.chain

Patch from MarcoFalke <falke.marco@gmail.com> in
bitcoin#19425 (comment)

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
@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.

5 participants