unit tests: OOB indexes & adding subaddress
Tests for checking proper error throwing for out-of-bounds subaddress indexes, and proper addition of subaddresses. Signed-off-by: Cole Lightfighter <cole@onicsla.bz>
This commit is contained in:
parent
4fd6a3d27f
commit
4fb7794651
|
@ -44,12 +44,12 @@ class WalletSubaddress : public ::testing::Test
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
w1.generate(wallet_name, password, recovery_key, true, false);
|
w1.generate(wallet_name, password, recovery_key, true, false);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
LOG_ERROR("failed to generate wallet: " << e.what());
|
LOG_ERROR("failed to generate wallet: " << e.what());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
w1.add_subaddress_account(test_label);
|
w1.add_subaddress_account(test_label);
|
||||||
|
@ -58,21 +58,20 @@ class WalletSubaddress : public ::testing::Test
|
||||||
|
|
||||||
virtual void TearDown()
|
virtual void TearDown()
|
||||||
{
|
{
|
||||||
boost::filesystem::wpath wallet_file(wallet_name);
|
boost::filesystem::wpath wallet_file(wallet_name);
|
||||||
boost::filesystem::wpath wallet_address_file(wallet_name + ".address.txt");
|
boost::filesystem::wpath wallet_address_file(wallet_name + ".address.txt");
|
||||||
boost::filesystem::wpath wallet_keys_file(wallet_name + ".keys");
|
boost::filesystem::wpath wallet_keys_file(wallet_name + ".keys");
|
||||||
|
|
||||||
if ( boost::filesystem::exists(wallet_file) )
|
if ( boost::filesystem::exists(wallet_file) )
|
||||||
boost::filesystem::remove(wallet_file);
|
boost::filesystem::remove(wallet_file);
|
||||||
|
|
||||||
if ( boost::filesystem::exists(wallet_address_file) )
|
if ( boost::filesystem::exists(wallet_address_file) )
|
||||||
boost::filesystem::remove(wallet_address_file);
|
boost::filesystem::remove(wallet_address_file);
|
||||||
|
|
||||||
if ( boost::filesystem::exists(wallet_keys_file) )
|
if ( boost::filesystem::exists(wallet_keys_file) )
|
||||||
boost::filesystem::remove(wallet_keys_file);
|
boost::filesystem::remove(wallet_keys_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tools::wallet2 w1;
|
tools::wallet2 w1;
|
||||||
std::string path_working_dir = ".";
|
std::string path_working_dir = ".";
|
||||||
std::string path_test_wallet = "test_wallet";
|
std::string path_test_wallet = "test_wallet";
|
||||||
|
@ -86,7 +85,34 @@ class WalletSubaddress : public ::testing::Test
|
||||||
const cryptonote::subaddress_index subaddress_index = {major_index, minor_index};
|
const cryptonote::subaddress_index subaddress_index = {major_index, minor_index};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WalletSubaddress, AddRow)
|
TEST_F(WalletSubaddress, GetSubaddressLabel)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
|
EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(WalletSubaddress, AddSubaddress)
|
||||||
|
{
|
||||||
|
std::string label = "test adding subaddress";
|
||||||
|
w1.add_subaddress(0, label);
|
||||||
|
EXPECT_EQ(label, w1.get_subaddress_label({0, 1}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(WalletSubaddress, OutOfBoundsIndexes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
w1.get_subaddress_label({1,0});
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
EXPECT_STREQ("index_major is out of bound", e.what());
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
w1.get_subaddress_label({0,2});
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
EXPECT_STREQ("index.minor is out of bound", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue