| Hi VIFF'ers, I have a small class and a unit test for it. The unittest fails, but this is not the real issue. The issue is the strange behavior I see during execution. During execution I see output similar to this: >>> Seeding random generator with random seed 5590 test_dealer DealerTest test_next_three_cards ... INIT Share value: None <Share at 0x278f0a8> ... contains 3 [] ... contains 1 [] adding 1 <Share at 0x278ceb8 current result: {13}> ... contains 2 [] adding 2 <Share at 0x278f558> ... contains 2 [<Share at 0x278f558 current result: None>] adding 2 <Share at 0x2787d50> ... contains 3 [<Share at 0x278f440 current result: None>] adding 3 <Share at 0x2791c38> ... contains 1 [<Share at 0x278ceb8 current result: None>] adding 1 <Share at 0x278fc88 current result: {9}> ... <<< As you see when player 1 adds a share to the value list, the current result of the share is 13. However when player 1 comes around to add a new share with current result 9, the current result of the share already contained in the list has transformed into None! It is clear from the hashcode that it is still the same object, so why does the current value change?? I have tried to boil down the code as much as possible. The test is executed with trial test_dealer.py on python 2.6.2 |
from viff.field import GF Zp = GF(53)
class Dealer(object):
def __init__(self, runtime):
self.runtime = runtime
self.values = []
def next_card(self, a):
print "n1", self.runtime.id
def choose_random_card1(x, a, r):
print "adding", self.runtime.id, r
self.values.append(r)
return r
def choose_random_card(a):
print "n3", self.runtime.id
if 1 == self.runtime.id:
r = self.runtime.input([1], Zp, 23)
else:
r = self.runtime.input([1], Zp)
print "contains", self.runtime.id, self.values
self.runtime.schedule_callback(a, choose_random_card1, a, r)
print "n9", self.runtime.id
a.addErrback(errorHandler)
print "n10", self.runtime.id
return a
print "n2", self.runtime.id
return choose_random_card(a)
def errorHandler(failure):
print "Error: %s" % failure
return failure
# Import VIFF packages.
from viff.test.util import RuntimeTestCase, protocol
from twisted.internet.defer import DeferredList
from dealer import Dealer
import pdb
from viff.field import GF
Zp = GF(53)
class DealerTest(RuntimeTestCase):
def get_value(self, runtime, v):
if 1 == runtime.id:
a = runtime.input([1], Zp, v)
else:
a = runtime.input([1], Zp)
return a
@protocol
def test_next_three_cards(self, runtime):
dealer = Dealer(runtime)
fourtwo = self.get_value(runtime, 42)
card1 = dealer.next_card(fourtwo)
def validation(x, c1, c2):
print "VALIDATION"
print ">>>>", x, c1, c2
self.assertEquals(x, [7, 7, 7])
return x
def step3(card2, card1):
print "STEP 3"
card3 = dealer.next_card(fourtwo)
c3 = runtime.output(card3)
runtime.schedule_callback(c3, validation, card1, card2)
return c3
def step2(card1):
print "STEP 2"
card2 = dealer.next_card(fourtwo)
c2 = runtime.output(card2)
runtime.schedule_callback(c2, step3, card1)
return c2
c1 = runtime.output(card1)
runtime.schedule_callback(c1, step2)
return c1
____________________________________________________ Janus Dam Nielsen R&D SCIENTIST, PhD. CENTRE FOR IT-SECURITY THE ALEXANDRA INSTITUTE LTD. T +45 42 22 93 56 W alexandra.dk ____________________________________________________ |
_______________________________________________ viff-devel mailing list (http://viff.dk/) [email protected] http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk
