Repository navigation
Expand file tree
/
Copy pathAddressTests.cpp
More file actions
39 lines (30 loc) · 1.52 KB
/
Copy pathAddressTests.cpp
File metadata and controls
39 lines (30 loc) · 1.52 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
// 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 "Icon/Address.h"
#include "HexCoding.h"
#include "PrivateKey.h"
#include <gtest/gtest.h>
using namespace TW;
using namespace TW::Icon;
TEST(IconAddress, Validation) {
ASSERT_TRUE(Address::isValid("cx116f042497e5f34268b1b91e742680f84cf4e9f3"));
ASSERT_TRUE(Address::isValid("hx116f042497e5f34268b1b91e742680f84cf4e9f3"));
ASSERT_FALSE(Address::isValid("abc"));
ASSERT_FALSE(Address::isValid("dshadghasdghsadadsadjsad"));
ASSERT_FALSE(Address::isValid("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"));
}
TEST(IconAddress, String) {
const auto address = Address("hx116f042497e5f34268b1b91e742680f84cf4e9f3");
ASSERT_EQ(address.string(), "hx116f042497e5f34268b1b91e742680f84cf4e9f3");
const auto address2 = Address("cx116f042497e5f34268b1b91e742680f84cf4e9f3");
ASSERT_EQ(address2.string(), "cx116f042497e5f34268b1b91e742680f84cf4e9f3");
}
TEST(IconAddress, FromPrivateKey) {
const auto privateKey = PrivateKey(parse_hex("94d1a980d5e528067d44bf8a60d646f556e40ca71e17cd4ead2d56f89e4bd20f"));
const auto publicKey = PublicKey(privateKey.getPublicKey(TWPublicKeyTypeSECP256k1Extended));
const auto address = Address(publicKey, TWIconAddressTypeAddress);
ASSERT_EQ(address.string(), "hx98c0832ca5bd8e8bf355ca9491888aa9725c2c48");
}