Manually iterate over UniValue arrays in tests
This commit is contained in:
@@ -31,7 +31,7 @@ void expect_deser_same(const T& expected)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
void expect_test_vector(T& it, const U& expected)
|
void expect_test_vector(T& v, const U& expected)
|
||||||
{
|
{
|
||||||
expect_deser_same(expected);
|
expect_deser_same(expected);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ void expect_test_vector(T& it, const U& expected)
|
|||||||
std::cout << "\t\"" ;
|
std::cout << "\t\"" ;
|
||||||
std::cout << HexStr(ss1.begin(), ss1.end()) << "\",\n";
|
std::cout << HexStr(ss1.begin(), ss1.end()) << "\",\n";
|
||||||
#else
|
#else
|
||||||
std::string raw = (it++)->get_str();
|
std::string raw = v.get_str();
|
||||||
CDataStream ss2(ParseHex(raw), SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ss2(ParseHex(raw), SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
|
||||||
ASSERT_TRUE(ss1.size() == ss2.size());
|
ASSERT_TRUE(ss1.size() == ss2.size());
|
||||||
|
|||||||
@@ -64,11 +64,8 @@ void test_tree(
|
|||||||
UniValue path_tests
|
UniValue path_tests
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
vector<UniValue>::iterator commitment_iterator = commitment_tests.getValues().begin();
|
size_t witness_ser_i = 0;
|
||||||
vector<UniValue>::iterator root_iterator = root_tests.getValues().begin();
|
size_t path_i = 0;
|
||||||
vector<UniValue>::iterator ser_iterator = ser_tests.getValues().begin();
|
|
||||||
vector<UniValue>::iterator witness_ser_iterator = witness_ser_tests.getValues().begin();
|
|
||||||
vector<UniValue>::iterator path_iterator = path_tests.getValues().begin();
|
|
||||||
|
|
||||||
Tree tree;
|
Tree tree;
|
||||||
|
|
||||||
@@ -88,7 +85,7 @@ void test_tree(
|
|||||||
vector<Witness> witnesses;
|
vector<Witness> witnesses;
|
||||||
|
|
||||||
for (size_t i = 0; i < 16; i++) {
|
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
|
// Witness here
|
||||||
witnesses.push_back(tree.witness());
|
witnesses.push_back(tree.witness());
|
||||||
@@ -103,10 +100,10 @@ void test_tree(
|
|||||||
ASSERT_TRUE(tree.last() == test_commitment);
|
ASSERT_TRUE(tree.last() == test_commitment);
|
||||||
|
|
||||||
// Check tree root consistency
|
// Check tree root consistency
|
||||||
expect_test_vector(root_iterator, tree.root());
|
expect_test_vector(root_tests[i], tree.root());
|
||||||
|
|
||||||
// Check serialization of tree
|
// 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
|
bool first = true; // The first witness can never form a path
|
||||||
BOOST_FOREACH(Witness& wit, witnesses)
|
BOOST_FOREACH(Witness& wit, witnesses)
|
||||||
@@ -121,7 +118,7 @@ void test_tree(
|
|||||||
auto path = wit.path();
|
auto path = wit.path();
|
||||||
|
|
||||||
{
|
{
|
||||||
expect_test_vector(path_iterator, path);
|
expect_test_vector(path_tests[path_i++], path);
|
||||||
|
|
||||||
typedef Fr<default_r1cs_ppzksnark_pp> FieldT;
|
typedef Fr<default_r1cs_ppzksnark_pp> FieldT;
|
||||||
|
|
||||||
@@ -173,7 +170,7 @@ void test_tree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check witness serialization
|
// 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());
|
ASSERT_TRUE(wit.root() == tree.root());
|
||||||
|
|
||||||
@@ -204,12 +201,11 @@ TEST(merkletree, vectors) {
|
|||||||
|
|
||||||
TEST(merkletree, emptyroots) {
|
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)));
|
UniValue empty_roots = read_json(std::string(json_tests::merkle_roots_empty, json_tests::merkle_roots_empty + sizeof(json_tests::merkle_roots_empty)));
|
||||||
vector<UniValue>::iterator root_iterator = empty_roots.getValues().begin();
|
|
||||||
|
|
||||||
libzcash::EmptyMerkleRoots<64, libzcash::SHA256Compress> emptyroots;
|
libzcash::EmptyMerkleRoots<64, libzcash::SHA256Compress> emptyroots;
|
||||||
|
|
||||||
for (size_t depth = 0; depth <= 64; depth++) {
|
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.
|
// Double check that we're testing (at least) all the empty roots we'll use.
|
||||||
|
|||||||
@@ -630,14 +630,13 @@ TEST(proofs, g2_deserialization)
|
|||||||
TEST(proofs, g1_test_vectors)
|
TEST(proofs, g1_test_vectors)
|
||||||
{
|
{
|
||||||
UniValue v = read_json(std::string(json_tests::g1_compressed, json_tests::g1_compressed + sizeof(json_tests::g1_compressed)));
|
UniValue v = read_json(std::string(json_tests::g1_compressed, json_tests::g1_compressed + sizeof(json_tests::g1_compressed)));
|
||||||
std::vector<UniValue>::iterator v_iterator = v.getValues().begin();
|
|
||||||
|
|
||||||
curve_G1 e = curve_Fr("34958239045823") * curve_G1::one();
|
curve_G1 e = curve_Fr("34958239045823") * curve_G1::one();
|
||||||
for (size_t i = 0; i < 10000; i++) {
|
for (size_t i = 0; i < 10000; i++) {
|
||||||
e = (curve_Fr("34958239045823") ^ i) * e;
|
e = (curve_Fr("34958239045823") ^ i) * e;
|
||||||
auto expected = CompressedG1(e);
|
auto expected = CompressedG1(e);
|
||||||
|
|
||||||
expect_test_vector(v_iterator, expected);
|
expect_test_vector(v[i], expected);
|
||||||
ASSERT_TRUE(expected.to_libsnark_g1<curve_G1>() == e);
|
ASSERT_TRUE(expected.to_libsnark_g1<curve_G1>() == e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -647,14 +646,13 @@ TEST(proofs, g1_test_vectors)
|
|||||||
TEST(proofs, g2_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)));
|
UniValue v = read_json(std::string(json_tests::g2_compressed, json_tests::g2_compressed + sizeof(json_tests::g2_compressed)));
|
||||||
std::vector<UniValue>::iterator v_iterator = v.getValues().begin();
|
|
||||||
|
|
||||||
curve_G2 e = curve_Fr("34958239045823") * curve_G2::one();
|
curve_G2 e = curve_Fr("34958239045823") * curve_G2::one();
|
||||||
for (size_t i = 0; i < 10000; i++) {
|
for (size_t i = 0; i < 10000; i++) {
|
||||||
e = (curve_Fr("34958239045823") ^ i) * e;
|
e = (curve_Fr("34958239045823") ^ i) * e;
|
||||||
auto expected = CompressedG2(e);
|
auto expected = CompressedG2(e);
|
||||||
|
|
||||||
expect_test_vector(v_iterator, expected);
|
expect_test_vector(v[i], expected);
|
||||||
ASSERT_TRUE(expected.to_libsnark_g2<curve_G2>() == e);
|
ASSERT_TRUE(expected.to_libsnark_g2<curve_G2>() == e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user