Electroneum
Loading...
Searching...
No Matches
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"
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
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
64 const std::string password = "testpass";
66 const std::string test_label = "subaddress test label";
67
71};
72
73TEST_F(WalletSubaddress, GetSubaddressLabel)
74{
75 EXPECT_EQ(test_label, w1.get_subaddress_label(subaddress_index));
76}
77
78TEST_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
85TEST_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}
const std::string test_label
const cryptonote::subaddress_index subaddress_index
const std::string password
uint32_t minor_index
uint32_t major_index
virtual void TearDown()
crypto::secret_key recovery_key
virtual void SetUp()
tools::wallet2 w1
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2216
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1995
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:82
unsigned int uint32_t
Definition stdint.h:126