Merge #16839: Replace Connman and BanMan globals with NodeContext local
362ded410bAvoid using g_rpc_node global in wallet code (Russell Yanofsky)8922d7f6b7scripted-diff: Remove g_connman, g_banman globals (Russell Yanofsky)e6f4f895d5Pass NodeContext, ConnMan, BanMan references more places (Russell Yanofsky)4d5448c76bMOVEONLY: Move NodeContext struct to node/context.h (Russell Yanofsky)301bd41a2escripted-diff: Rename InitInterfaces to NodeContext (Russell Yanofsky) Pull request description: This change is mainly a naming / organization change intended to simplify #10102. It: - Renames struct InitInterfaces to struct NodeContext and moves it from src/init.h to src/node/context.h. This is a cosmetic change intended to make the point of the struct more obvious. - Gets rid of BanMan and ConnMan globals making them NodeContext members instead. Getting rid of these globals has been talked about in past as a way to implement testing and simulations. Making them NodeContext members is a way of keeping them accessible without the globals. - Splits g_rpc_interfaces global into g_rpc_node and g_rpc_chain globals. This better separates node and wallet rpc methods. Node RPC methods should have access NodeContext, while wallet RPC methods should only have indirect access to node functionality via interfaces::Chain. - Adds NodeContext& references to interfaces::Chain class and the interfaces::MakeChain() function. This is needed to access ConnMan and BanMan instances without the globals. - Gets rid of redundant Node and Chain instances in Qt tests. This is needed due to the previous MakeChain change, and also makes test setup a little more straightforward. More cleanup could be done in the future, but it will require deduplication of bitcoind, bitcoin-qt, and TestingSetup init code. ACKs for top commit: laanwj: ACK362ded410bTree-SHA512: 9ae6ff1e33423291d1e52056bac95e0874538390892a6e83c4c115b3c73155a8827c0191b46eb3d14e3b3f6c23ccb08095490880fbc3188026319c71739f7db2
This commit is contained in:
45 files changed
+336
-211
No files matched your search
@@ -51,11 +51,10 @@ void EditAddressAndSubmit(
|
||||
* In each case, verify the resulting state of the address book and optionally
|
||||
* the warning message presented to the user.
|
||||
*/
|
||||
void TestAddAddressesToSendBook()
|
||||
void TestAddAddressesToSendBook(interfaces::Node& node)
|
||||
{
|
||||
TestChain100Setup test;
|
||||
auto chain = interfaces::MakeChain();
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
|
||||
@@ -101,10 +100,9 @@ void TestAddAddressesToSendBook()
|
||||
|
||||
// Initialize relevant QT models.
|
||||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||
auto node = interfaces::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
OptionsModel optionsModel(node);
|
||||
AddWallet(wallet);
|
||||
WalletModel walletModel(std::move(node->getWallets()[0]), *node, platformStyle.get(), &optionsModel);
|
||||
WalletModel walletModel(interfaces::MakeWallet(wallet), node, platformStyle.get(), &optionsModel);
|
||||
RemoveWallet(wallet);
|
||||
EditAddressDialog editAddressDialog(EditAddressDialog::NewSendingAddress);
|
||||
editAddressDialog.setModel(walletModel.getAddressTableModel());
|
||||
@@ -150,5 +148,5 @@ void AddressBookTests::addressBookTests()
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
TestAddAddressesToSendBook();
|
||||
TestAddAddressesToSendBook(m_node);
|
||||
}
|
||||
@@ -4,8 +4,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class AddressBookTests : public QObject
|
||||
{
|
||||
public:
|
||||
AddressBookTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
@@ -41,7 +41,7 @@ void RPCNestedTests::rpcNestedTests()
|
||||
std::string result;
|
||||
std::string result2;
|
||||
std::string filtered;
|
||||
auto node = interfaces::MakeNode();
|
||||
interfaces::Node* node = &m_node;
|
||||
RPCConsole::RPCExecuteCommandLine(*node, result, "getblockchaininfo()[chain]", &filtered); //simple result filtering with path
|
||||
QVERIFY(result=="main");
|
||||
QVERIFY(filtered == "getblockchaininfo()[chain]");
|
||||
|
||||
@@ -8,8 +8,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class RPCNestedTests : public QObject
|
||||
{
|
||||
public:
|
||||
RPCNestedTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
|
||||
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
|
||||
}
|
||||
|
||||
auto node = interfaces::MakeNode();
|
||||
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode();
|
||||
|
||||
bool fInvalid = false;
|
||||
|
||||
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
|
||||
if (QTest::qExec(&test1) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
RPCNestedTests test3;
|
||||
RPCNestedTests test3(*node);
|
||||
if (QTest::qExec(&test3) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
@@ -85,11 +85,11 @@ int main(int argc, char *argv[])
|
||||
fInvalid = true;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
WalletTests test5;
|
||||
WalletTests test5(*node);
|
||||
if (QTest::qExec(&test5) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
AddressBookTests test6;
|
||||
AddressBookTests test6(*node);
|
||||
if (QTest::qExec(&test6) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
|
||||
@@ -126,15 +126,15 @@ void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, st
|
||||
// QT_QPA_PLATFORM=xcb src/qt/test/test_bitcoin-qt # Linux
|
||||
// QT_QPA_PLATFORM=windows src/qt/test/test_bitcoin-qt # Windows
|
||||
// QT_QPA_PLATFORM=cocoa src/qt/test/test_bitcoin-qt # macOS
|
||||
void TestGUI()
|
||||
void TestGUI(interfaces::Node& node)
|
||||
{
|
||||
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
|
||||
TestChain100Setup test;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
||||
}
|
||||
auto chain = interfaces::MakeChain();
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||
node.context()->connman = std::move(test.m_node.connman);
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), WalletDatabase::CreateMock());
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
{
|
||||
@@ -161,10 +161,9 @@ void TestGUI()
|
||||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||
SendCoinsDialog sendCoinsDialog(platformStyle.get());
|
||||
TransactionView transactionView(platformStyle.get());
|
||||
auto node = interfaces::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
OptionsModel optionsModel(node);
|
||||
AddWallet(wallet);
|
||||
WalletModel walletModel(std::move(node->getWallets().back()), *node, platformStyle.get(), &optionsModel);
|
||||
WalletModel walletModel(interfaces::MakeWallet(wallet), node, platformStyle.get(), &optionsModel);
|
||||
RemoveWallet(wallet);
|
||||
sendCoinsDialog.setModel(&walletModel);
|
||||
transactionView.setModel(&walletModel);
|
||||
@@ -262,5 +261,5 @@ void WalletTests::walletTests()
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
TestGUI();
|
||||
TestGUI(m_node);
|
||||
}
|
||||
@@ -4,8 +4,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class WalletTests : public QObject
|
||||
{
|
||||
public:
|
||||
WalletTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
Reference in new issue
Block a user