From 23e95c16ba5a1716ef8ed55c434143d27847edf5 Mon Sep 17 00:00:00 2001 From: Cheng Date: Fri, 15 Sep 2023 19:44:26 +1000 Subject: [PATCH] moved a large array from stack to dynamic allocation, and fixed unit test to correctly handle the new database schema --- src/unit_test.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/unit_test.cpp b/src/unit_test.cpp index df7166b..69d85cb 100644 --- a/src/unit_test.cpp +++ b/src/unit_test.cpp @@ -187,7 +187,7 @@ static bool checkDataConversionsProduceExpected(void){ point pt_a{ scl_b.timesBase() }; std::string str_pt_a{ &(base58(pt_a))[0] }; if (pt_a != base58::bin(str_pt_a.c_str())){ - MyException("Round trip from and two base 58 representation failed"); + throw MyException("Round trip from and two base 58 representation failed"); } } { @@ -397,15 +397,11 @@ static bool OpenWallet(void) { sql_read_name read_name(db.get()); // db.reset(nullptr);// Force error of premature destruction of Isqlite3 while (read_keys.step() == Icompiled_sql::ROW) { - auto pubkey = read_keys.column(0); - auto id = read_keys.column(1); - auto use = read_keys.column(2); - if (use != 1){ - throw MyException(R"|(Unknown secret key algorithm index in "Names" table)|"); - } - if (!read_name(id)){ - throw MyException(R"|(No entry corresponding to public key in "Names" table)|"); - } + auto pubkey = read_keys.column(1); + auto id = read_keys.column(2); + auto use = read_keys.column(3); + if (use != 1)throw MyException(sz_unknown_secret_key_algorithm); + if (!read_name(id)) throw MyException(sz_no_corresponding_entry); const char* name = read_name.name(); if(MasterSecret(name).timesBase()!=*pubkey)throw MyException(R"|(Public key of name fails to correspond)|"); wxLogMessage(wxT("\t\t\"%s\" has expected public key 0x%s"), name, (wxString)(bin2hex(*pubkey))); @@ -923,18 +919,22 @@ static bool TestShareSecretGenerationSpeed(void) { } } } - uint8_t buff[hashes * 3 * 64]; - randombytes_buf(std::span(buff)); - start_time = std::chrono::high_resolution_clock::now(); - c = hash(buff); - end_time = std::chrono::high_resolution_clock::now(); - time_taken = std::chrono::duration_cast (end_time - start_time); - { bool f = false; //dont optimize pointless calculation away - for (auto x : c.blob) { f = f || x; } - if (f) { - wxLogMessage(_wx("\t\tone hash of %d bytes took %lld microseconds"), hashes * 3 * 64, time_taken.count()); + { + std::unique_ptr uBuff = std::make_unique(hashes * 3 * 64); + auto sBuff = std::span(uBuff.get(), hashes * 3 * 64); + randombytes_buf(sBuff); + start_time = std::chrono::high_resolution_clock::now(); + c = hash(sBuff); + end_time = std::chrono::high_resolution_clock::now(); + time_taken = std::chrono::duration_cast (end_time - start_time); + { bool f = false; //dont optimize pointless calculation away + for (auto x : c.blob) { f = f || x; } + if (f) { + wxLogMessage(_wx("\t\tone hash of %d bytes took %lld microseconds"), hashes * 3 * 64, time_taken.count()); + } } } + } } catch (const std::exception & e) {