]> Git Repo - VerusCoin.git/commitdiff
test: gtest for Sapling encoding and decoding
authorJack Grigg <[email protected]>
Mon, 13 Aug 2018 12:20:07 +0000 (13:20 +0100)
committerJack Grigg <[email protected]>
Mon, 13 Aug 2018 12:20:07 +0000 (13:20 +0100)
src/Makefile.gtest.include
src/gtest/test_keys.cpp [new file with mode: 0644]

index e089d57836f7c2621d4f187124f40d3ea68af693..65e067b8118fad633ae80dba6bbeee8906db0286 100644 (file)
@@ -23,6 +23,7 @@ zcash_gtest_SOURCES += \
        gtest/test_equihash.cpp \
        gtest/test_httprpc.cpp \
        gtest/test_joinsplit.cpp \
+       gtest/test_keys.cpp \
        gtest/test_keystore.cpp \
        gtest/test_noteencryption.cpp \
        gtest/test_mempool.cpp \
diff --git a/src/gtest/test_keys.cpp b/src/gtest/test_keys.cpp
new file mode 100644 (file)
index 0000000..74a3bb6
--- /dev/null
@@ -0,0 +1,42 @@
+#include <chainparams.h>
+#include <key_io.h>
+#include <zcash/Address.hpp>
+
+#include <gtest/gtest.h>
+
+TEST(Keys, EncodeAndDecodeSapling)
+{
+    SelectParams(CBaseChainParams::MAIN);
+
+    for (size_t i = 0; i < 1000; i++) {
+        auto sk = libzcash::SaplingSpendingKey::random();
+        {
+            std::string sk_string = EncodeSpendingKey(sk);
+            EXPECT_EQ(
+                sk_string.substr(0, 24),
+                Params().Bech32HRP(CChainParams::SAPLING_SPENDING_KEY));
+
+            auto spendingkey2 = DecodeSpendingKey(sk_string);
+            EXPECT_TRUE(IsValidSpendingKey(spendingkey2));
+
+            ASSERT_TRUE(boost::get<libzcash::SaplingSpendingKey>(&spendingkey2) != nullptr);
+            auto sk2 = boost::get<libzcash::SaplingSpendingKey>(spendingkey2);
+            EXPECT_EQ(sk, sk2);
+        }
+        {
+            auto addr = sk.default_address();
+
+            std::string addr_string = EncodePaymentAddress(addr);
+            EXPECT_EQ(
+                addr_string.substr(0, 2),
+                Params().Bech32HRP(CChainParams::SAPLING_PAYMENT_ADDRESS));
+
+            auto paymentaddr2 = DecodePaymentAddress(addr_string);
+            EXPECT_TRUE(IsValidPaymentAddress(paymentaddr2));
+
+            ASSERT_TRUE(boost::get<libzcash::SaplingPaymentAddress>(&paymentaddr2) != nullptr);
+            auto addr2 = boost::get<libzcash::SaplingPaymentAddress>(paymentaddr2);
+            EXPECT_EQ(addr, addr2);
+        }
+    }
+}
This page took 0.026805 seconds and 4 git commands to generate.