aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-05-25 14:31:54 -0400
committerCarl Dong <contact@carldong.me>2022-06-02 11:40:03 -0400
commitfed085a1a4cd2787202752b6a0d98e42dce97f09 (patch)
treef5f85da84e9aee2a1e7fd6ac52edf70dfa90fcbd /src/test
parent7d03feef8156ef37a4efa01dc591467bc7d957bf (diff)
init: Initialize globals with kernel::Context's life
...instead of explicitly calling init::{Set,Unset}Globals. Cool thing about this is that in both the testing and bitcoin-chainstate codepaths, we no longer need to explicitly unset globals. The kernel::Context goes out of scope and the globals are unset "automatically". Also construct kernel::Context outside of AppInitSanityChecks()
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util/setup_common.cpp3
-rw-r--r--src/test/util/setup_common.h2
2 files changed, 2 insertions, 3 deletions
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 7b70ace759..61af5d4418 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -126,7 +126,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
InitLogging(*m_node.args);
AppInitParameterInteraction(*m_node.args);
LogInstance().StartLogging();
- init::SetGlobals();
+ m_node.kernel = std::make_unique<kernel::Context>();
SetupEnvironment();
SetupNetworking();
InitSignatureCache();
@@ -146,7 +146,6 @@ BasicTestingSetup::~BasicTestingSetup()
LogInstance().DisconnectTestLogger();
fs::remove_all(m_path_root);
gArgs.ClearArgs();
- init::UnsetGlobals();
}
ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index 3030271827..5c31cfc22b 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -81,7 +81,7 @@ static constexpr CAmount CENT{1000000};
* This just configures logging, data dir and chain parameters.
*/
struct BasicTestingSetup {
- node::NodeContext m_node;
+ node::NodeContext m_node; // keep as first member to be destructed last
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~BasicTestingSetup();