Skip to content

Commit

Permalink
tests: federation: activitypub: bovine: Almost there
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Nov 20, 2023
1 parent ee12609 commit 8e4d6f9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
9 changes: 8 additions & 1 deletion scitt_emulator/federation_activitypub_bovine.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async def handle(
):
try:
logger.info(f"{__file__}:handle(handler_event={handler_event})")
print(f"{__file__}:handle(handler_event={handler_event})")
match handler_event:
case HandlerEvent.OPENED:
# Listen for events from SCITT
Expand All @@ -177,7 +178,7 @@ async def federate_created_entries_pass_client(
created_entry: SCITTSignalsFederationCreatedEntry = None,
):
nonlocal client
asyncio.create_task(
signals.add_background_task(
federate_created_entries(client, sender, created_entry)
)

Expand All @@ -202,6 +203,9 @@ async def federate_created_entries_pass_client(
case HandlerEvent.CLOSED:
return
case HandlerEvent.DATA:
print(
f"Got new data in ActivityPub inbox: {pprint.pformat(data)}"
)
logger.info(
"Got new data in ActivityPub inbox: %s", pprint.pformat(data)
)
Expand Down Expand Up @@ -251,6 +255,9 @@ async def federate_created_entries_pass_client(
client, claim=claim
)
except Exception as ex:
print(ex)
import traceback
traceback.print_exc()
logger.error(ex)
logger.exception(ex)
logger.error(json.dumps(data))
Expand Down
45 changes: 43 additions & 2 deletions tests/test_federation_activitypub_bovine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import docutils.nodes
import docutils.utils

from scitt_emulator.tree_algs import TREE_ALGS
from scitt_emulator.signals import SCITTSignals
from scitt_emulator.client import ClaimOperationError
from scitt_emulator.federation_activitypub_bovine import (
SCITTFederationActivityPubBovine,
Expand Down Expand Up @@ -105,12 +107,46 @@ async def make_client_session(self):
}
)
)

# ensure service parameters include methods service can federate by
workspace_path = tmp_path / handle_name / "workspace"
storage_path = workspace_path / "storage"
storage_path.mkdir(parents=True)
service_parameters_path = workspace_path / "service_parameters.json"
tree_alg = "CCF"
TREE_ALGS[tree_alg](
signals=SCITTSignals(),
storage_path=storage_path,
service_parameters_path=service_parameters_path,
).initialize_service()
service_parameters = json.loads(service_parameters_path.read_text())
# TODO Decide on how we offer extensions for more federation protocols
# and declare which version is in use. We would need an extension doc
# which describes the format of this blob and how to intrepret it
# https://github.com/ietf-wg-scitt/draft-ietf-scitt-architecture/issues/79#issuecomment-1797016940
service_parameters["federation"] = [
{
"protocol": "https://github.com/w3c/activitypub",
"version": "https://github.com/w3c/activitypub/commit/cda0c902317f194daeeb50b2df0225bca5b06f52",
"activitypub": {
"actors": {
handle_name: {
# SCITT_ALL_SUBJECTS would be a special value
# We'd want to have extension docs explain more
"subjects": "SCITT_ALL_SUBJECTS",
}
}
}
}
]
service_parameters_path.write_text(json.dumps(service_parameters))

services[handle_name] = Service(
{
"middleware": [TestSCITTFederationActivityPubBovine],
"middleware_config_path": [middleware_config_path],
"tree_alg": "CCF",
"workspace": tmp_path / handle_name / "workspace",
"workspace": workspace_path,
"error_rate": 0,
"use_lro": False,
},
Expand Down Expand Up @@ -158,6 +194,8 @@ async def make_client_session(self):
)
)

# TODO Poll following endpoints until all services are following each other

# Create claims in each instance
claims = []
for handle_name, service in services.items():
Expand Down Expand Up @@ -209,7 +247,10 @@ async def make_client_session(self):
}
)

# time.sleep(100)
time.sleep(1)
import pprint
pprint.pprint(claims)
time.sleep(100)

# Test that we can download claims from all instances federated with
for handle_name, service in services.items():
Expand Down

0 comments on commit 8e4d6f9

Please sign in to comment.