TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName) { SetDataDir("tempdir"); const CChainParams& chainparams = Params(); // Ideally we'd move all the RPC tests to the functional testing framework // instead of unit tests, but for now we need these here. RegisterAllCoreRPCCommands(tableRPC); ClearDatadirCache(); // We have to run a scheduler thread to prevent ActivateBestChain // from blocking due to queue overrun. threadGroup.create_thread(boost::bind(&CScheduler::serviceQueue, &scheduler)); GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); mempool.setSanityCheck(1.0); pblocktree.reset(new CBlockTreeDB(1 << 20, true)); pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true)); pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get())); if (!LoadGenesisBlock(chainparams)) { throw std::runtime_error("LoadGenesisBlock failed."); } { CValidationState state; if (!ActivateBestChain(state, chainparams)) { throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", FormatStateMessage(state))); } } nScriptCheckThreads = 3; for (int i=0; i < nScriptCheckThreads-1; i++) threadGroup.create_thread(&ThreadScriptCheck); g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests. connman = g_connman.get(); peerLogic.reset(new PeerLogicValidation(connman, scheduler, /*enable_bip61=*/true)); }
// Verify importwallet RPC starts rescan at earliest block with timestamp // greater or equal than key birthday. Previously there was a bug where // importwallet RPC would start the scan at the latest block with timestamp less // than or equal to key birthday. BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { auto chain = interfaces::MakeChain(); // Create two blocks with same timestamp to verify that importwallet rescan // will pick up both blocks, not just the first. const int64_t BLOCK_TIME = chainActive.Tip()->GetBlockTimeMax() + 5; SetMockTime(BLOCK_TIME); m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); // Set key birthday to block time increased by the timestamp window, so // rescan will start at the block time. const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW; SetMockTime(KEY_TIME); m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); auto locked_chain = chain->lock(); std::string backup_file = (SetDataDir("importwallet_rescan") / "wallet.backup").string(); // Import key into wallet and call dumpwallet to create backup file. { std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(*chain, WalletLocation(), WalletDatabase::CreateDummy()); LOCK(wallet->cs_wallet); wallet->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = KEY_TIME; wallet->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); JSONRPCRequest request; request.params.setArray(); request.params.push_back(backup_file); AddWallet(wallet); ::dumpwallet(request); RemoveWallet(wallet); } // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME // were scanned, and no prior blocks were scanned. { std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(*chain, WalletLocation(), WalletDatabase::CreateDummy()); JSONRPCRequest request; request.params.setArray(); request.params.push_back(backup_file); AddWallet(wallet); ::importwallet(request); RemoveWallet(wallet); LOCK(wallet->cs_wallet); BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U); BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetHash()); bool expected = i >= 100; BOOST_CHECK_EQUAL(found, expected); } } SetMockTime(0); }
static void init_args(int argc, char **argv) { int i; char *buf; i = 1; while (i < argc) { if (strncmp(argv[i], "-l", 2) == 0) { i++; if (i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetLocalDir(buf); free(buf); i++; } } else if (strncmp(argv[i], "-L", 2) == 0) { i++; if (i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetLibDir(buf); free(buf); i++; } } else if (strncmp(argv[i], "-D", 2) == 0) { i++; if (i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetDataDir(buf); free(buf); i++; } } else if (strncmp(argv[i], "-s", 2) == 0) { i++; SetSingleTextureMode (); #ifndef FREEGLUT } else if (strncmp(argv[i], "-m", 2) == 0) { i++; GfuiMouseSetHWPresent(); /* allow the hardware cursor */ #endif } else { i++; /* ignore bad args */ } } #ifdef FREEGLUT GfuiMouseSetHWPresent(); /* allow the hardware cursor (freeglut pb ?) */ #endif }
int main(int argc, char** argv) { SetupBenchArgs(); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str()); return EXIT_FAILURE; } if (HelpRequested(gArgs)) { std::cout << gArgs.GetHelpMessage(); return EXIT_SUCCESS; } // Set the datadir after parsing the bench options const fs::path bench_datadir{SetDataDir()}; SHA256AutoDetect(); RandomInit(); ECC_Start(); SetupEnvironment(); int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS); std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER); std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING); bool is_list_only = gArgs.GetBoolArg("-list", false); double scaling_factor; if (!ParseDouble(scaling_str, &scaling_factor)) { fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str()); return EXIT_FAILURE; } std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter()); std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER); if ("plot" == printer_arg) { printer.reset(new benchmark::PlotlyPrinter( gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL), gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); } benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only); fs::remove_all(bench_datadir); ECC_Stop(); return EXIT_SUCCESS; }
MyTextMaker::MyTextMaker() { m_theta = 0; SetDataDir("font3d/"); }
static void init_args(int argc, char **argv, const char **raceconfig) { int i; char *buf; i = 1; while(i < argc) { if(strncmp(argv[i], "-l", 2) == 0) { i++; if(i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetLocalDir(buf); free(buf); i++; } } else if(strncmp(argv[i], "-L", 2) == 0) { i++; if(i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetLibDir(buf); free(buf); i++; } } else if(strncmp(argv[i], "-D", 2) == 0) { i++; if(i < argc) { buf = (char *)malloc(strlen(argv[i]) + 2); sprintf(buf, "%s/", argv[i]); SetDataDir(buf); free(buf); i++; } } else if(strncmp(argv[i], "-s", 2) == 0) { i++; SetSingleTextureMode(); } else if(strncmp(argv[i], "-k", 2) == 0) { i++; // Keep modules in memory (for valgrind) printf("Unloading modules disabled, just intended for valgrind runs.\n"); bKeepModules = true; #ifndef FREEGLUT } else if(strncmp(argv[i], "-m", 2) == 0) { i++; GfuiMouseSetHWPresent(); /* allow the hardware cursor */ #endif } else if(strncmp(argv[i], "-r", 2) == 0) { i++; *raceconfig = ""; if(i < argc) { *raceconfig = argv[i]; i++; } if((strlen(*raceconfig) == 0) || (strstr(*raceconfig, ".xml") == 0)) { printf("Please specify a race configuration xml when using -r\n"); exit(1); } } else { i++; /* ignore bad args */ } } #ifdef FREEGLUT GfuiMouseSetHWPresent(); /* allow the hardware cursor (freeglut pb ?) */ #endif }