Debian Codegraph @

monero/tests/unit_tests/subaddress.cpp

raw symbols SCIP
1 // Copyright (c) 2014-2022, 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"
36 #include "cryptonote_basic/account.h"
37 #include "cryptonote_basic/cryptonote_basic_impl.h"
38 #include "wallet/api/subaddress.h"
39
40 class WalletSubaddress : public ::testing::Test
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
55 w1.add_subaddress_account(test_label);
56 w1.set_subaddress_label(subaddress_index, test_label);
57 }
58
59 virtual void TearDown()
60 {
61 }
62
63 tools::wallet2 w1;
64 const std::string password = "testpass";
65 crypto::secret_key recovery_key = crypto::secret_key();
66 const std::string test_label = "subaddress test label";
67
68 uint32_t major_index = 0;
69 uint32_t minor_index = 0;
70 const cryptonote::subaddress_index subaddress_index = {major_index, minor_index};
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 }