Electroneum
subaddress.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2019, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 #include <boost/filesystem.hpp>
31 #include "gtest/gtest.h"
32 
33 #include "include_base_utils.h"
34 #include "wallet/wallet2.h"
35 #include "crypto/crypto.h"
38 #include "wallet/api/subaddress.h"
39 
41 {
42  protected:
43  virtual void SetUp()
44  {
45  try
46  {
47  w1.generate("", password, recovery_key, true, false);
48  }
49  catch (const std::exception& e)
50  {
51  LOG_ERROR("failed to generate wallet: " << e.what());
52  throw;
53  }
54 
57  }
58 
59  virtual void TearDown()
60  {
61  }
62 
64  const std::string password = "testpass";
66  const std::string test_label = "subaddress test label";
67 
71 };
72 
73 TEST_F(WalletSubaddress, GetSubaddressLabel)
74 {
75  EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
76 }
77 
78 TEST_F(WalletSubaddress, AddSubaddress)
79 {
80  std::string label = "test adding subaddress";
81  w1.add_subaddress(0, label);
82  EXPECT_EQ(label, w1.get_subaddress_label({0, 1}));
83 }
84 
85 TEST_F(WalletSubaddress, OutOfBoundsIndexes)
86 {
87  try
88  {
89  w1.get_subaddress_label({1,0});
90  }
91  catch(const std::exception& e)
92  {
93  EXPECT_STREQ("index_major is out of bound", e.what());
94  }
95  try
96  {
97  w1.get_subaddress_label({0,2});
98  }
99  catch(const std::exception& e)
100  {
101  EXPECT_STREQ("index.minor is out of bound", e.what());
102  }
103 }
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
::std::string string
Definition: gtest-port.h:1097
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:82
TEST_F(WalletSubaddress, GetSubaddressLabel)
Definition: subaddress.cpp:73
tools::wallet2 w1
Definition: subaddress.cpp:63
void add_subaddress_account(const std::string &label, const bool update_account_tags=true)
Definition: wallet2.cpp:1463
const cryptonote::subaddress_index subaddress_index
Definition: subaddress.cpp:70
uint32_t minor_index
Definition: subaddress.cpp:69
const std::string password
Definition: subaddress.cpp:64
virtual void TearDown()
Definition: subaddress.cpp:59
unsigned int uint32_t
Definition: stdint.h:126
virtual void SetUp()
Definition: subaddress.cpp:43
uint32_t major_index
Definition: subaddress.cpp:68
crypto::secret_key recovery_key
Definition: subaddress.cpp:65
void set_subaddress_label(const cryptonote::subaddress_index &index, const std::string &label)
Definition: wallet2.cpp:1528
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void generate(const std::string &wallet_, const epee::wipeable_string &password, const epee::wipeable_string &multisig_data, bool create_address_file=false)
Generates a wallet or restores one.
Definition: wallet2.cpp:4869
const std::string test_label
Definition: subaddress.cpp:66