From 5fb326d41d1994b6583959658347a91facb6cae0 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 7 Jan 2017 10:11:31 +0100 Subject: [PATCH] Manually iterate over UniValue arrays in tests --- src/gtest/json_test_vectors.h | 4 ++-- src/gtest/test_merkletree.cpp | 20 ++++++++------------ src/gtest/test_proofs.cpp | 6 ++---- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/gtest/json_test_vectors.h b/src/gtest/json_test_vectors.h index 623dab5e1..27c8757ec 100644 --- a/src/gtest/json_test_vectors.h +++ b/src/gtest/json_test_vectors.h @@ -31,7 +31,7 @@ void expect_deser_same(const T& expected) } template -void expect_test_vector(T& it, const U& expected) +void expect_test_vector(T& v, const U& expected) { expect_deser_same(expected); @@ -42,7 +42,7 @@ void expect_test_vector(T& it, const U& expected) std::cout << "\t\"" ; std::cout << HexStr(ss1.begin(), ss1.end()) << "\",\n"; #else - std::string raw = (it++)->get_str(); + std::string raw = v.get_str(); CDataStream ss2(ParseHex(raw), SER_NETWORK, PROTOCOL_VERSION); ASSERT_TRUE(ss1.size() == ss2.size()); diff --git a/src/gtest/test_merkletree.cpp b/src/gtest/test_merkletree.cpp index bd60d37c4..a8960d762 100644 --- a/src/gtest/test_merkletree.cpp +++ b/src/gtest/test_merkletree.cpp @@ -64,11 +64,8 @@ void test_tree( UniValue path_tests ) { - vector::iterator commitment_iterator = commitment_tests.getValues().begin(); - vector::iterator root_iterator = root_tests.getValues().begin(); - vector::iterator ser_iterator = ser_tests.getValues().begin(); - vector::iterator witness_ser_iterator = witness_ser_tests.getValues().begin(); - vector::iterator path_iterator = path_tests.getValues().begin(); + size_t witness_ser_i = 0; + size_t path_i = 0; Tree tree; @@ -88,7 +85,7 @@ void test_tree( vector witnesses; for (size_t i = 0; i < 16; i++) { - uint256 test_commitment = uint256S((commitment_iterator++)->get_str()); + uint256 test_commitment = uint256S(commitment_tests[i].get_str()); // Witness here witnesses.push_back(tree.witness()); @@ -103,10 +100,10 @@ void test_tree( ASSERT_TRUE(tree.last() == test_commitment); // Check tree root consistency - expect_test_vector(root_iterator, tree.root()); + expect_test_vector(root_tests[i], tree.root()); // Check serialization of tree - expect_ser_test_vector(ser_iterator, tree, tree); + expect_ser_test_vector(ser_tests[i], tree, tree); bool first = true; // The first witness can never form a path BOOST_FOREACH(Witness& wit, witnesses) @@ -121,7 +118,7 @@ void test_tree( auto path = wit.path(); { - expect_test_vector(path_iterator, path); + expect_test_vector(path_tests[path_i++], path); typedef Fr FieldT; @@ -173,7 +170,7 @@ void test_tree( } // Check witness serialization - expect_ser_test_vector(witness_ser_iterator, wit, tree); + expect_ser_test_vector(witness_ser_tests[witness_ser_i++], wit, tree); ASSERT_TRUE(wit.root() == tree.root()); @@ -204,12 +201,11 @@ TEST(merkletree, vectors) { TEST(merkletree, emptyroots) { UniValue empty_roots = read_json(std::string(json_tests::merkle_roots_empty, json_tests::merkle_roots_empty + sizeof(json_tests::merkle_roots_empty))); - vector::iterator root_iterator = empty_roots.getValues().begin(); libzcash::EmptyMerkleRoots<64, libzcash::SHA256Compress> emptyroots; for (size_t depth = 0; depth <= 64; depth++) { - expect_test_vector(root_iterator, emptyroots.empty_root(depth)); + expect_test_vector(empty_roots[depth], emptyroots.empty_root(depth)); } // Double check that we're testing (at least) all the empty roots we'll use. diff --git a/src/gtest/test_proofs.cpp b/src/gtest/test_proofs.cpp index 69ffdbe54..49202f1f6 100644 --- a/src/gtest/test_proofs.cpp +++ b/src/gtest/test_proofs.cpp @@ -630,14 +630,13 @@ TEST(proofs, g2_deserialization) TEST(proofs, g1_test_vectors) { UniValue v = read_json(std::string(json_tests::g1_compressed, json_tests::g1_compressed + sizeof(json_tests::g1_compressed))); - std::vector::iterator v_iterator = v.getValues().begin(); curve_G1 e = curve_Fr("34958239045823") * curve_G1::one(); for (size_t i = 0; i < 10000; i++) { e = (curve_Fr("34958239045823") ^ i) * e; auto expected = CompressedG1(e); - expect_test_vector(v_iterator, expected); + expect_test_vector(v[i], expected); ASSERT_TRUE(expected.to_libsnark_g1() == e); } } @@ -647,14 +646,13 @@ TEST(proofs, g1_test_vectors) TEST(proofs, g2_test_vectors) { UniValue v = read_json(std::string(json_tests::g2_compressed, json_tests::g2_compressed + sizeof(json_tests::g2_compressed))); - std::vector::iterator v_iterator = v.getValues().begin(); curve_G2 e = curve_Fr("34958239045823") * curve_G2::one(); for (size_t i = 0; i < 10000; i++) { e = (curve_Fr("34958239045823") ^ i) * e; auto expected = CompressedG2(e); - expect_test_vector(v_iterator, expected); + expect_test_vector(v[i], expected); ASSERT_TRUE(expected.to_libsnark_g2() == e); } }