Skip to content

Commit

Permalink
Add pytest setup for CI (#46)
Browse files Browse the repository at this point in the history
* Add pytest setup for CI

Add pytest setup to run on CI, Remove redundant files

* Add binding for default_r1cs_ppzkpcd_pp

* Add Binding for default_types/r1cs_ppzkpcd_pp.hpp

* Update workflow for pytest setup
  • Loading branch information
gargarchit authored Jun 5, 2020
1 parent 400c459 commit dcf522e
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pyzpkpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ jobs:
flake8 . --exclude third_party \
--count --select=E9,F63,F7,F82 --show-source --statistics \
--count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 test
- name: Building Library
run: |
chmod 557 build.sh
./build.sh
./build.sh
- name: Scan for security issues
run: |
bandit -r syft -ll
- name: Run tests
run: |
cp build/src/*.so test
coverage run -m pytest test
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ jobs:
flake8 . --exclude third_party \
--count --select=E9,F63,F7,F82 --show-source --statistics \
--count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Building Library
run: |
chmod 557 build.sh
./build.sh
- name: Scan for security issues
run: |
bandit -r syft -ll
- name: Run tests
run: |
cp build/src/*.so test
coverage run -m pytest test
1 change: 0 additions & 1 deletion _pyzpk/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions _pyzpk/main.py

This file was deleted.

11 changes: 11 additions & 0 deletions src/PyZPK/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <libsnark/common/data_structures/set_commitment.hpp>
#include <libsnark/common/routing_algorithms/benes_routing_algorithm.cpp>
#include <libsnark/common/routing_algorithms/as_waksman_routing_algorithm.cpp>
#include <libsnark/common/default_types/r1cs_ppzkpcd_pp.hpp>
#include <libsnark/common/default_types/tinyram_ppzksnark_pp.hpp>
using namespace std;
using namespace libsnark;
namespace py = pybind11;
Expand Down Expand Up @@ -114,4 +116,13 @@ PYBIND11_MODULE(pyzpk, m)
)pbdoc", py::arg("left"), py::arg("right"), py::arg("lo"), py::arg("hi"), py::arg("permutation"), py::arg("permutation_inv"), py::arg("routing"));
m.def("get_as_waksman_routing", &get_as_waksman_routing, py::arg("permutation"));
m.def("valid_as_waksman_routing", &valid_as_waksman_routing, py::arg("permutation"), py::arg("routing"));


// Binding for #include common/default_types/r1cs_ppzkpcd_pp.hpp
py::class_<default_r1cs_ppzkpcd_pp>(m, "default_r1cs_ppzkpcd_pp")
.def_static("init_public_params", &default_r1cs_ppzkpcd_pp::init_public_params);

// Binding for #include common/default_types/tinyram_ppzksnark_pp.hpp
py::class_<default_tinyram_ppzksnark_pp>(m, "default_tinyram_ppzksnark_pp")
.def_static("init_public_params", &default_tinyram_ppzksnark_pp::init_public_params);
}
19 changes: 0 additions & 19 deletions src/PyZPK/main.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions src/PyZPK/test/routing_algorithms.py

This file was deleted.

Empty file removed test/__init__.py
Empty file.
62 changes: 62 additions & 0 deletions test/test_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Testing functionality for routing on an benes network and arbitrary-size (AS) Waksman network.
import pytest
import pyzpk
import math

def test_benes():
num_packets = 8
permutation = pyzpk.integer_permutation(math.ceil(num_packets))
while permutation.next_permutation():
routing = pyzpk.get_benes_routing(permutation)
assert pyzpk.valid_benes_routing(permutation, routing) == True

def test_as_waksman():
num_packets = 8
permutation = pyzpk.integer_permutation(num_packets)
while permutation.next_permutation():
routing = pyzpk.get_as_waksman_routing(permutation)
assert pyzpk.valid_as_waksman_routing(permutation, routing) == True

def test_data_structures():
min_element = 0
max_element = 7

# intiallize vector and populate from 0 to 7 of size 8 using std::iota
vec = pyzpk.integer_permutation(min_element,max_element)
assert vec.get(2) == 2
assert vec.get(1) == 1
assert vec.get(5) == 5
assert vec.get(7) == 7
# slice from a to b
vec1 = vec.slice(3,5)
assert vec1.get(5) == 5
# Permutating the vector
vec.set(0,7)
vec.set(1,4)
vec.set(2,3)
vec.set(3,0)
vec.set(4,5)
vec.set(5,1)
vec.set(6,2)
vec.set(7,6)
assert vec.get(2) == 3
assert vec.get(1) == 4
assert vec.get(5) == 1
assert vec.get(7) == 6
# .size()
assert vec.size() == 8
# Check is_valid permute
assert vec.is_valid() == True
# Random shuffle elements of vector
vec.random_shuffle()
assert vec.is_valid() == True
# Finding next permute
vec.next_permutation()
assert vec.is_valid() == True
# Finding next permute
vec2 = vec.inverse()
assert vec2.is_valid() == True
# set a number above max_element for idx 5
vec.set(5,10)
# Check is_valid permute
assert vec.is_valid() == False
19 changes: 0 additions & 19 deletions test/test_dummy.py

This file was deleted.

54 changes: 0 additions & 54 deletions test_binding.py

This file was deleted.

0 comments on commit dcf522e

Please sign in to comment.