Add a check to test that wallet load fails if we're on the wrong network.

This commit is contained in:
Kris Nuttycombe 2021-09-29 12:52:41 -06:00
parent 7132b27723
commit f9656e2637
1 changed files with 25 additions and 0 deletions

View File

@ -126,6 +126,31 @@ TEST(WalletTests, SetupDatadirLocationRunAsFirstTest) {
mapArgs["-datadir"] = pathTemp.string();
}
TEST(WalletTests, WalletNetworkSerialization) {
SelectParams(CBaseChainParams::TESTNET);
// Get temporary and unique path for file.
// Note: / operator to append paths
fs::path pathTemp = fs::temp_directory_path() / fs::unique_path();
fs::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string();
// create a new testnet wallet and generate a seed
CWallet wallet(Params(), "wallet.dat");
wallet.InitLoadWallet(Params(), true);
wallet.GenerateNewSeed();
wallet.Flush();
// now, switch to mainnet and attempt to restore the wallet
// using the same wallet.dat
SelectParams(CBaseChainParams::MAIN);
CWallet restored(Params(), "wallet.dat");
// load should fail due to being associated with the wrong network
bool fFirstRunRet;
EXPECT_NE(restored.LoadWallet(fFirstRunRet), DB_LOAD_OK);
}
TEST(WalletTests, SproutNoteDataSerialisation) {
auto sk = libzcash::SproutSpendingKey::random();
auto wtx = GetValidSproutReceive(sk, 10, true);