BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::string& fedpegscript) : m_path_root(fs::temp_directory_path() / "test_bitcoin" / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30)))) { SHA256AutoDetect(); RandomInit(); ECC_Start(); SetupEnvironment(); SetupNetworking(); InitSignatureCache(); InitScriptExecutionCache(); InitRangeproofCache(); InitSurjectionproofCache(); fCheckBlockIndex = true; // Hack to allow testing of fedpeg args if (!fedpegscript.empty()) { gArgs.SoftSetArg("-fedpegscript", fedpegscript); gArgs.SoftSetBoolArg("-con_has_parent_chain", true); gArgs.SoftSetBoolArg("-validatepegin", false); } // CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. // TODO: fix the code to support SegWit blocks. gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT)); SelectParams(chainName); // ELEMENTS: // Set policy asset for correct fee output generation policyAsset = CAsset(); noui_connect(); }
BasicTestingSetup::BasicTestingSetup() { ECC_Start(); SetupEnvironment(); fPrintToDebugLog = false; // don't want to write to debug.log file fCheckBlockIndex = true; SelectParams(CBaseChainParams::MAIN); }
int main(int argc, char **argv) { ECC_Start(); SetupEnvironment(); fPrintToDebugLog = false; // don't want to write to debug.log file benchmark::BenchRunner::RunAll(); ECC_Stop(); }
BasicTestingSetup::BasicTestingSetup(CBaseChainParams::Network network) { ECC_Start(); SetupEnvironment(); fPrintToDebugLog = false; // don't want to write to debug.log file fCheckBlockIndex = true; SelectParams(network); noui_connect(); }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName) { ECC_Start(); SetupEnvironment(); SetupNetworking(); fPrintToDebugLog = false; // don't want to write to debug.log file fCheckBlockIndex = true; SelectParams(chainName); noui_connect(); }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName) { assert(init_and_check_sodium() != -1); ECC_Start(); pzcashParams = ZCJoinSplit::Unopened(); SetupEnvironment(); SetupNetworking(); fPrintToDebugLog = false; // don't want to write to debug.log file fCheckBlockIndex = true; SelectParams(chainName); noui_connect(); }
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; }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName) { SHA256AutoDetect(); RandomInit(); ECC_Start(); SetupEnvironment(); SetupNetworking(); InitSignatureCache(); InitScriptExecutionCache(); fPrintToDebugLog = false; // don't want to write to debug.log file fCheckBlockIndex = true; SelectParams(chainName); noui_connect(); }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName) : m_path_root(fs::temp_directory_path() / "test_bitcoin" / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30)))) { SHA256AutoDetect(); RandomInit(); ECC_Start(); SetupEnvironment(); SetupNetworking(); InitSignatureCache(); InitScriptExecutionCache(); fCheckBlockIndex = true; SelectParams(chainName); noui_connect(); }
int main(int argc, char* argv[]) { #ifdef WIN32 util::WinCmdLineArgs winArgs; std::tie(argc, argv) = winArgs.get(); #endif SetupEnvironment(); RandomInit(); try { if (!WalletAppInit(argc, argv)) return EXIT_FAILURE; } catch (const std::exception& e) { PrintExceptionContinue(&e, "WalletAppInit()"); return EXIT_FAILURE; } catch (...) { PrintExceptionContinue(nullptr, "WalletAppInit()"); return EXIT_FAILURE; } std::string method {}; for(int i = 1; i < argc; ++i) { if (!IsSwitchChar(argv[i][0])) { if (!method.empty()) { fprintf(stderr, "Error: two methods provided (%s and %s). Only one method should be provided.\n", method.c_str(), argv[i]); return EXIT_FAILURE; } method = argv[i]; } } if (method.empty()) { fprintf(stderr, "No method provided. Run `bitcoin-wallet -help` for valid methods.\n"); return EXIT_FAILURE; } // A name must be provided when creating a file if (method == "create" && !gArgs.IsArgSet("-wallet")) { fprintf(stderr, "Wallet name must be provided when creating a new wallet.\n"); return EXIT_FAILURE; } std::string name = gArgs.GetArg("-wallet", ""); ECCVerifyHandle globalVerifyHandle; ECC_Start(); if (!WalletTool::ExecuteWalletToolFunc(method, name)) return EXIT_FAILURE; ECC_Stop(); return EXIT_SUCCESS; }
BasicTestingSetup::BasicTestingSetup(const std::string& chainName) : m_path_root(fs::temp_directory_path() / "test_bitcoin" / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30)))) { SHA256AutoDetect(); ECC_Start(); SetupEnvironment(); SetupNetworking(); InitSignatureCache(); InitScriptExecutionCache(); fCheckBlockIndex = true; // CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. // TODO: fix the code to support SegWit blocks. gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT)); SelectParams(chainName); noui_connect(); }
int main(int argc, char** argv) { ECC_Start(); ECCVerifyHandle verifyHandle; BLSInit(); SetupEnvironment(); fPrintToDebugLog = false; // don't want to write to debug.log file benchmark::BenchRunner::RunAll(); // need to be called before global destructors kick in (PoolAllocator is needed due to many BLSSecretKeys) CleanupBLSDkgTests(); CleanupBLSTests(); ECC_Stop(); }
// This is all you need to run all the tests int main(int argc, char *argv[]) { ECC_Start(); SetupEnvironment(); SetupNetworking(); SelectParams(CBaseChainParams::MAIN); noui_connect(); bool fInvalid = false; // Don't remove this, it's needed to access // QCoreApplication:: in the tests QCoreApplication app(argc, argv); app.setApplicationName("Dash-Qt-test"); SSL_library_init(); URITests test1; if (QTest::qExec(&test1) != 0) fInvalid = true; #ifdef ENABLE_WALLET PaymentServerTests test2; if (QTest::qExec(&test2) != 0) fInvalid = true; #endif RPCNestedTests test3; if (QTest::qExec(&test3) != 0) fInvalid = true; CompatTests test4; if (QTest::qExec(&test4) != 0) fInvalid = true; TrafficGraphDataTests test5; if (QTest::qExec(&test5) != 0) fInvalid = true; ECC_Stop(); return fInvalid; }
int main(int argc, char** argv) { SetupBenchArgs(); gArgs.ParseParameters(argc, argv); if (HelpRequested(gArgs)) { std::cout << gArgs.GetHelpMessage(); return 0; } 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 = boost::lexical_cast<double>(scaling_str); 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); ECC_Stop(); }
Secp256k1Init() { ECC_Start(); }
int main(int argc, char** argv) { struct event_base* base; struct evhttp* http; struct evhttp_bound_socket* handle; unsigned short port = 15520; if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) return (1); base = event_base_new(); if (!base) { fprintf(stderr, "Couldn't create an event_base: exiting\n"); return 1; } http = evhttp_new(base); evhttp_set_cb(http, "/led/blink", led_blink, NULL); handle = evhttp_bind_socket_with_handle(http, "0.0.0.0", port); //TODO: factor out thread std::thread cmdThread([&]() { //TODO, the locking is to broad at the moment // during executing a command the queue is locked // and therefore no new commands can be added // copy the command and callback and release the lock // would be a solution std::unique_lock<std::mutex> lock(cs_queue); while (!stopThread) { while (!notified) { // loop to avoid spurious wakeups queueCondVar.wait(lock); } while (!cmdQueue.empty()) { std::string cmdOut; t_cmdCB cmdCB = cmdQueue.front(); std::string cmd = std::get<0>(cmdCB); std::string password = std::get<1>(cmdCB); if (!password.empty()) { std::string base64str; std::string unencryptedJson; try { DBB::encryptAndEncodeCommand(cmd, password, base64str); if (!DBB::sendCommand(base64str, cmdOut)) unencryptedJson = "sending command failed"; else DBB::decryptAndDecodeCommand(cmdOut, password, unencryptedJson); } catch (const std::exception& ex) { unencryptedJson = "response decryption failed: "+cmdOut; } cmdOut = unencryptedJson; } else { DBB::sendCommand(cmd, cmdOut); } std::get<2>(cmdCB)(cmdOut); cmdQueue.pop(); } notified = false; } }); //create a thread for the http handling std::thread usbCheckThread([&]() { while(1) { //check devices if (!DBB::isConnectionOpen()) { if (DBB::openConnection()) { #ifdef DBB_ENABLE_QT //TODO, check if this requires locking if (widget) widget->deviceStateHasChanged(true); #endif } else { #ifdef DBB_ENABLE_QT if (widget) widget->deviceStateHasChanged(false); #endif } } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } }); ECC_Start(); #ifdef DBB_ENABLE_QT #if QT_VERSION > 0x050100 // Generate high-dpi pixmaps QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif //create a thread for the http handling std::thread httpThread([&]() { event_base_dispatch(base); }); QApplication app(argc, argv); widget = new DBBDaemonGui(0); widget->show(); app.exec(); #else //directly start libevents main run loop event_base_dispatch(base); #endif ECC_Stop(); exit(1); }
/** * This test covers methods on CWalletDB to load/save crypted z keys. */ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { ECC_Start(); SelectParams(CBaseChainParams::TESTNET); // Get temporary and unique path for file. // Note: / operator to append paths boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); bool fFirstRun; CWallet wallet("wallet_crypted.dat"); ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun)); // No default CPubKey set ASSERT_TRUE(fFirstRun); // wallet should be empty std::set<libzcash::PaymentAddress> addrs; wallet.GetPaymentAddresses(addrs); ASSERT_EQ(0, addrs.size()); // Add random key to the wallet auto paymentAddress = wallet.GenerateNewZKey(); // wallet should have one key wallet.GetPaymentAddresses(addrs); ASSERT_EQ(1, addrs.size()); // encrypt wallet SecureString strWalletPass; strWalletPass.reserve(100); strWalletPass = "******"; ASSERT_TRUE(wallet.EncryptWallet(strWalletPass)); // adding a new key will fail as the wallet is locked EXPECT_ANY_THROW(wallet.GenerateNewZKey()); // unlock wallet and then add wallet.Unlock(strWalletPass); auto paymentAddress2 = wallet.GenerateNewZKey(); // Create a new wallet from the existing wallet path CWallet wallet2("wallet_crypted.dat"); ASSERT_EQ(DB_LOAD_OK, wallet2.LoadWallet(fFirstRun)); // Confirm it's not the same as the other wallet ASSERT_TRUE(&wallet != &wallet2); // wallet should have two keys wallet2.GetPaymentAddresses(addrs); ASSERT_EQ(2, addrs.size()); // check we have entries for our payment addresses ASSERT_TRUE(addrs.count(paymentAddress.Get())); ASSERT_TRUE(addrs.count(paymentAddress2.Get())); // spending key is crypted, so we can't extract valid payment address libzcash::SpendingKey keyOut; wallet2.GetSpendingKey(paymentAddress.Get(), keyOut); ASSERT_FALSE(paymentAddress.Get() == keyOut.address()); // unlock wallet to get spending keys and verify payment addresses wallet2.Unlock(strWalletPass); wallet2.GetSpendingKey(paymentAddress.Get(), keyOut); ASSERT_EQ(paymentAddress.Get(), keyOut.address()); wallet2.GetSpendingKey(paymentAddress2.Get(), keyOut); ASSERT_EQ(paymentAddress2.Get(), keyOut.address()); }