From acacc044fcb82009d7cbbe93db6008727250d84f Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Sun, 30 Jan 2022 11:09:06 -0700 Subject: [PATCH] Add gtest for change address derivation. Check that derivation of the UFVK change address is consistent irrespective of the path by which it is derived. --- src/gtest/test_zip32.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gtest/test_zip32.cpp b/src/gtest/test_zip32.cpp index 2a43a192e..78b18ad8c 100644 --- a/src/gtest/test_zip32.cpp +++ b/src/gtest/test_zip32.cpp @@ -172,3 +172,19 @@ TEST(ZIP32, diversifier_index_t_lt) EXPECT_FALSE(libzcash::diversifier_index_t(0xffffffff) < libzcash::diversifier_index_t(0x01)); } +TEST(ZIP32, DeriveChangeAddress) +{ + std::vector> rawSeed { + 0, 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}; + HDSeed seed(rawSeed); + + auto accountSk = libzcash::SaplingExtendedSpendingKey::ForAccount(seed, 1, 0); + auto extfvk = accountSk.first.ToXFVK(); + auto changeSk = accountSk.first.DeriveInternalKey(); + auto changeDfvk = extfvk.GetInternalDFVK(); + + EXPECT_EQ(changeDfvk.DefaultAddress(), extfvk.GetChangeAddress()); + EXPECT_EQ(changeSk.ToXFVK().DefaultAddress(), extfvk.GetChangeAddress()); +} +