Repository navigation
Expand file tree
/
Copy pathAddressTests.cpp
More file actions
55 lines (46 loc) · 2.21 KB
/
Copy pathAddressTests.cpp
File metadata and controls
55 lines (46 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2019 Mart Roosmaa.
// Copyright © 2017-2020 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "Nano/Address.h"
#include "HexCoding.h"
#include <gtest/gtest.h>
using namespace std;
using namespace TW;
using namespace TW::Nano;
TEST(NanoAddress, FromPublicKey) {
{
const auto publicKey = PublicKey(parse_hex("5114aad86a390897d2a91b33b931b3a59a7df9e63eb3694f9430122f5622ae50"), TWPublicKeyTypeED25519Blake2b);
const auto address = Address(publicKey);
ASSERT_EQ(string("nano_1nanode8ngaakzbck8smq6ru9bethqwyehomf79sae1k7xd47dkidjqzffeg"), address.string());
}
{
const auto publicKey = PublicKey(parse_hex("03e20ec6b4a39a629815ae02c0a1393b9225e3b890cae45b59f42fa29be9668d"), TWPublicKeyTypeED25519);
ASSERT_THROW(Address address(publicKey), std::invalid_argument);
}
}
TEST(NanoAddress, FromString) {
{
string nanoAddress = "nano_1nanode8ngaakzbck8smq6ru9bethqwyehomf79sae1k7xd47dkidjqzffeg";
const auto address = Address(nanoAddress);
ASSERT_EQ(address.string(), nanoAddress);
ASSERT_EQ(hex(address.bytes), "5114aad86a390897d2a91b33b931b3a59a7df9e63eb3694f9430122f5622ae50");
}
{
string xrbAddress = "xrb_1111111111111111111111111111111111111111111111111111hifc8npp";
string nanoAddress = "nano_1111111111111111111111111111111111111111111111111111hifc8npp";
const auto address = Address(xrbAddress);
ASSERT_EQ(address.string(), nanoAddress);
ASSERT_EQ(hex(address.bytes), "0000000000000000000000000000000000000000000000000000000000000000");
}
}
TEST(NanoAddress, isValid) {
string nanodeAddress = "nano_1nanode8ngaakzbck8smq6ru9bethqwyehomf79sae1k7xd47dkidjqzffeg";
string faultyChecksumAddress = "xrb_1111111111111111111111111111111111111111111111111111hi111111";
string bitcoinAddress = "1Ma2DrB78K7jmAwaomqZNRMCvgQrNjE2QC";
ASSERT_TRUE(Address::isValid(nanodeAddress));
ASSERT_FALSE(Address::isValid(faultyChecksumAddress));
ASSERT_FALSE(Address::isValid(bitcoinAddress));
}