-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtest_agenting.py
More file actions
248 lines (192 loc) · 10.2 KB
/
test_agenting.py
File metadata and controls
248 lines (192 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# -*- encoding: utf-8 -*-
"""
tests.app.agenting module
"""
import time
from hio.base import doing, tyming
from keri import kering, core
from keri.core import coring, serdering
from keri.core.coring import Seqner
from keri.help import nowIso8601
from keri.app import habbing, indirecting, agenting, directing
from keri.db import basing, dbing
from keri.vdr import eventing, viring
def test_withness_receiptor(seeder):
with habbing.openHby(name="wan", salt=core.Salter(raw=b'wann-the-witness').qb64) as wanHby, \
habbing.openHby(name="wil", salt=core.Salter(raw=b'will-the-witness').qb64) as wilHby, \
habbing.openHby(name="wes", salt=core.Salter(raw=b'wess-the-witness').qb64) as wesHby, \
habbing.openHby(name="pal", salt=core.Salter(raw=b'0123456789abcdef').qb64) as palHby:
wanDoers = indirecting.setupWitness(alias="wan", hby=wanHby, tcpPort=5632, httpPort=5642)
wilDoers = indirecting.setupWitness(alias="wil", hby=wilHby, tcpPort=5633, httpPort=5643)
wesDoers = indirecting.setupWitness(alias="wes", hby=wesHby, tcpPort=5634, httpPort=5644)
wanHab = wanHby.habByName(name="wan")
wilHab = wilHby.habByName(name="wil")
wesHab = wesHby.habByName(name="wes")
seeder.seedWitEnds(palHby.db, witHabs=[wanHab, wilHab, wesHab], protocols=[kering.Schemes.tcp])
rctDoer = ReceiptDoer(hby=palHby, wanHab=wanHab, wilHab=wilHab, wesHab=wesHab)
limit = 5.0
tock = 0.03125
doers = wanDoers + wilDoers + wesDoers + [rctDoer]
doist = doing.Doist(limit=limit, tock=tock, doers=doers)
doist.enter()
tymer = tyming.Tymer(tymth=doist.tymen(), duration=doist.limit)
while not (rctDoer.done or tymer.expired):
doist.recur()
time.sleep(doist.tock)
doist.exit()
assert rctDoer.done is True
class ReceiptDoer(doing.DoDoer):
""" Test scenario of witness receipts. """
def __init__(self, hby, wanHab, wilHab, wesHab):
self.hby = hby
self.wanHab = wanHab
self.wilHab = wilHab
self.wesHab = wesHab
super(ReceiptDoer, self).__init__(doers=[doing.doify(self.testDo)])
def testDo(self, tymth, tock=0.0, **kwa):
""" Execute a series of kli commands for this test scenario """
# enter context
self.wind(tymth)
self.tock = tock
_ = (yield self.tock)
palHab = self.hby.makeHab(name="pal", wits=[self.wanHab.pre, self.wilHab.pre], transferable=True)
witDoer = agenting.WitnessReceiptor(hby=self.hby)
witDoer.msgs.append(dict(pre=palHab.pre))
self.extend([witDoer])
kev = palHab.kever
ser = kev.serder
dgkey = dbing.dgKey(ser.preb, ser.saidb)
while True:
wilWigs = self.wilHab.db.getWigs(dgkey)
wanWigs = self.wanHab.db.getWigs(dgkey)
if len(wilWigs) == 2 and len(wanWigs) == 2:
break
yield self.tock
# Controller should send endpoints between witnesses. Check for Endpoints for each other:
keys = (self.wanHab.pre, kering.Schemes.tcp)
said = self.wilHab.db.lans.get(keys=keys)
assert said is not None
keys = (self.wilHab.pre, kering.Schemes.tcp)
said = self.wanHab.db.lans.get(keys=keys)
assert said is not None
palHab.rotate(adds=[self.wesHab.pre])
witDoer.msgs.append(dict(pre=palHab.pre, sn=1))
kev = palHab.kever
ser = kev.serder
dgkey = dbing.dgKey(ser.preb, ser.saidb)
while True:
wilWigs = self.wilHab.db.getWigs(dgkey)
wanWigs = self.wanHab.db.getWigs(dgkey)
wesWigs = self.wesHab.db.getWigs(dgkey)
if len(wilWigs) == 3 and len(wanWigs) == 3 and len(wesWigs) == 3:
break
yield self.tock
self.remove([witDoer])
return True
def test_witness_sender(seeder):
with habbing.openHby(name="wan", salt=core.Salter(raw=b'wann-the-witness').qb64) as wanHby, \
habbing.openHby(name="wil", salt=core.Salter(raw=b'will-the-witness').qb64) as wilHby, \
habbing.openHby(name="wes", salt=core.Salter(raw=b'wess-the-witness').qb64) as wesHby, \
habbing.openHby(name="pal", salt=core.Salter(raw=b'0123456789abcdef').qb64) as palHby:
# looks like bad magic value in seeder is causing this to fail
pdoer = PublishDoer(wanHby, wilHby, wesHby, palHby, seeder)
directing.runController(doers=[pdoer], expire=15.0)
assert pdoer.done is True
class PublishDoer(doing.DoDoer):
def __init__(self, wanHby, wilHby, wesHby, palHby, seeder):
wanDoers = indirecting.setupWitness(alias="wan", hby=wanHby, tcpPort=5632, httpPort=5642)
wilDoers = indirecting.setupWitness(alias="wil", hby=wilHby, tcpPort=5633, httpPort=5643)
wesDoers = indirecting.setupWitness(alias="wes", hby=wesHby, tcpPort=5634, httpPort=5644)
self.regers = dict(
wan=next(doer.baser for doer in wanDoers if isinstance(doer, basing.BaserDoer)),
wil=next(doer.baser for doer in wilDoers if isinstance(doer, basing.BaserDoer)),
wes=next(doer.baser for doer in wesDoers if isinstance(doer, basing.BaserDoer)),
)
wanHab = wanHby.habByName(name="wan")
wilHab = wilHby.habByName(name="wil")
wesHab = wesHby.habByName(name="wes")
seeder.seedWitEnds(palHby.db, witHabs=[wanHab, wilHab, wesHab], protocols=[kering.Schemes.tcp])
self.palHab = palHby.makeHab(name="pal", wits=[wanHab.pre, wilHab.pre, wesHab.pre], transferable=True)
self.witDoer = agenting.WitnessPublisher(hby=palHby)
doers = wanDoers + wilDoers + wesDoers + [self.witDoer]
self.toRemove = list(doers)
doers.extend([doing.doify(self.testDo)])
super(PublishDoer, self).__init__(doers=doers)
def testDo(self, tymth, tock=0.0, **kwa):
""" Run the test and exit and remove all child doers when done """
self.wind(tymth)
self.tock = tock
yield self.tock
regser = eventing.incept(pre=self.palHab.pre, baks=[], code=coring.MtrDex.Blake3_256)
serder = eventing.issue(vcdig=regser.pre,
regk="EbA1o_bItVC9i6YB3hr2C3I_Gtqvz02vCmavJNoBA3Jg")
msg = bytearray(serder.raw)
msg.extend(core.Counter(core.Codens.SealSourceCouples, count=1,
gvrsn=kering.Vrsn_1_0).qb64b)
msg.extend(Seqner(sn=self.palHab.kever.sn).qb64b)
msg.extend(self.palHab.kever.serder.saidb)
self.witDoer.msgs.append(dict(pre=self.palHab.pre, msg=msg))
while not self.witDoer.cues:
yield self.tock
cue = self.witDoer.cues.popleft()
assert cue["pre"] == self.palHab.pre
assert cue["msg"] == msg
for name in ["wes", "wil", "wan"]:
reger = self.regers[name]
while True:
raw = reger.getTvt(dbing.dgKey(serder.preb, serder.saidb))
if raw:
found = serdering.SerderKERI(raw=bytes(raw))
if found and serder.pre == found.pre:
break
yield self.tock
self.remove(self.toRemove)
return True
def test_witness_inquisitor(mockHelpingNowUTC, seeder):
with habbing.openHby(name="wan", salt=core.Salter(raw=b'wann-the-witness').qb64) as wanHby, \
habbing.openHby(name="wil", salt=core.Salter(raw=b'will-the-witness').qb64) as wilHby, \
habbing.openHby(name="wes", salt=core.Salter(raw=b'wess-the-witness').qb64) as wesHby, \
habbing.openHby(name="pal", salt=core.Salter(raw=b'0123456789abcdef').qb64) as palHby, \
habbing.openHby(name="qin", salt=core.Salter(raw=b'abcdef0123456789').qb64) as qinHby:
wanDoers = indirecting.setupWitness(alias="wan", hby=wanHby, tcpPort=5632, httpPort=5642)
wilDoers = indirecting.setupWitness(alias="wil", hby=wilHby, tcpPort=5633, httpPort=5643)
wesDoers = indirecting.setupWitness(alias="wes", hby=wesHby, tcpPort=5634, httpPort=5644)
wanHab = wanHby.habByName(name="wan")
wilHab = wilHby.habByName(name="wil")
wesHab = wesHby.habByName(name="wes")
seeder.seedWitEnds(palHby.db, witHabs=[wanHab, wilHab, wesHab], protocols=[kering.Schemes.tcp])
seeder.seedWitEnds(qinHby.db, witHabs=[wanHab, wilHab, wesHab], protocols=[kering.Schemes.tcp])
palHab = palHby.makeHab(name="pal", wits=[wanHab.pre, wilHab.pre, wesHab.pre], transferable=True)
qinHab = qinHby.makeHab(name="qin", wits=[wanHab.pre, wilHab.pre, wesHab.pre], transferable=True)
palWitDoer = agenting.WitnessReceiptor(hby=palHby)
palWitDoer.msgs.append(dict(pre=palHab.pre))
qinWitDoer = agenting.WitnessReceiptor(hby=qinHby)
qinWitDoer.msgs.append(dict(pre=qinHab.pre))
qinWitq = agenting.WitnessInquisitor(hby=qinHby)
# query up a few to make sure it still works
stamp = nowIso8601() # need same time stamp or not duplicate
qinWitq.query(src=qinHab.pre, pre=palHab.pre, stamp=stamp, wits=palHab.kever.wits)
qinWitq.query(src=qinHab.pre, pre=palHab.pre, stamp=stamp, wits=palHab.kever.wits)
qinWitq.query(src=qinHab.pre, pre=palHab.pre, stamp=stamp, wits=palHab.kever.wits)
palWitq = agenting.WitnessInquisitor(hby=palHby)
palWitq.query(src=palHab.pre, pre=qinHab.pre, stamp=stamp, wits=qinHab.kever.wits)
limit = 5.0
tock = 0.03125
doist = doing.Doist(limit=limit, tock=tock)
doers = wanDoers + wilDoers + wesDoers + [palWitDoer, qinWitDoer]
doist.do(doers=doers)
for hab in [palHab, qinHab]:
kev = hab.kever
ser = kev.serder
dgkey = dbing.dgKey(ser.preb, ser.saidb)
wigs = wanHab.db.getWigs(dgkey)
assert len(wigs) == 3
wigs = wilHab.db.getWigs(dgkey)
assert len(wigs) == 3
wigs = wesHab.db.getWigs(dgkey)
assert len(wigs) == 3
doist = doing.Doist(limit=limit, tock=tock)
doers = wanDoers + wilDoers + wesDoers + [qinWitq, palWitq]
doist.do(doers=doers)
assert palHab.pre in qinHab.kevers
assert qinHab.pre in palHab.kevers