a few more serial bridge index integrations and tests

pull/29/head
Paul Shapiro 6 years ago
parent 6c19abf379
commit e74c266b7e

@ -35,6 +35,8 @@ using namespace address_utils;
//
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "string_tools.h"
#include "cryptonote_basic/account.h"
using namespace cryptonote;
//
#include "tools__ret_vals.hpp"
using namespace epee;
@ -107,7 +109,6 @@ optional<string> address_utils::new_integratedAddrFromStdAddr(const string &std_
}
if (info.is_subaddress) {
BOOST_THROW_EXCEPTION(runtime_error("new_integratedAddrFromStdAddr must not be called with a subaddress"));
//
return none;
}
if (info.has_payment_id != false) {
@ -121,3 +122,14 @@ optional<string> address_utils::new_integratedAddrFromStdAddr(const string &std_
);
return int_address_string;
}
account_public_address address_utils::new_fake_address_for_rct_tx()
{
cryptonote::account_base dummy;
dummy.generate();
//
return dummy.get_keys().m_account_address;
}
string address_utils::new_fake_address_string_for_rct_tx(network_type nettype)
{
return get_account_address_as_str(nettype, false/*subaddress*/, new_fake_address_for_rct_tx());
}

@ -31,30 +31,35 @@
//
#include <string>
#include <boost/optional.hpp>
using namespace std;
using namespace boost;
//
#include "cryptonote_config.h"
#include "cryptonote_basic/account.h"
#include "tools__ret_vals.hpp"
//
namespace monero
{
namespace address_utils
{
using namespace std;
using namespace boost;
using namespace cryptonote;
struct DecodedAddress_RetVals: tools::RetVals_base
{ // TODO: inherit from tools__ret_vals
{
optional<string> pub_viewKey_string;
optional<string> pub_spendKey_string;
bool isSubaddress;
optional<string> paymentID_string;
};
//
// TODO: migrate these methods to use nettype
//
DecodedAddress_RetVals decodedAddress(const string &addressString, cryptonote::network_type nettype);
bool isSubAddress(const string &addressString, cryptonote::network_type nettype);
bool isIntegratedAddress(const string &addressString, cryptonote::network_type nettype);
DecodedAddress_RetVals decodedAddress(const string &addressString, network_type nettype);
bool isSubAddress(const string &addressString, network_type nettype);
bool isIntegratedAddress(const string &addressString, network_type nettype);
//
optional<string> new_integratedAddrFromStdAddr(const string &std_address_string, const string &short_paymentID, cryptonote::network_type nettype);
//
account_public_address new_fake_address_for_rct_tx();
string new_fake_address_string_for_rct_tx(network_type nettype);
}
}

@ -40,7 +40,7 @@ namespace monero_paymentID_utils
{
//
// Generating Payment IDs
crypto::hash8 new_short_plain_paymentID(); // This is favored - its length will be detected and encrypted automatically on send
crypto::hash8 new_short_plain_paymentID();
std::string new_short_plain_paymentID_string();
//
// Parsing and Detecting Payment IDs

@ -91,11 +91,10 @@ bool monero_wallet_utils::bytes_to_words(
);
}
//
//
bool monero_wallet_utils::new_wallet(
std::string mnemonic_language,
WalletDescriptionRetVals &retVals,
bool isTestnet
cryptonote::network_type nettype
) {
retVals = {};
//
@ -103,7 +102,7 @@ bool monero_wallet_utils::new_wallet(
crypto::secret_key nonLegacy32B_sec_seed = account.generate();
//
const cryptonote::account_keys& keys = account.get_keys();
std::string address_string = account.get_public_address_str(isTestnet ? cryptonote::TESTNET : cryptonote::MAINNET); // getting the string here instead of leaving it to the consumer b/c get_public_address_str could potentially change in implementation (see TODO) so it's not right to duplicate that here
std::string address_string = account.get_public_address_str(nettype); // getting the string here instead of leaving it to the consumer b/c get_public_address_str could potentially change in implementation (see TODO) so it's not right to duplicate that here
//
std::string mnemonic_string;
bool r = crypto::ElectrumWords::bytes_to_words(nonLegacy32B_sec_seed, mnemonic_string, std::move(mnemonic_language));
@ -194,44 +193,44 @@ bool monero_wallet_utils::decoded_seed(
}
//
SeedDecodedMnemonic_RetVals monero_wallet_utils::mnemonic_string_from_seed_hex_string(
std::string sec_hexString,
std::string mnemonic_language // aka wordset name
const std::string &sec_hexString,
const std::string &mnemonic_language // aka wordset name
) {
SeedDecodedMnemonic_RetVals retVals = {};
//
// std::string mnemonic_string;
// uint32_t sec_hexString_length = sec_hexString.size();
// //
// bool r = false;
// if (sec_hexString_length == sec_seed_hex_string_length) { // normal seed
// crypto::secret_key sec_seed;
// r = string_tools::hex_to_pod(sec_hexString, sec_seed);
// if (!r) {
// retVals.did_error = true;
// retVals.err_string = "Invalid seed";
// return retVals;
// }
// r = crypto::ElectrumWords::bytes_to_words(sec_seed, mnemonic_string, mnemonic_language);
// } else if (sec_hexString_length == legacy16B__sec_seed_hex_string_length) {
// legacy16B_secret_key legacy16B_sec_seed;
// r = string_tools::hex_to_pod(sec_hexString, legacy16B_sec_seed);
// if (!r) {
// retVals.did_error = true;
// retVals.err_string = "Invalid seed";
// return retVals;
// }
// r = bytes_to_words(legacy16B_sec_seed, mnemonic_string, mnemonic_language); // called with the legacy16B version
// } else {
// retVals.did_error = true;
// retVals.err_string = "Invalid seed length";
// return retVals;
// }
// if (!r) {
// retVals.did_error = true;
// retVals.err_string = "Couldn't get mnemonic from hex seed";
// return retVals;
// }
// retVals.mnemonic_string = mnemonic_string; // TODO: should/can we just send retVals.mnemonic_string to bytes_to_words ?
std::string mnemonic_string;
uint32_t sec_hexString_length = sec_hexString.size();
//
bool r = false;
if (sec_hexString_length == sec_seed_hex_string_length) { // normal seed
crypto::secret_key sec_seed;
r = string_tools::hex_to_pod(sec_hexString, sec_seed);
if (!r) {
retVals.did_error = true;
retVals.err_string = "Invalid seed";
return retVals;
}
r = crypto::ElectrumWords::bytes_to_words(sec_seed, mnemonic_string, mnemonic_language);
} else if (sec_hexString_length == legacy16B__sec_seed_hex_string_length) {
legacy16B_secret_key legacy16B_sec_seed;
r = string_tools::hex_to_pod(sec_hexString, legacy16B_sec_seed);
if (!r) {
retVals.did_error = true;
retVals.err_string = "Invalid seed";
return retVals;
}
r = bytes_to_words(legacy16B_sec_seed, mnemonic_string, mnemonic_language); // called with the legacy16B version
} else {
retVals.did_error = true;
retVals.err_string = "Invalid seed length";
return retVals;
}
if (!r) {
retVals.did_error = true;
retVals.err_string = "Couldn't get mnemonic from hex seed";
return retVals;
}
retVals.mnemonic_string = mnemonic_string; // TODO: should/can we just send retVals.mnemonic_string to bytes_to_words ?
return retVals;
}
//
@ -239,7 +238,7 @@ bool monero_wallet_utils::wallet_with(
std::string mnemonic_string,
std::string mnemonic_language,
WalletDescriptionRetVals &retVals,
bool isTestnet
cryptonote::network_type nettype
) {
retVals = {};
//
@ -261,7 +260,7 @@ bool monero_wallet_utils::wallet_with(
retVals.optl__desc = WalletDescription{
*decodedSeed_retVals.optl__sec_seed_string, // assumed non nil if r
//
account.get_public_address_str(isTestnet ? cryptonote::TESTNET : cryptonote::MAINNET),
account.get_public_address_str(nettype),
//
keys.m_spend_secret_key,
keys.m_view_secret_key,
@ -285,7 +284,7 @@ bool monero_wallet_utils::validate_wallet_components_with(
cryptonote::address_parse_info decoded_address_info;
r = cryptonote::get_account_address_from_str(
decoded_address_info,
inputs.isTestnet ? cryptonote::TESTNET : cryptonote::MAINNET,
inputs.nettype,
inputs.address_string
);
if (r == false) {

@ -47,6 +47,9 @@ using namespace tools;
//
namespace monero_wallet_utils
{
using namespace std;
using namespace boost;
using namespace tools;
//
// 16B keys
POD_CLASS ec_nonscalar_16Byte {
@ -73,30 +76,33 @@ namespace monero_wallet_utils
// Accounts
struct MnemonicDecodedSeed_RetVals: RetVals_base
{
boost::optional<crypto::secret_key> optl__sec_seed = boost::none;
boost::optional<std::string> optl__sec_seed_string = boost::none;
boost::optional<std::string> optl__mnemonic_string = boost::none;
optional<crypto::secret_key> optl__sec_seed = none;
optional<std::string> optl__sec_seed_string = none;
optional<std::string> optl__mnemonic_string = none;
bool from_legacy16B_lw_seed = false;
};
bool decoded_seed(
std::string mnemonic_string,
std::string mnemonic_language_string,
string mnemonic_string,
string mnemonic_language_string,
//
MnemonicDecodedSeed_RetVals &retVals
);
//
struct SeedDecodedMnemonic_RetVals: RetVals_base
{
boost::optional<std::string> mnemonic_string = boost::none;
optional<string> mnemonic_string = none;
};
SeedDecodedMnemonic_RetVals mnemonic_string_from_seed_hex_string(std::string seed_string, std::string wordsetName);
SeedDecodedMnemonic_RetVals mnemonic_string_from_seed_hex_string(
const string &seed_string,
const string &wordsetName
);
//
// Convenience functions - Wallets
struct WalletDescription
{
std::string sec_seed_string; // as string bc it might by legacy 16B style aside from crypto::secret_key
string sec_seed_string; // as string bc it might by legacy 16B style aside from crypto::secret_key
//
std::string address_string;
string address_string;
//
crypto::secret_key sec_spendKey;
crypto::secret_key sec_viewKey;
@ -112,13 +118,13 @@ namespace monero_wallet_utils
bool new_wallet(
std::string mnemonic_language,
WalletDescriptionRetVals &retVals,
bool isTestnet = false
cryptonote::network_type nettype = cryptonote::MAINNET
);
bool wallet_with(
std::string mnemonic_string,
std::string mnemonic_language,
WalletDescriptionRetVals &retVals,
bool isTestnet = false
cryptonote::network_type nettype = cryptonote::MAINNET
);
//
struct WalletComponentsToValidate
@ -127,7 +133,7 @@ namespace monero_wallet_utils
std::string sec_viewKey_string; // Required
const std::string *optl__sec_spendKey_string;
const std::string *optl__sec_seed_string;
bool isTestnet;
cryptonote::network_type nettype;
};
struct WalletComponentsValidationResults: RetVals_base
{

@ -39,7 +39,10 @@
#include "monero_fork_rules.hpp"
#include "monero_transfer_utils.hpp"
#include "monero_address_utils.hpp" // TODO: split this/these out into a different namespaces or file so this file can scale (leave file for shared utils)
#include "monero_paymentID_utils.hpp"
#include "monero_wallet_utils.hpp"
#include "wallet_errors.h"
#include "string_tools.h"
//
//
using namespace std;
@ -126,17 +129,16 @@ string serial_bridge::decode_address(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
network_type nettype = nettype_from_string(json_root.get<string>("nettype_string"));
auto retVals = monero::address_utils::decodedAddress(json_root.get<string>("address"), nettype);
auto retVals = monero::address_utils::decodedAddress(json_root.get<string>("address"), nettype_from_string(json_root.get<string>("nettype_string")));
if (retVals.did_error) {
return error_ret_json_from_message(*(retVals.err_string));
}
boost::property_tree::ptree root;
root.put(ret_json_key__decode_address__isSubaddress(), retVals.isSubaddress);
root.put(ret_json_key__decode_address__pub_viewKey_string(), std::move(*(retVals.pub_viewKey_string)));
root.put(ret_json_key__decode_address__pub_spendKey_string(), std::move(*(retVals.pub_spendKey_string)));
root.put(ret_json_key__isSubaddress(), retVals.isSubaddress);
root.put(ret_json_key__pub_viewKey_string(), std::move(*(retVals.pub_viewKey_string)));
root.put(ret_json_key__pub_spendKey_string(), std::move(*(retVals.pub_spendKey_string)));
if (retVals.paymentID_string != none) {
root.put(ret_json_key__decode_address__paymentID_string(), std::move(*(retVals.paymentID_string)));
root.put(ret_json_key__paymentID_string(), std::move(*(retVals.paymentID_string)));
}
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
@ -150,8 +152,7 @@ string serial_bridge::is_subaddress(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
network_type nettype = nettype_from_string(json_root.get<string>("nettype_string"));
bool retVal = monero::address_utils::isSubAddress(json_root.get<string>("address"), nettype);
bool retVal = monero::address_utils::isSubAddress(json_root.get<string>("address"), nettype_from_string(json_root.get<string>("nettype_string")));
boost::property_tree::ptree root;
root.put(ret_json_key__generic_retVal(), retVal);
stringstream ret_ss;
@ -166,8 +167,7 @@ string serial_bridge::is_integrated_address(const string &args_string)
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
network_type nettype = nettype_from_string(json_root.get<string>("nettype_string"));
bool retVal = monero::address_utils::isIntegratedAddress(json_root.get<string>("address"), nettype);
bool retVal = monero::address_utils::isIntegratedAddress(json_root.get<string>("address"), nettype_from_string(json_root.get<string>("nettype_string")));
boost::property_tree::ptree root;
root.put(ret_json_key__generic_retVal(), retVal);
stringstream ret_ss;
@ -177,24 +177,112 @@ string serial_bridge::is_integrated_address(const string &args_string)
}
string serial_bridge::new_integrated_address(const string &args_string)
{
// standard addr + short pid
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
optional<string> retVal = monero::address_utils::new_integratedAddrFromStdAddr(json_root.get<string>("address"), json_root.get<string>("short_pid"), nettype_from_string(json_root.get<string>("nettype_string")));
boost::property_tree::ptree root;
if (retVal != none) {
root.put(ret_json_key__generic_retVal(), std::move(*retVal));
}
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::new_fake_address_for_rct_tx(const string &args_string)
{
// TODO: probably take random scalar as an argument
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
optional<string> retVal = monero::address_utils::new_fake_address_string_for_rct_tx(
nettype_from_string(json_root.get<string>("nettype_string"))
);
boost::property_tree::ptree root;
if (retVal != none) {
root.put(ret_json_key__generic_retVal(), std::move(*retVal));
}
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::new_payment_id(const string &args_string)
{
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
optional<string> retVal = monero_paymentID_utils::new_short_plain_paymentID_string();
boost::property_tree::ptree root;
if (retVal != none) {
root.put(ret_json_key__generic_retVal(), std::move(*retVal));
}
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
//
string serial_bridge::newly_created_wallet(const string &args_string)
{
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
monero_wallet_utils::WalletDescriptionRetVals retVals;
bool r = monero_wallet_utils::new_wallet(
json_root.get<string>("wordset_name"),
retVals,
nettype_from_string(json_root.get<string>("nettype_string"))
);
bool did_error = retVals.did_error;
if (!r) {
THROW_WALLET_EXCEPTION_IF(!did_error, error::wallet_internal_error, "Illegal fail flag with !did_error");
return error_ret_json_from_message(*(retVals.err_string));
}
THROW_WALLET_EXCEPTION_IF(did_error, error::wallet_internal_error, "Illegal success flag but did_error");
//
boost::property_tree::ptree root;
root.put(ret_json_key__mnemonic_string(), (*(retVals.optl__desc)).mnemonic_string);
root.put(ret_json_key__sec_seed_string(), (*(retVals.optl__desc)).sec_seed_string);
root.put(ret_json_key__address_string(), (*(retVals.optl__desc)).address_string);
root.put(ret_json_key__pub_viewKey_string(), epee::string_tools::pod_to_hex((*(retVals.optl__desc)).pub_viewKey));
root.put(ret_json_key__sec_viewKey_string(), epee::string_tools::pod_to_hex((*(retVals.optl__desc)).sec_viewKey));
root.put(ret_json_key__pub_spendKey_string(), epee::string_tools::pod_to_hex((*(retVals.optl__desc)).pub_spendKey));
root.put(ret_json_key__sec_spendKey_string(), epee::string_tools::pod_to_hex((*(retVals.optl__desc)).sec_spendKey));
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::mnemonic_from_seed(const string &args_string)
{
// seed_string, wordset_name
boost::property_tree::ptree json_root;
if (!parsed_json_root(args_string, json_root)) {
// it will already have thrown an exception
return error_ret_json_from_message("Invalid JSON");
}
monero_wallet_utils::SeedDecodedMnemonic_RetVals retVals = monero_wallet_utils::mnemonic_string_from_seed_hex_string(
json_root.get<string>("seed_string"),
json_root.get<string>("wordset_name")
);
boost::property_tree::ptree root;
if (retVals.err_string != none) {
error_ret_json_from_message(*(retVals.err_string));
}
root.put(ret_json_key__generic_retVal(), *(retVals.mnemonic_string));
stringstream ret_ss;
boost::property_tree::write_json(ret_ss, root);
//
return ret_ss.str();
}
string serial_bridge::seed_and_keys_from_mnemonic(const string &args_string)
{

@ -42,17 +42,17 @@ namespace serial_bridge
using namespace cryptonote;
//
// Bridging Functions - these take and return JSON strings
string create_transaction(const string &args_string); // TODO: probably expose tx key as arg
string create_transaction(const string &args_string); // TODO: maybe expose tx key as arg
//
string decode_address(const string &args_string);
string is_subaddress(const string &args_string);
string is_integrated_address(const string &args_string);
//
string new_integrated_address(const string &args_string);
string new_fake_address_for_rct_tx(const string &args_string); // TODO: probably expose random scalar as arg
string new_fake_address_for_rct_tx(const string &args_string); // TODO: maybe expose random scalar as arg
string new_payment_id(const string &args_string);
//
string newly_created_wallet(const string &args_string); // TODO: probably expose random scalar as arg
string newly_created_wallet(const string &args_string); // TODO: maybe expose random scalar as arg
string mnemonic_from_seed(const string &args_string);
string seed_and_keys_from_mnemonic(const string &args_string);
string verified_components_for_login(const string &args_string);
@ -76,11 +76,17 @@ namespace serial_bridge
// - - create_transaction
static inline string ret_json_key__create_transaction__serialized_signed_tx() { return "serialized_signed_tx"; }
static inline string ret_json_key__create_transaction__tx_hash() { return "tx_hash"; }
// - - decode_address
static inline string ret_json_key__decode_address__pub_viewKey_string() { return "pub_viewKey_string"; }
static inline string ret_json_key__decode_address__pub_spendKey_string() { return "pub_spendKey_string"; }
static inline string ret_json_key__decode_address__paymentID_string() { return "paymentID_string"; } // optional
static inline string ret_json_key__decode_address__isSubaddress() { return "isSubaddress"; }
// - - decode_address, etc
static inline string ret_json_key__paymentID_string() { return "paymentID_string"; } // optional
static inline string ret_json_key__isSubaddress() { return "isSubaddress"; }
static inline string ret_json_key__mnemonic_string() { return "mnemonic_string"; }
static inline string ret_json_key__sec_seed_string() { return "sec_seed_string"; }
static inline string ret_json_key__address_string() { return "address_string"; }
static inline string ret_json_key__pub_viewKey_string() { return "pub_viewKey_string"; }
static inline string ret_json_key__pub_spendKey_string() { return "pub_spendKey_string"; }
static inline string ret_json_key__sec_viewKey_string() { return "sec_viewKey_string"; }
static inline string ret_json_key__sec_spendKey_string() { return "sec_spendKey_string"; }
// JSON keys - Args
// TODO:

@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(bridged__transfers__create)
string amount_string = "10000000000";
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("from_address_string", from_address_string);
root.put("sec_viewKey_string", "7bea1907940afdd480eff7c4bcadb478a0fbb626df9e3ed74ae801e18f53e104");
root.put("sec_spendKey_string", "4e6d43cd03812b803c6f3206689f5fcc910005fc7e91d50d79b0776dbefcd803");
@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(bridged__decode_address)
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("address", "4L6Gcy9TAHqPVPMnqa5cPtJK25tr7maE7LrJe67vzumiCtWwjDBvYnHZr18wFexJpih71Mxsjv8b7EpQftpB9NjPaL41VrjstLM5WevLZx");
//
stringstream args_ss;
@ -471,19 +471,19 @@ BOOST_AUTO_TEST_CASE(bridged__decode_address)
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> pub_viewKey_string = ret_tree.get_optional<string>(ret_json_key__decode_address__pub_viewKey_string());
optional<string> pub_viewKey_string = ret_tree.get_optional<string>(ret_json_key__pub_viewKey_string());
BOOST_REQUIRE(pub_viewKey_string != none);
BOOST_REQUIRE((*pub_viewKey_string).size() > 0);
cout << "bridged: pub_viewKey_string: " << *pub_viewKey_string << endl;
optional<string> pub_spendKey_string = ret_tree.get_optional<string>(ret_json_key__decode_address__pub_spendKey_string());
optional<string> pub_spendKey_string = ret_tree.get_optional<string>(ret_json_key__pub_spendKey_string());
BOOST_REQUIRE(pub_spendKey_string != none);
BOOST_REQUIRE((*pub_spendKey_string).size() > 0);
cout << "bridged: pub_viewKey_string: " << *pub_spendKey_string << endl;
optional<string> paymentID_string = ret_tree.get_optional<string>(ret_json_key__decode_address__paymentID_string());
cout << "bridged: pub_spendKey_string: " << *pub_spendKey_string << endl;
optional<string> paymentID_string = ret_tree.get_optional<string>(ret_json_key__paymentID_string());
BOOST_REQUIRE(paymentID_string != none);
BOOST_REQUIRE((*paymentID_string).size() > 0);
cout << "bridged: paymentID_string: " << *paymentID_string << endl;
optional<bool> isSubaddress = ret_tree.get_optional<bool>(ret_json_key__decode_address__isSubaddress());
optional<bool> isSubaddress = ret_tree.get_optional<bool>(ret_json_key__isSubaddress());
BOOST_REQUIRE(isSubaddress != none);
BOOST_REQUIRE(*isSubaddress == false);
cout << "bridged: isSubaddress: " << *isSubaddress << endl;
@ -494,7 +494,7 @@ BOOST_AUTO_TEST_CASE(bridged__is_subaddress)
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("address", "4L6Gcy9TAHqPVPMnqa5cPtJK25tr7maE7LrJe67vzumiCtWwjDBvYnHZr18wFexJpih71Mxsjv8b7EpQftpB9NjPaL41VrjstLM5WevLZx");
//
stringstream args_ss;
@ -508,10 +508,10 @@ BOOST_AUTO_TEST_CASE(bridged__is_subaddress)
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<bool> isSubaddress = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(isSubaddress != none);
BOOST_REQUIRE(*isSubaddress == false);
cout << "bridged: isSubaddress: " << *isSubaddress << endl;
optional<bool> value = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(value != none);
BOOST_REQUIRE(*value == false);
cout << "bridged: isSubaddress: " << *value << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__is_integrated_address)
@ -519,7 +519,7 @@ BOOST_AUTO_TEST_CASE(bridged__is_integrated_address)
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET)); // TODO: specify this by constant and transform fn
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("address", "4L6Gcy9TAHqPVPMnqa5cPtJK25tr7maE7LrJe67vzumiCtWwjDBvYnHZr18wFexJpih71Mxsjv8b7EpQftpB9NjPaL41VrjstLM5WevLZx");
//
stringstream args_ss;
@ -533,8 +533,179 @@ BOOST_AUTO_TEST_CASE(bridged__is_integrated_address)
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<bool> isIntegratedAddress = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(isIntegratedAddress != none);
BOOST_REQUIRE(*isIntegratedAddress == true);
cout << "bridged: isIntegratedAddress: " << *isIntegratedAddress << endl;
optional<bool> value = ret_tree.get_optional<bool>(ret_json_key__generic_retVal());
BOOST_REQUIRE(value != none);
BOOST_REQUIRE(*value == true);
cout << "bridged: isIntegratedAddress: " << *value << endl;
}
//
#include <boost/algorithm/string/predicate.hpp>
BOOST_AUTO_TEST_CASE(bridged__new_integrated_address)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("address", "43zxvpcj5Xv9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqm93wHGkg");
root.put("short_pid", "b79f8efc81f58f67");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::new_integrated_address(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> value = ret_tree.get_optional<string>(ret_json_key__generic_retVal());
BOOST_REQUIRE(value != none);
BOOST_REQUIRE((*value).size() > 0);
BOOST_REQUIRE(boost::equal(*value, string("4DhdwdSDgoS9SEkNXbMCG7LPQStHMpFCQCmkmR4u5nzjWwq5Xkv5VmGgYEsHXg4ja2FGRD5wMWbBVMijDTqmmVqmCzkMP1DMV6WCiNCdsp")));
cout << "bridged: integratedAddress: " << *value << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__new_fake_address_for_rct_tx)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET));
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::new_fake_address_for_rct_tx(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> value = ret_tree.get_optional<string>(ret_json_key__generic_retVal());
BOOST_REQUIRE(value != none);
BOOST_REQUIRE((*value).size() > 0);
cout << "bridged: fake address for rct tx: " << *value << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__new_short_payment_id)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::new_payment_id(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> value = ret_tree.get_optional<string>(ret_json_key__generic_retVal());
BOOST_REQUIRE(value != none);
BOOST_REQUIRE((*value).size() > 0);
cout << "bridged: payment id: " << *value << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__new_wallet)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("nettype_string", string_from_nettype(MAINNET));
root.put("wordset_name", "English");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::newly_created_wallet(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> mnemonic_string = ret_tree.get_optional<string>(ret_json_key__mnemonic_string());
BOOST_REQUIRE(mnemonic_string != none);
BOOST_REQUIRE((*mnemonic_string).size() > 0);
cout << "bridged: new wallet: mnemonic: " << *mnemonic_string << endl;
optional<string> sec_seed_string = ret_tree.get_optional<string>(ret_json_key__sec_seed_string());
BOOST_REQUIRE(sec_seed_string != none);
BOOST_REQUIRE((*sec_seed_string).size() > 0);
cout << "bridged: new wallet: sec_seed: " << *sec_seed_string << endl;
optional<string> address_string = ret_tree.get_optional<string>(ret_json_key__address_string());
BOOST_REQUIRE(address_string != none);
BOOST_REQUIRE((*address_string).size() > 0);
cout << "bridged: new wallet: address: " << *address_string << endl;
optional<string> pub_viewKey_string = ret_tree.get_optional<string>(ret_json_key__pub_viewKey_string());
BOOST_REQUIRE(pub_viewKey_string != none);
BOOST_REQUIRE((*pub_viewKey_string).size() > 0);
cout << "bridged: new wallet: pub_viewKey_string: " << *pub_viewKey_string << endl;
optional<string> pub_spendKey_string = ret_tree.get_optional<string>(ret_json_key__pub_spendKey_string());
BOOST_REQUIRE(pub_spendKey_string != none);
BOOST_REQUIRE((*pub_spendKey_string).size() > 0);
cout << "bridged: new wallet: pub_spendKey_string: " << *pub_spendKey_string << endl;
optional<string> sec_viewKey_string = ret_tree.get_optional<string>(ret_json_key__sec_viewKey_string());
BOOST_REQUIRE(sec_viewKey_string != none);
BOOST_REQUIRE((*sec_viewKey_string).size() > 0);
cout << "bridged: new wallet: sec_viewKey_string: " << *sec_viewKey_string << endl;
optional<string> sec_spendKey_string = ret_tree.get_optional<string>(ret_json_key__sec_spendKey_string());
BOOST_REQUIRE(sec_spendKey_string != none);
BOOST_REQUIRE((*sec_spendKey_string).size() > 0);
cout << "bridged: new wallet: sec_spendKey_string: " << *sec_spendKey_string << endl;
}
//
BOOST_AUTO_TEST_CASE(bridged__mnemonic_from_seed)
{
using namespace serial_bridge;
//
boost::property_tree::ptree root;
root.put("seed_string", "9c973aa296b79bbf452781dd3d32ad7f");
root.put("wordset_name", "English");
//
stringstream args_ss;
boost::property_tree::write_json(args_ss, root);
auto ret_string = serial_bridge::mnemonic_from_seed(args_ss.str());
stringstream ret_stream;
ret_stream << ret_string;
boost::property_tree::ptree ret_tree;
boost::property_tree::read_json(ret_stream, ret_tree);
optional<string> err_string = ret_tree.get_optional<string>(ret_json_key__any__err_msg());
if (err_string != none) {
BOOST_REQUIRE_MESSAGE(false, *err_string);
}
optional<string> mnemonic_string = ret_tree.get_optional<string>(ret_json_key__generic_retVal());
BOOST_REQUIRE(mnemonic_string != none);
BOOST_REQUIRE((*mnemonic_string).size() > 0);
cout << "bridged: mnemonic from seed: mnemonic: " << *mnemonic_string << endl;
}
BOOST_AUTO_TEST_CASE(bridged__seed_and_keys_from_mnemonic)
{
}
BOOST_AUTO_TEST_CASE(bridged__verified_components_for_login)
{
}
BOOST_AUTO_TEST_CASE(bridged__estimate_rct_size)
{
}
//
BOOST_AUTO_TEST_CASE(bridged__calculate_fee)
{
}
BOOST_AUTO_TEST_CASE(bridged__generate_key_image)
{
}

Loading…
Cancel
Save