viff

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 diff
     1.1 --- a/viff/test/test_runtime.py	Fri Apr 04 22:25:03 2008 +0200
     1.2 +++ b/viff/test/test_runtime.py	Fri Apr 04 23:59:11 2008 +0200
     1.3 @@ -60,6 +60,43 @@
     1.4      """Test L{viff.runtime.Runtime}."""
     1.5  
     1.6      @protocol
     1.7 +    def test_mul_no_resharing_int(self, runtime):
     1.8 +        """Verify that local multiplications really are local."""
     1.9 +        a = Share(runtime, self.Zp, self.Zp(2))
    1.10 +        b = 3
    1.11 +        c = a * b
    1.12 +
    1.13 +        # We setup a list which can be mutated from the mutate
    1.14 +        # callback below:
    1.15 +        c_value = [None]
    1.16 +        def mutate(value):
    1.17 +            c_value[0] = value
    1.18 +
    1.19 +        # We now add the callback to c and expect it to be called
    1.20 +        # immediatedly since c should have a value right away. This is
    1.21 +        # a slight hack: There is nothing in the Deferred abstraction
    1.22 +        # that says that callbacks will be called immediatedly.
    1.23 +        c.addCallback(mutate)
    1.24 +        self.assertEquals(c_value[0], 6)
    1.25 +
    1.26 +    @protocol
    1.27 +    def test_mul_no_resharing_field_element(self, runtime):
    1.28 +        """Verify that local multiplications really are local.
    1.29 +
    1.30 +        This test uses a Zp element instead of a plain integer.
    1.31 +        """
    1.32 +        a = Share(runtime, self.Zp, self.Zp(2))
    1.33 +        b = self.Zp(3)
    1.34 +        c = a * b
    1.35 +
    1.36 +        c_value = [None]
    1.37 +        def mutate(value):
    1.38 +            c_value[0] = value
    1.39 +
    1.40 +        c.addCallback(mutate)
    1.41 +        self.assertEquals(c_value[0], 6)
    1.42 +
    1.43 +    @protocol
    1.44      def test_xor(self, runtime):
    1.45          """Test exclusive-or.
    1.46