source: code/test_simplexorrequestor.py @ 133

Last change on this file since 133 was 23, checked in by trishank, 7 years ago

Add pre-release upPIR from June 2011.

File size: 2.2 KB
Line 
1# on success, nothing is printed
2import simplexorrequestor
3
4# I'm keeping some of these datastructures tiny in order to make the output
5# more readable if an error is discovered
6mirrorinfolist = [{'name':'mirror1'}, {'name':'mirror2'}, {'name':'mirror3'}, {'name':'mirror4'}, {'name':'mirror5'}]
7blocklist = [12,34]   
8# this would usually be richer, but I only need these fields
9manifestdict = {'blockcount':64, 'hashalgorithm':'noop',
10    'blockhashlist':['']*64}
11
12rxgobj = simplexorrequestor.RandomXORRequestor(mirrorinfolist, blocklist, manifestdict, 2)
13
14request1 = rxgobj.get_next_xorrequest()
15request2 = rxgobj.get_next_xorrequest()
16
17# success!
18rxgobj.notify_success(request1,'a')
19request3 = rxgobj.get_next_xorrequest()
20# so request1 and request3 should be for the same mirror...
21assert(request1[0] == request3[0])
22
23# failure..
24rxgobj.notify_failure(request2)
25request4 = rxgobj.get_next_xorrequest()
26assert(request2[0] != request4[0])
27# so request2 and request4 should be for different mirrors...
28
29
30# success!
31rxgobj.notify_success(request3,'b')
32# we're out of blocks to request from the first mirror...
33
34rxgobj.notify_success(request4,chr(2))
35
36# we're out of blocks to request from the first mirror...
37request5 = rxgobj.get_next_xorrequest()
38assert(request5[0] != request3[0])
39assert(request5[0] == request4[0])
40# we should have requested from the same mirror we tried before
41
42rxgobj.notify_success(request5,chr(4))
43
44# this should be ()
45request6 = rxgobj.get_next_xorrequest()
46assert(request6 == ())
47
48# okay, now it's time to see if we get the right answer...  'a' ^ chr(2) == 'c'
49answer1 = rxgobj.return_block(12)
50
51# 'b' ^ chr(4) == 'f'
52answer2 = rxgobj.return_block(34)
53
54assert(answer1 == 'c')
55assert(answer2 == 'f')
56
57
58
59
60
61# Now let's try this where we chew through all of the mirrors to ensure we get
62# the right exception
63mirrorinfolist = [{'name':'mirror1'}, {'name':'mirror2'}, {'name':'mirror3'}]
64
65rxgobj = simplexorrequestor.RandomXORRequestor(mirrorinfolist, blocklist, manifestdict, 2)
66
67request1 = rxgobj.get_next_xorrequest()
68request2 = rxgobj.get_next_xorrequest()
69
70rxgobj.notify_failure(request1)
71try:
72  rxgobj.notify_failure(request2)
73except simplexorrequestor.InsufficientMirrors:
74  pass
75else:
76  print "Should be notified of insufficient mirrors!"
77
Note: See TracBrowser for help on using the repository browser.