1 #include <chainparams.h>
3 #include <zcash/Address.hpp>
4 #include <zcash/zip32.h>
5 #include "consensus/upgrades.h"
9 #include <gtest/gtest.h>
11 TEST(Keys, EncodeAndDecodeSapling)
13 SelectParams(CBaseChainParams::MAIN);
15 auto m = GetTestMasterSaplingSpendingKey();
17 for (uint32_t i = 0; i < 1000; i++) {
18 auto sk = m.Derive(i);
20 std::string sk_string = EncodeSpendingKey(sk);
22 sk_string.substr(0, 24),
23 Params().Bech32HRP(CChainParams::SAPLING_EXTENDED_SPEND_KEY));
25 auto spendingkey2 = DecodeSpendingKey(sk_string);
26 EXPECT_TRUE(IsValidSpendingKey(spendingkey2));
28 ASSERT_TRUE(boost::get<libzcash::SaplingExtendedSpendingKey>(&spendingkey2) != nullptr);
29 auto sk2 = boost::get<libzcash::SaplingExtendedSpendingKey>(spendingkey2);
33 auto addr = sk.DefaultAddress();
35 std::string addr_string = EncodePaymentAddress(addr);
37 addr_string.substr(0, 2),
38 Params().Bech32HRP(CChainParams::SAPLING_PAYMENT_ADDRESS));
40 auto paymentaddr2 = DecodePaymentAddress(addr_string);
41 EXPECT_TRUE(IsValidPaymentAddress(paymentaddr2, SAPLING_BRANCH_ID));
43 ASSERT_TRUE(boost::get<libzcash::SaplingPaymentAddress>(&paymentaddr2) != nullptr);
44 auto addr2 = boost::get<libzcash::SaplingPaymentAddress>(paymentaddr2);
45 EXPECT_EQ(addr, addr2);