forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DerivationPathTests.cpp
73 lines (58 loc) · 2.55 KB
/
DerivationPathTests.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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 "DerivationPath.h"
#include <gtest/gtest.h>
namespace TW {
TEST(DerivationPath, InitWithIndices) {
const auto path = DerivationPath(TWPurposeBIP44, TWCoinTypeEthereum, 0, 0, 0);
ASSERT_EQ(path.indices[0], DerivationPathIndex(44, /* hardened: */true));
ASSERT_EQ(path.indices[1], DerivationPathIndex(60, /* hardened: */true));
ASSERT_EQ(path.indices[2], DerivationPathIndex(0, /* hardened: */true));
ASSERT_EQ(path.indices[3], DerivationPathIndex(0, /* hardened: */false));
ASSERT_EQ(path.indices[4], DerivationPathIndex(0, /* hardened: */false));
}
TEST(DerivationPath, InitWithString) {
ASSERT_NO_THROW(DerivationPath("m/44'/60'/0'/0/0"));
const auto path = DerivationPath("m/44'/60'/0'/0/0");
ASSERT_EQ(path.indices[0], DerivationPathIndex(44, /* hardened: */true));
ASSERT_EQ(path.indices[1], DerivationPathIndex(60, /* hardened: */true));
ASSERT_EQ(path.indices[2], DerivationPathIndex(0, /* hardened: */true));
ASSERT_EQ(path.indices[3], DerivationPathIndex(0, /* hardened: */false));
ASSERT_EQ(path.indices[4], DerivationPathIndex(0, /* hardened: */false));
ASSERT_EQ(path.purpose(), 44);
ASSERT_EQ(path.coin(), 60);
ASSERT_EQ(path.account(), 0);
ASSERT_EQ(path.change(), 0);
ASSERT_EQ(path.address(), 0);
}
TEST(DerivationPath, InitInvalid) {
ASSERT_THROW(DerivationPath("a/b/c"), std::invalid_argument);
ASSERT_THROW(DerivationPath("m/44'/60''/"), std::invalid_argument);
}
TEST(DerivationPath, IndexOutOfBounds) {
DerivationPath path;
EXPECT_EQ(path.indices.size(), 0);
EXPECT_EQ(path.purpose(), TWPurposeBIP44);
EXPECT_EQ(path.coin(), TWCoinTypeBitcoin);
EXPECT_EQ(path.account(), 0);
EXPECT_EQ(path.change(), 0);
EXPECT_EQ(path.address(), 0);
ASSERT_NO_THROW(path.setPurpose(TWPurposeBIP44));
ASSERT_NO_THROW(path.setCoin(TWCoinTypeBitcoin));
ASSERT_NO_THROW(path.setAccount(0));
ASSERT_NO_THROW(path.setChange(0));
ASSERT_NO_THROW(path.setAddress(0));
}
TEST(DerivationPath, String) {
const auto path = DerivationPath("m/44'/60'/0'/0/0");
ASSERT_EQ(path.string(), "m/44'/60'/0'/0/0");
}
TEST(DerivationPath, Equal) {
const auto path1 = DerivationPath("m/44'/60'/0'/0/0");
const auto path2 = DerivationPath("44'/60'/0'/0/0");
ASSERT_EQ(path1, path2);
}
} // namespace