Electroneum
Loading...
Searching...
No Matches
address_from_url.cpp
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// FIXME: move this into a full wallet2 unit test suite, if possible
31
32#include "gtest/gtest.h"
33
34#include "wallet/wallet2.h"
35#include "common/dns_utils.h"
37#include <string>
38
39TEST(AddressFromTXT, Success)
40{
41 std::string addr = "etnjwQwwEY65dhSMfKto64GgY7j7q2RUSZP1r8rXZ615J4egUC596R4crvZ5woWWTWBUztnKMUudzQ22E37LHiV48XWeJDFkkY";
42
43 std::string txtr = "oa1:etn";
44 txtr += " recipient_address=";
45 txtr += addr;
46 txtr += ";";
47
49
50 EXPECT_STREQ(addr.c_str(), res.c_str());
51
52 std::string txtr2 = "foobar";
53
54 txtr2 += txtr;
55
56 txtr2 += "more foobar";
57
59
60 EXPECT_STREQ(addr.c_str(), res.c_str());
61
62 std::string txtr3 = "foobar oa1:etn tx_description=\"Donation for Electroneum Development Fund\"; ";
63 txtr3 += "recipient_address=";
64 txtr3 += addr;
65 txtr3 += "; foobar";
66
68
69 EXPECT_STREQ(addr.c_str(), res.c_str());
70}
71
72TEST(AddressFromTXT, Failure)
73{
74 std::string txtr = "oa1:etn recipient_address=not a real address";
75
77
78 ASSERT_STREQ("", res.c_str());
79
80 txtr += ";";
81
83 ASSERT_STREQ("", res.c_str());
84}
85
86TEST(AddressFromURL, Success)
87{
88 const std::string addr = ETN_DONATION_ADDR;
89
90 bool dnssec_result = false;
91
92 std::vector<std::string> addresses = tools::dns_utils::addresses_from_url("donate.electroneum.com", dnssec_result);
93
94 EXPECT_EQ(1, addresses.size());
95 if (addresses.size() == 1)
96 {
97 EXPECT_STREQ(addr.c_str(), addresses[0].c_str());
98 }
99
100 // OpenAlias address with an @ instead of first .
101 addresses = tools::dns_utils::addresses_from_url("donate@electroneum.com", dnssec_result);
102 EXPECT_EQ(1, addresses.size());
103 if (addresses.size() == 1)
104 {
105 EXPECT_STREQ(addr.c_str(), addresses[0].c_str());
106 }
107}
108
109TEST(AddressFromURL, Failure)
110{
111 bool dnssec_result = false;
112
113 std::vector<std::string> addresses = tools::dns_utils::addresses_from_url("example.veryinvalid", dnssec_result);
114
115 // for a non-existing domain such as "example.invalid", the non-existence is proved with NSEC records
116 ASSERT_TRUE(dnssec_result);
117
118 ASSERT_EQ(0, addresses.size());
119}
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define ASSERT_STREQ(s1, s2)
Definition gtest.h:2004
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1995
#define TEST(test_case_name, test_name)
Definition gtest.h:2187
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
const char * res
std::vector< std::string > addresses_from_url(const std::string &url, bool &dnssec_valid)
gets a electroneum address from the TXT record of a DNS entry
std::string address_from_txt_record(const std::string &s)
Header file that declares simple_wallet class.
constexpr const char ETN_DONATION_ADDR[]