]> Git Repo - VerusCoin.git/blob - src/gtest/test_keys.cpp
Build fix
[VerusCoin.git] / src / gtest / test_keys.cpp
1 #include <chainparams.h>
2 #include <key_io.h>
3 #include <zcash/Address.hpp>
4 #include <zcash/zip32.h>
5 #include "consensus/upgrades.h"
6
7 #include "utiltest.h"
8
9 #include <gtest/gtest.h>
10
11 TEST(Keys, EncodeAndDecodeSapling)
12 {
13     SelectParams(CBaseChainParams::MAIN);
14
15     auto m = GetTestMasterSaplingSpendingKey();
16
17     for (uint32_t i = 0; i < 1000; i++) {
18         auto sk = m.Derive(i);
19         {
20             std::string sk_string = EncodeSpendingKey(sk);
21             EXPECT_EQ(
22                 sk_string.substr(0, 24),
23                 Params().Bech32HRP(CChainParams::SAPLING_EXTENDED_SPEND_KEY));
24
25             auto spendingkey2 = DecodeSpendingKey(sk_string);
26             EXPECT_TRUE(IsValidSpendingKey(spendingkey2));
27
28             ASSERT_TRUE(boost::get<libzcash::SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
29             auto sk2 = boost::get<libzcash::SaplingExtendedSpendingKey>(spendingkey2);
30             EXPECT_EQ(sk, sk2);
31         }
32         {
33             auto addr = sk.DefaultAddress();
34
35             std::string addr_string = EncodePaymentAddress(addr);
36             EXPECT_EQ(
37                 addr_string.substr(0, 2),
38                 Params().Bech32HRP(CChainParams::SAPLING_PAYMENT_ADDRESS));
39
40             auto paymentaddr2 = DecodePaymentAddress(addr_string);
41             EXPECT_TRUE(IsValidPaymentAddress(paymentaddr2, SAPLING_BRANCH_ID));
42
43             ASSERT_TRUE(boost::get<libzcash::SaplingPaymentAddress>(&paymentaddr2) != nullptr);
44             auto addr2 = boost::get<libzcash::SaplingPaymentAddress>(paymentaddr2);
45             EXPECT_EQ(addr, addr2);
46         }
47     }
48 }
This page took 0.024777 seconds and 4 git commands to generate.