forked from cheng/wallet
105 lines
4.3 KiB
C++
105 lines
4.3 KiB
C++
#include "stdafx.h"
|
|
//#include <wx/webview.h>
|
|
//#include <mbctype.h>
|
|
|
|
/* Any code here can be deleted at will without impact on the
|
|
functioning of the program.
|
|
|
|
This routine gets called during every unit test, and can log its results
|
|
to the log window. It should normally do absolutely nothing,
|
|
because useful working code should be moved the appropriate
|
|
files, and broken code should be thrown away
|
|
|
|
Anything here is a residue of forgotten experiments, and can safely
|
|
be thrown away. If any experiments have value, they will be
|
|
have been recorded in git. Nothing here is needed. If it was
|
|
needed, would have been moved.
|
|
|
|
Namespace testbed is only defined in this cpp file, hence nothing within
|
|
this namespace can be accessed from anywhere else.
|
|
except the routine testbed
|
|
|
|
If it needs to interact with the outside world, should post a message
|
|
analogously to queue_error_message, which then calls back to a
|
|
routine in this file.*/
|
|
void ascii2test();
|
|
extern const uint8_t* const ascii2six;
|
|
|
|
namespace testbed {
|
|
using ristretto255::hash, ristretto255::hsh, ristretto255::scalar,
|
|
ristretto255::point, ro::serialize, ro::bin2hex, ro::hex2bin,
|
|
ro::bin2hex, ro::fasthash, ro::CompileSizedString,
|
|
ro::base58, ro::has_machine_independent_representation,
|
|
ristretto255::extended_private_key,
|
|
ristretto255::extended_public_key;
|
|
static constexpr char SrcFilename[]{ "src/testbed.cpp" };
|
|
|
|
|
|
/* experimental code called during unit test
|
|
Anything here is a residue of forgotten experiments,
|
|
and can safely be thrown away
|
|
|
|
This is a playground, where you can do stuff without worrying you might
|
|
inadvertently break something that matters
|
|
|
|
Output goes to the unit test log.
|
|
|
|
No mechanism for input is available. You generally do not need it
|
|
because you hard code the testing data, and detect errors with
|
|
asserts, rather than exceptions but, of course, it can post a
|
|
dialog using postmessage, and the dialog can then call anything.
|
|
|
|
Uncaught exceptions result in unit test failure, and an error message
|
|
at the end of the unit test, but not in an error message in the
|
|
main program UI.
|
|
|
|
If using postmessage, execution of the code waits for the dialog to
|
|
return, data from the dialog can be used in the testbed code, and
|
|
uncaught exceptions in the dialog will result unit test failure
|
|
and be reported in the unit test log.
|
|
|
|
If using queumessage, the testbed code will complete while the dialog
|
|
is waiting, data cannot be returned for use in the testbed code,
|
|
and uncaught exceptions in the dialog queued will appear in the main UI.
|
|
*/
|
|
|
|
void testbed() {
|
|
hsh a_hsh=hsh().hashinto("the quick brown fox", "jumped over the lazy dog");
|
|
hash<256> a_hash = a_hsh;
|
|
// wxVersionInfo wx = wxWebView::GetBackendVersionInfo(wxASCII_STR(wxWebViewBackendDefault));
|
|
// wxLogMessage(wx.ToString());
|
|
// wx = wxWebView::GetBackendVersionInfo(wxASCII_STR(wxWebViewBackendEdge));
|
|
// wxLogMessage(wx.ToString());
|
|
// queue_error_message("hello world");
|
|
// throw MyException("hello world exception", __LINE__, __func__, SrcFilename);
|
|
ILogMessage("begin testbed");
|
|
/* auto text_secret{DeriveTextSecret(scalar(7), 1)};
|
|
if (text_secret == decltype(text_secret){"Rmc mLSu mDk DhfV 9gBK kKj"}) {
|
|
ILogMessage("\t\tObtained expected text secret from scalar(7)");
|
|
}
|
|
else {
|
|
errorCode = 18;
|
|
szError = "Fail\tUnexpected text secret from scalar(7)";
|
|
ILogError(szError.c_str());
|
|
}
|
|
auto start_time{ std::chrono::high_resolution_clock::now() };
|
|
extended_private_key s1(& text_secret[0]);
|
|
auto end_time{ std::chrono::high_resolution_clock::now() };
|
|
std::string str_s1{ &(base58(s1))[0] };
|
|
wxLogMessage("\t\textended private key: %s", str_s1);
|
|
const char * str_s2 = "jyRioJfob242toZDETkd7nG4YW6oYeGBEVEw4KLGWZaJfCPV2hQbT3AFUcnu6ZXEvDPPpSmM5ivMJ2awJxSBS5DoE";
|
|
if (str_s2 != str_s1) {
|
|
throw MyException("unexpected value of private key", __LINE__, __func__, SrcFilename);
|
|
}
|
|
auto s2 = base58<extended_private_key>::bin(str_s2);
|
|
if ( s1 != s2) {
|
|
throw MyException("Round trip for extended_private_key to and from base 58 representation failed", __LINE__, __func__, SrcFilename);
|
|
}
|
|
|
|
auto time_taken{ std::chrono::duration_cast<std::chrono::microseconds> (end_time - start_time) };
|
|
wxLogMessage("\t\tStrong secret derivation took %lld microseconds", time_taken.count());*/
|
|
|
|
ILogMessage("end testbed");
|
|
}
|
|
}
|