changeset 638:45ce0d082747

Verify that multiplications really are local. The tests rely on the fact that an already called Deferred will execute a callback immediately when it is added with addCallback. The API does not guarantee this behavior, but the current implementation works that way. I don't know if this will change if the Deferred class is implemented in C, as this Twisted ticket suggests: http://twistedmatrix.com/trac/ticket/2245
author Martin Geisler <mg@daimi.au.dk>
date Fri, 04 Apr 2008 23:59:11 +0200
parents d1d4c633fca8
children c99ae4b6b054
files viff/test/test_runtime.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/test/test_runtime.py	Fri Apr 04 22:25:03 2008 +0200
+++ b/viff/test/test_runtime.py	Fri Apr 04 23:59:11 2008 +0200
@@ -60,6 +60,43 @@
     """Test L{viff.runtime.Runtime}."""
 
     @protocol
+    def test_mul_no_resharing_int(self, runtime):
+        """Verify that local multiplications really are local."""
+        a = Share(runtime, self.Zp, self.Zp(2))
+        b = 3
+        c = a * b
+
+        # We setup a list which can be mutated from the mutate
+        # callback below:
+        c_value = [None]
+        def mutate(value):
+            c_value[0] = value
+
+        # We now add the callback to c and expect it to be called
+        # immediatedly since c should have a value right away. This is
+        # a slight hack: There is nothing in the Deferred abstraction
+        # that says that callbacks will be called immediatedly.
+        c.addCallback(mutate)
+        self.assertEquals(c_value[0], 6)
+
+    @protocol
+    def test_mul_no_resharing_field_element(self, runtime):
+        """Verify that local multiplications really are local.
+
+        This test uses a Zp element instead of a plain integer.
+        """
+        a = Share(runtime, self.Zp, self.Zp(2))
+        b = self.Zp(3)
+        c = a * b
+
+        c_value = [None]
+        def mutate(value):
+            c_value[0] = value
+
+        c.addCallback(mutate)
+        self.assertEquals(c_value[0], 6)
+
+    @protocol
     def test_xor(self, runtime):
         """Test exclusive-or.