diff --git a/src/_zkapauthorizer/tests/storage_common.py b/src/_zkapauthorizer/tests/storage_common.py index 6ae3a4c2c67fa2077e537ec3f33d06c96a94b4d1..4baf4de7b89ff6ab3c0ea7145b5d0fa347f3a8e9 100644 --- a/src/_zkapauthorizer/tests/storage_common.py +++ b/src/_zkapauthorizer/tests/storage_common.py @@ -20,6 +20,11 @@ from twisted.python.filepath import ( FilePath, ) +from .strategies import ( + # Not really a strategy... + bytes_for_share, +) + def cleanup_storage_server(storage_server): """ Delete all of the shares held by the given storage server. @@ -35,3 +40,36 @@ def cleanup_storage_server(storage_server): for p in start.walk(): if p is not start: p.remove() + + +def write_toy_shares( + storage_server, + storage_index, + renew_secret, + cancel_secret, + sharenums, + size, + canary, +): + """ + Write some immutable shares to the given storage server. + + :param allmydata.storage.server.StorageServer storage_server: + :param bytes storage_index: + :param bytes renew_secret: + :param bytes cancel_secret: + :param set[int] sharenums: + :param int size: + :param IRemoteReference canary: + """ + _, allocated = storage_server.remote_allocate_buckets( + storage_index, + renew_secret, + cancel_secret, + sharenums, + size, + canary=canary, + ) + for (sharenum, writer) in allocated.items(): + writer.remote_write(0, bytes_for_share(sharenum, size)) + writer.remote_close() diff --git a/src/_zkapauthorizer/tests/test_storage_protocol.py b/src/_zkapauthorizer/tests/test_storage_protocol.py index 9789d50a63e7c359de9424e42b70060bd35fd10d..f567d320928009eb74d5b3e45efb30d9eff954cf 100644 --- a/src/_zkapauthorizer/tests/test_storage_protocol.py +++ b/src/_zkapauthorizer/tests/test_storage_protocol.py @@ -91,6 +91,7 @@ from .fixtures import ( ) from .storage_common import ( cleanup_storage_server, + write_toy_shares, ) from ..api import ( ZKAPAuthorizerStorageServer, @@ -626,36 +627,3 @@ def write_vector_to_read_vector(write_vector): write vector. """ return (write_vector[0], len(write_vector[1])) - - -def write_toy_shares( - storage_server, - storage_index, - renew_secret, - cancel_secret, - sharenums, - size, - canary, -): - """ - Write some immutable shares to the given storage server. - - :param allmydata.storage.server.StorageServer storage_server: - :param bytes storage_index: - :param bytes renew_secret: - :param bytes cancel_secret: - :param set[int] sharenums: - :param int size: - :param IRemoteReference canary: - """ - _, allocated = storage_server.remote_allocate_buckets( - storage_index, - renew_secret, - cancel_secret, - sharenums, - size, - canary=canary, - ) - for (sharenum, writer) in allocated.items(): - writer.remote_write(0, bytes_for_share(sharenum, size)) - writer.remote_close()