1
0
forked from cheng/wallet

moved a large array from stack to dynamic allocation, and fixed unit

test to correctly handle the new database schema
This commit is contained in:
Cheng 2023-09-15 19:44:26 +10:00
parent 408942a336
commit 23e95c16ba
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA

View File

@ -187,7 +187,7 @@ static bool checkDataConversionsProduceExpected(void){
point pt_a{ scl_b.timesBase() }; point pt_a{ scl_b.timesBase() };
std::string str_pt_a{ &(base58(pt_a))[0] }; std::string str_pt_a{ &(base58(pt_a))[0] };
if (pt_a != base58<point>::bin(str_pt_a.c_str())){ if (pt_a != base58<point>::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()); sql_read_name read_name(db.get());
// db.reset(nullptr);// Force error of premature destruction of Isqlite3 // db.reset(nullptr);// Force error of premature destruction of Isqlite3
while (read_keys.step() == Icompiled_sql::ROW) { while (read_keys.step() == Icompiled_sql::ROW) {
auto pubkey = read_keys.column<ristretto255::point>(0); auto pubkey = read_keys.column<ristretto255::point>(1);
auto id = read_keys.column<int>(1); auto id = read_keys.column<int>(2);
auto use = read_keys.column<int>(2); auto use = read_keys.column<int>(3);
if (use != 1){ if (use != 1)throw MyException(sz_unknown_secret_key_algorithm);
throw MyException(R"|(Unknown secret key algorithm index in "Names" table)|"); if (!read_name(id)) throw MyException(sz_no_corresponding_entry);
}
if (!read_name(id)){
throw MyException(R"|(No entry corresponding to public key in "Names" table)|");
}
const char* name = read_name.name(); const char* name = read_name.name();
if(MasterSecret(name).timesBase()!=*pubkey)throw MyException(R"|(Public key of name fails to correspond)|"); 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))); 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<byte>(buff)); std::unique_ptr<uint8_t[]> uBuff = std::make_unique<uint8_t[]>(hashes * 3 * 64);
start_time = std::chrono::high_resolution_clock::now(); auto sBuff = std::span<uint8_t>(uBuff.get(), hashes * 3 * 64);
c = hash(buff); randombytes_buf(sBuff);
end_time = std::chrono::high_resolution_clock::now(); start_time = std::chrono::high_resolution_clock::now();
time_taken = std::chrono::duration_cast<std::chrono::microseconds> (end_time - start_time); c = hash(sBuff);
{ bool f = false; //dont optimize pointless calculation away end_time = std::chrono::high_resolution_clock::now();
for (auto x : c.blob) { f = f || x; } time_taken = std::chrono::duration_cast<std::chrono::microseconds> (end_time - start_time);
if (f) { { bool f = false; //dont optimize pointless calculation away
wxLogMessage(_wx("\t\tone hash of %d bytes took %lld microseconds"), hashes * 3 * 64, time_taken.count()); 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) { catch (const std::exception & e) {