From 683f62a2f06eefb6a9f5d5fd26d5308d37366f57 Mon Sep 17 00:00:00 2001 From: Paul Hewlett <1104895+eccles@users.noreply.github.com> Date: Wed, 29 May 2024 15:49:00 +0100 Subject: [PATCH] Simple Hash is removed. (#265) * Simple Hash is removed. The proof mechanism is now not specified anywhere and accepts and uses whatever the backend supples. The customer can still specify the proof mechanism as MERKLE_LOG but cannot specify any other value. AB#9189 --- README.rst | 22 +-- archivist/assets.py | 2 +- archivist/confirmer.py | 1 - ...nce using CURRENT OUTSTANDING Policy.ipynb | 4 - ... Asset Compliance using SINCE Policy.ipynb | 2 - .../notebooks/Checking the Dog's Weight.ipynb | 1 - ...Create Artist and Album Release Info.ipynb | 2 - .../Create Event with Verified Domain.ipynb | 6 +- .../notebooks/Feeding the Dog Hourly.ipynb | 1 - .../Feeding the Dog in a Timely Manner.ipynb | 1 - archivist/notebooks/Feeding the Dog.ipynb | 1 - ...st and Additional Album Release Info.ipynb | 2 - .../Find Artist and Create Cover Art.ipynb | 2 - .../Playing Fetch Every 5 Minutes.ipynb | 1 - ...lbum Release Info with Record Labels.ipynb | 1 - ...Sharing Album Release Info with User.ipynb | 1 - ...ring Artist Asset with Record Labels.ipynb | 1 - .../Sharing Artist Asset with User.ipynb | 1 - archivist/parser.py | 17 -- archivist/proof_mechanism.py | 7 +- docs/code/index.rst | 1 - docs/code/proof_mechanism.rst | 10 - docs/fixtures.rst | 6 - examples/applications_registration.py | 4 - examples/create_asset.py | 13 +- examples/create_event.py | 5 +- examples/sbom_release.py | 2 - examples/scan_test.py | 2 - examples/sharing_asset.py | 18 +- functests/execaccess_policies.py | 2 - functests/execapplications.py | 9 - functests/execassets.py | 168 ++--------------- functests/execpublicassets.py | 43 +---- unittests/testaccess_policies.py | 2 +- unittests/testassets.py | 171 ++++++------------ unittests/testassetsconstants.py | 67 ++----- unittests/testassetslist.py | 14 +- unittests/testassetsread.py | 8 +- unittests/testnotebooks.py | 1 - unittests/testproof_mechanism.py | 28 +-- 40 files changed, 132 insertions(+), 518 deletions(-) delete mode 100644 docs/code/proof_mechanism.rst diff --git a/README.rst b/README.rst index 9b85e7ba..7e35f46c 100644 --- a/README.rst +++ b/README.rst @@ -55,7 +55,6 @@ You can then use the examples code to create assets (see examples directory): from os import getenv from archivist.archivist import Archivist - from archivist.proof_mechanism import ProofMechanism def create_asset(arch): @@ -85,21 +84,13 @@ You can then use the examples code to create assets (see examples directory): # it does not start with arc_ } # - # Select the mechanism used to prove evidence for the asset. If the selected proof - # mechanism is not enabled for your tenant then an error will occur. - # If unspecified then SIMPLE_HASH is used. - props = { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - } - - # The first argument are the properties of the asset - # The second argument are the attributes of the asset - # The third argument is wait for confirmation: + # The first argument are the attributes of the asset + # The second argument is wait for confirmation: # If @confirm@ is True then this function will not - # return until the asset is confirmed on the blockchain and ready + # return until the asset is confirmed and ready # to accept events (or an error occurs) # - return arch.assets.create(props=props, attrs=attrs, confirm=True) + return arch.assets.create(attrs=attrs, confirm=True) # alternatively if some work can be done whilst the asset is confirmed then this call can be # replaced by a two-step alternative: @@ -131,9 +122,8 @@ You can then use the examples code to create assets (see examples directory): client_secret = tokenfile.read().strip() # Initialize connection to Archivist. max_time is the time to wait for confirmation - # of an asset or event creation - the default is 1200 seconds but one can optionally - # specify a different value here particularly when creating assets on SIMPLE_HASH - # as confirmation times are much shorter in this case. + # of an asset or event creation - the default is 300 seconds but one can optionally + # specify a different value. with arch = Archivist( "https://app.datatrails.ai", (client_id, client_secret), diff --git a/archivist/assets.py b/archivist/assets.py index 209e5a95..f5e3ee31 100644 --- a/archivist/assets.py +++ b/archivist/assets.py @@ -127,7 +127,7 @@ def create( Creates asset with defined properties and attributes. Args: - props (dict): Properties - usually only the proof_mechanism setting + props (dict): Properties attrs (dict): attributes of created asset. confirm (bool): if True wait for asset to be confirmed. diff --git a/archivist/confirmer.py b/archivist/confirmer.py index 420cf98d..82b7d4f3 100644 --- a/archivist/confirmer.py +++ b/archivist/confirmer.py @@ -101,7 +101,6 @@ def _wait_for_confirmation(self: Managers, identity: str) -> ReturnTypes: f"confirmation for {identity} FAILED - this is unusable" ) - # Simple hash and merkleLog if status in ( ConfirmationStatus.CONFIRMED.name, ConfirmationStatus.COMMITTED.name, diff --git a/archivist/notebooks/Check Asset Compliance using CURRENT OUTSTANDING Policy.ipynb b/archivist/notebooks/Check Asset Compliance using CURRENT OUTSTANDING Policy.ipynb index ec45eb23..9f4f158e 100644 --- a/archivist/notebooks/Check Asset Compliance using CURRENT OUTSTANDING Policy.ipynb +++ b/archivist/notebooks/Check Asset Compliance using CURRENT OUTSTANDING Policy.ipynb @@ -40,7 +40,6 @@ "from archivist.archivist import Archivist\n", "from archivist.compliance_policy_requests import CompliancePolicyCurrentOutstanding\n", "from archivist.constants import ASSET_BEHAVIOURS\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger\n", "\n", "filterwarnings(\"ignore\", message=\"Unverified HTTPS request\")" @@ -164,7 +163,6 @@ " },\n", " ],\n", " \"behaviours\": ASSET_BEHAVIOURS,\n", - " \"proof_mechanism\": ProofMechanism.SIMPLE_HASH.name,\n", " \"attributes\": {\n", " \"arc_display_name\": \"Gringott's Vault 2\",\n", " \"arc_description\": \"Main door to the second level security vault in Gringott's Wizarding Bank\",\n", @@ -355,7 +353,6 @@ " \"owner\": \"0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce\",\n", " \"at_time\": \"2023-01-16T11:51:30Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"827586838445807967\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866\"\n", @@ -377,7 +374,6 @@ " \"owner\": \"0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce\",\n", " \"at_time\": \"2023-01-16T11:51:30Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"827586838445807967\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866\"\n", diff --git a/archivist/notebooks/Check Asset Compliance using SINCE Policy.ipynb b/archivist/notebooks/Check Asset Compliance using SINCE Policy.ipynb index d1ef9829..f38f08c6 100644 --- a/archivist/notebooks/Check Asset Compliance using SINCE Policy.ipynb +++ b/archivist/notebooks/Check Asset Compliance using SINCE Policy.ipynb @@ -300,7 +300,6 @@ " \"owner\": \"0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce\",\n", " \"at_time\": \"2023-01-16T11:52:27Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"827586838445807967\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866\"\n", @@ -322,7 +321,6 @@ " \"owner\": \"0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce\",\n", " \"at_time\": \"2023-01-16T11:52:27Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"827586838445807967\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866\"\n", diff --git a/archivist/notebooks/Checking the Dog's Weight.ipynb b/archivist/notebooks/Checking the Dog's Weight.ipynb index ad0de1d8..33760334 100644 --- a/archivist/notebooks/Checking the Dog's Weight.ipynb +++ b/archivist/notebooks/Checking the Dog's Weight.ipynb @@ -48,7 +48,6 @@ "from archivist.compliance_policy_requests import (\n", " CompliancePolicyRichness,\n", ")\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, diff --git a/archivist/notebooks/Create Artist and Album Release Info.ipynb b/archivist/notebooks/Create Artist and Album Release Info.ipynb index 56539ae3..56af0879 100644 --- a/archivist/notebooks/Create Artist and Album Release Info.ipynb +++ b/archivist/notebooks/Create Artist and Album Release Info.ipynb @@ -44,7 +44,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, @@ -207,7 +206,6 @@ " \"owner\": \"0x5284e740A744F075E402f7fB0c4485532ddf4Af8\",\n", " \"at_time\": \"2023-06-02T20:57:01Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"8275868384\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\"\n", diff --git a/archivist/notebooks/Create Event with Verified Domain.ipynb b/archivist/notebooks/Create Event with Verified Domain.ipynb index 2b843075..09cb5349 100644 --- a/archivist/notebooks/Create Event with Verified Domain.ipynb +++ b/archivist/notebooks/Create Event with Verified Domain.ipynb @@ -232,11 +232,8 @@ " # The first argument is the attributes of the asset\n", " # The second argument is wait for confirmation:\n", " # If @confirm@ is True then this function will not\n", - " # return until the asset is confirmed on the blockchain and ready\n", + " # return until the asset is confirmed and ready\n", " # to accept events (or an error occurs)\n", - " # After an asset is submitted to the blockchain (submitted),\n", - " # it will be in the \"Pending\" status.\n", - " # Once it is added to the blockchain, the status will be changed to \"Confirmed\"\n", " return arch.assets.create(attrs=attrs, confirm=True)" ] }, @@ -276,7 +273,6 @@ " \"confirmation_status\": \"CONFIRMED\",\n", " \"identity\": \"assets/0047715f-368e-4a62-aa04-48e6fa974e85\",\n", " \"owner\": \"0xe889E67FdBa658C6f27ccBDa98D9d1B5500Dbbce\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"public\": false,\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", " \"tenant_identity\": \"tenant/9bfb80ee-81f6-40dc-b5c7-1c7fb2fb9866\",\n", diff --git a/archivist/notebooks/Feeding the Dog Hourly.ipynb b/archivist/notebooks/Feeding the Dog Hourly.ipynb index cca1e9d2..1f8b131b 100644 --- a/archivist/notebooks/Feeding the Dog Hourly.ipynb +++ b/archivist/notebooks/Feeding the Dog Hourly.ipynb @@ -48,7 +48,6 @@ "from archivist.compliance_policy_requests import (\n", " CompliancePolicyPeriodOutstanding,\n", ")\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, diff --git a/archivist/notebooks/Feeding the Dog in a Timely Manner.ipynb b/archivist/notebooks/Feeding the Dog in a Timely Manner.ipynb index a9dbfe38..28a54c8f 100644 --- a/archivist/notebooks/Feeding the Dog in a Timely Manner.ipynb +++ b/archivist/notebooks/Feeding the Dog in a Timely Manner.ipynb @@ -48,7 +48,6 @@ "from archivist.compliance_policy_requests import (\n", " CompliancePolicyDynamicTolerance,\n", ")\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, diff --git a/archivist/notebooks/Feeding the Dog.ipynb b/archivist/notebooks/Feeding the Dog.ipynb index dd003522..846e64ad 100644 --- a/archivist/notebooks/Feeding the Dog.ipynb +++ b/archivist/notebooks/Feeding the Dog.ipynb @@ -48,7 +48,6 @@ "from archivist.compliance_policy_requests import (\n", " CompliancePolicyCurrentOutstanding,\n", ")\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, diff --git a/archivist/notebooks/Find Artist and Additional Album Release Info.ipynb b/archivist/notebooks/Find Artist and Additional Album Release Info.ipynb index 0c1c25d8..8278fd5f 100644 --- a/archivist/notebooks/Find Artist and Additional Album Release Info.ipynb +++ b/archivist/notebooks/Find Artist and Additional Album Release Info.ipynb @@ -41,7 +41,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, @@ -208,7 +207,6 @@ " \"owner\": \"0x5284e740A744F075E402f7fB0c4485532ddf4Af8\",\n", " \"at_time\": \"2023-06-02T21:33:34Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"8275868384\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\"\n", diff --git a/archivist/notebooks/Find Artist and Create Cover Art.ipynb b/archivist/notebooks/Find Artist and Create Cover Art.ipynb index d7f2a4bb..8a044255 100644 --- a/archivist/notebooks/Find Artist and Create Cover Art.ipynb +++ b/archivist/notebooks/Find Artist and Create Cover Art.ipynb @@ -41,7 +41,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, @@ -235,7 +234,6 @@ " \"owner\": \"0x5284e740A744F075E402f7fB0c4485532ddf4Af8\",\n", " \"at_time\": \"2023-06-02T21:01:56Z\",\n", " \"storage_integrity\": \"TENANT_STORAGE\",\n", - " \"proof_mechanism\": \"SIMPLE_HASH\",\n", " \"chain_id\": \"8275868384\",\n", " \"public\": false,\n", " \"tenant_identity\": \"tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1\"\n", diff --git a/archivist/notebooks/Playing Fetch Every 5 Minutes.ipynb b/archivist/notebooks/Playing Fetch Every 5 Minutes.ipynb index 7e2d0d1e..b2b588ed 100644 --- a/archivist/notebooks/Playing Fetch Every 5 Minutes.ipynb +++ b/archivist/notebooks/Playing Fetch Every 5 Minutes.ipynb @@ -48,7 +48,6 @@ "from archivist.compliance_policy_requests import (\n", " CompliancePolicySince,\n", ")\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger" ] }, diff --git a/archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb b/archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb index 80ff76cf..eac2895d 100644 --- a/archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb +++ b/archivist/notebooks/Sharing Album Release Info with Record Labels.ipynb @@ -50,7 +50,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger\n", "from archivist.constants import ASSET_BEHAVIOURS" ] diff --git a/archivist/notebooks/Sharing Album Release Info with User.ipynb b/archivist/notebooks/Sharing Album Release Info with User.ipynb index 07ec7e42..13bf7b7c 100644 --- a/archivist/notebooks/Sharing Album Release Info with User.ipynb +++ b/archivist/notebooks/Sharing Album Release Info with User.ipynb @@ -44,7 +44,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger\n", "from archivist.constants import ASSET_BEHAVIOURS" ] diff --git a/archivist/notebooks/Sharing Artist Asset with Record Labels.ipynb b/archivist/notebooks/Sharing Artist Asset with Record Labels.ipynb index 5c0ebce7..722254cf 100644 --- a/archivist/notebooks/Sharing Artist Asset with Record Labels.ipynb +++ b/archivist/notebooks/Sharing Artist Asset with Record Labels.ipynb @@ -51,7 +51,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger\n", "from archivist.constants import ASSET_BEHAVIOURS" ] diff --git a/archivist/notebooks/Sharing Artist Asset with User.ipynb b/archivist/notebooks/Sharing Artist Asset with User.ipynb index e2e5ab2f..ab6a1724 100644 --- a/archivist/notebooks/Sharing Artist Asset with User.ipynb +++ b/archivist/notebooks/Sharing Artist Asset with User.ipynb @@ -44,7 +44,6 @@ "from dotenv import load_dotenv\n", "\n", "from archivist.archivist import Archivist\n", - "from archivist.proof_mechanism import ProofMechanism\n", "from archivist.logger import set_logger\n", "from archivist.constants import ASSET_BEHAVIOURS" ] diff --git a/archivist/parser.py b/archivist/parser.py index ab0a52c9..278ec890 100644 --- a/archivist/parser.py +++ b/archivist/parser.py @@ -14,7 +14,6 @@ from .archivist import Archivist from .dictmerge import _deepmerge from .logger import set_logger -from .proof_mechanism import ProofMechanism from .utils import get_auth filterwarnings("ignore", message="Unverified HTTPS request") @@ -81,15 +80,6 @@ def common_parser(description: str): default="https://app.datatrails.ai", help="url of Archivist service", ) - parser.add_argument( - "-p", - "--proof-mechanism", - type=ProofMechanism, - action=EnumAction, - dest="proof_mechanism", - default=None, - help="mechanism for proving the evidence for events on the Asset", - ) parser.add_argument( "--auth-token", type=str, @@ -152,13 +142,6 @@ def endpoint(args): arch = None LOGGER.info("Initializing connection to DATATRAILS...") fixtures = {} - if args.proof_mechanism is not None: - fixtures = { - "assets": { - "proof_mechanism": args.proof_mechanism.name, - }, - } - if args.namespace is not None: fixtures = _deepmerge( fixtures, diff --git a/archivist/proof_mechanism.py b/archivist/proof_mechanism.py index e23ef685..5067615b 100644 --- a/archivist/proof_mechanism.py +++ b/archivist/proof_mechanism.py @@ -3,6 +3,8 @@ Enumerated type that allows user to select the proof_mechanism option when creating an asset. + Currently there is only one proof mechanism so this code is here only for + compatibility. """ # pylint: disable=unused-private-member @@ -14,8 +16,7 @@ class ProofMechanism(Enum): """Enumerate proof mechanism options""" # previously used but now removed - __RESERVED = 1 - #: Assets and events are proven using a hash of the originator's evidence - SIMPLE_HASH = 2 + __RESERVED1 = 1 + __RESERVED2 = 2 #: Assets and events are proven using a merkle log hash of the originator's evidence MERKLE_LOG = 3 diff --git a/docs/code/index.rst b/docs/code/index.rst index f62e1574..893d4da5 100644 --- a/docs/code/index.rst +++ b/docs/code/index.rst @@ -22,4 +22,3 @@ Shows all code timestamp errors - proof_mechanism diff --git a/docs/code/proof_mechanism.rst b/docs/code/proof_mechanism.rst deleted file mode 100644 index 5d520b90..00000000 --- a/docs/code/proof_mechanism.rst +++ /dev/null @@ -1,10 +0,0 @@ - -.. _proof_mechanismref: - -Proof Mechanism Enumeration ----------------------------- - - -.. automodule:: archivist.proof_mechanism - :members: - diff --git a/docs/fixtures.rst b/docs/fixtures.rst index 19666eaf..c994609c 100644 --- a/docs/fixtures.rst +++ b/docs/fixtures.rst @@ -12,7 +12,6 @@ and locations. from archivist.archivist import Archivist from archivist.errors import ArchivistError - from archivist.proof_mechanism import ProofMechanism # Oauth2 token that grants access with open(".auth_token", mode='r', encoding="utf-8") as tokenfile: @@ -22,11 +21,6 @@ and locations. ledger = Archivist( "https://app.datatrails.ai", authtoken, - fixtures = { - "assets": { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - } - }, ) # lets define doors in our namespace that reside on the ledger... diff --git a/examples/applications_registration.py b/examples/applications_registration.py index 817f0606..9e239374 100644 --- a/examples/applications_registration.py +++ b/examples/applications_registration.py @@ -13,7 +13,6 @@ from warnings import filterwarnings from archivist.archivist import Archivist -from archivist.proof_mechanism import ProofMechanism filterwarnings("ignore", message="Unverified HTTPS request") @@ -101,9 +100,6 @@ def main(): ) as arch1: # create an asset asset = arch1.assets.create( - props={ - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - }, attrs={ "arc_display_name": "display_name", "arc_description": "display_description", diff --git a/examples/create_asset.py b/examples/create_asset.py index fb8f51f4..7df12af1 100644 --- a/examples/create_asset.py +++ b/examples/create_asset.py @@ -11,7 +11,6 @@ from archivist.archivist import Archivist from archivist.logger import set_logger -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth filterwarnings("ignore", message="Unverified HTTPS request") @@ -44,14 +43,9 @@ def create_asset(arch): # it does not start with arc_ } # - # Select the mechanism used to prove evidence for the asset. If the selected proof - # mechanism is not enabled for your tenant then an error will occur. - # If unspecified then SIMPLE_HASH is used. - # # Optionally one can create a publicasset by specifying public as True # If unspecified a private asset wll be created. props = { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "public": True, } @@ -59,7 +53,7 @@ def create_asset(arch): # The second argument are the attributes of the asset # The third argument is wait for confirmation: # If @confirm@ is True then this function will not - # return until the asset is confirmed on the blockchain and ready + # return until the asset is confirmed and ready # to accept events (or an error occurs) # return arch.assets.create(props=props, attrs=attrs, confirm=True) @@ -101,9 +95,8 @@ def main(): ) # Initialize connection to Archivist. max_time is the time to wait for confirmation - # of an asset or event creation - the default is 1200 seconds but one can optionally - # specify a different value here particularly when creating assets on SIMPLE_HASH - # as confirmation times are much shorter in this case. + # of an asset or event creation - the default is 300 seconds but one can optionally + # specify a different value. with Archivist( "https://app.datatrails.ai", auth, diff --git a/examples/create_event.py b/examples/create_event.py index 80394d49..4d991789 100644 --- a/examples/create_event.py +++ b/examples/create_event.py @@ -119,11 +119,8 @@ def create_asset(arch): # The first argument is the attributes of the asset # The second argument is wait for confirmation: # If @confirm@ is True then this function will not - # return until the asset is confirmed on the blockchain and ready + # return until the asset is confirmed and ready # to accept events (or an error occurs) - # After an asset is submitted to the blockchain (submitted), - # it will be in the "Pending" status. - # Once it is added to the blockchain, the status will be changed to "Confirmed" return arch.assets.create(attrs=attrs, confirm=True) diff --git a/examples/sbom_release.py b/examples/sbom_release.py index b1e841be..f1382831 100644 --- a/examples/sbom_release.py +++ b/examples/sbom_release.py @@ -12,7 +12,6 @@ from archivist.archivist import Archivist from archivist.constants import ASSET_BEHAVIOURS, SBOM_PACKAGE, SBOM_RELEASE -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth filterwarnings("ignore", message="Unverified HTTPS request") @@ -43,7 +42,6 @@ def sbom_release(arch, release, sbom_filename): }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_display_type": SBOM_PACKAGE, diff --git a/examples/scan_test.py b/examples/scan_test.py index 83f1eb8f..5e0d1b99 100644 --- a/examples/scan_test.py +++ b/examples/scan_test.py @@ -10,7 +10,6 @@ from archivist.archivist import Archivist from archivist.constants import ASSET_BEHAVIOURS -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth filterwarnings("ignore", message="Unverified HTTPS request") @@ -50,7 +49,6 @@ def scan_test(arch, datestring, scanned_expected=False): }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": asset_name, "arc_namespace": "namespace", diff --git a/examples/sharing_asset.py b/examples/sharing_asset.py index 14b1ebe4..be1538fb 100644 --- a/examples/sharing_asset.py +++ b/examples/sharing_asset.py @@ -13,7 +13,6 @@ from archivist.archivist import Archivist from archivist.constants import ASSET_BEHAVIOURS, SUBJECTS_SELF_ID from archivist.logger import set_logger -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth filterwarnings("ignore", message="Unverified HTTPS request") @@ -37,22 +36,14 @@ def create_example_asset(arch, label): "ext_vendor_name": label, } - # Select the mechanism used to prove evidence for the asset. If the selected proof - # mechanism is not enabled for your tenant then an error will occur. - # If unspecified then SIMPLE_HASH is used. - # - props = { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - } - # The first argument is the properties of the asset # The second argument is the attributes of the asset # The third argument is wait for confirmation: # If @confirm@ is True then this function will not - # return until the asset is confirmed on the blockchain and ready + # return until the asset is confirmed and ready # to accept events (or an error occurs) # - return arch.assets.create(props=props, attrs=attrs, confirm=True) + return arch.assets.create(attrs=attrs, confirm=True) def create_archivist(label): @@ -65,9 +56,8 @@ def create_archivist(label): auth_token=getenv(f"DATATRAILS_AUTHTOKEN_{label}"), ) # Initialize connection to Archivist. max_time is the time to wait for confirmation - # of an asset or event creation - the default is 1200 seconds but one can optionally - # specify a different value here particularly when creating assets on SIMPLE_HASH - # as confirmation times are much shorter in this case. + # of an asset or event creation - the default is 300 seconds but one can optionally + # specify a different value. return Archivist( "https://app.datatrails.ai", auth, diff --git a/functests/execaccess_policies.py b/functests/execaccess_policies.py index ffd28726..7fe6559c 100644 --- a/functests/execaccess_policies.py +++ b/functests/execaccess_policies.py @@ -12,7 +12,6 @@ from archivist import logger from archivist.archivist import Archivist from archivist.constants import ASSET_BEHAVIOURS -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth from .constants import TestCase @@ -76,7 +75,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", diff --git a/functests/execapplications.py b/functests/execapplications.py index aab2713a..489ba32e 100644 --- a/functests/execapplications.py +++ b/functests/execapplications.py @@ -12,7 +12,6 @@ from archivist import logger from archivist.archivist import Archivist from archivist.errors import ArchivistUnauthenticatedError -from archivist.proof_mechanism import ProofMechanism from archivist.utils import get_auth from .constants import TestCase @@ -237,18 +236,10 @@ def test_archivist_token(self): traffic_light = deepcopy(ATTRS) traffic_light["arc_display_type"] = "Traffic light with violation camera" asset = new_arch.assets.create( - props={ - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - }, attrs=traffic_light, confirm=True, ) LOGGER.debug("create asset %s", json_dumps(asset, indent=4)) - self.assertEqual( - asset["proof_mechanism"], - ProofMechanism.SIMPLE_HASH.name, - msg="Incorrect asset proof mechanism", - ) identity = asset["identity"] props = { "operation": "Record", diff --git a/functests/execassets.py b/functests/execassets.py index 06afe89a..10fdceb0 100644 --- a/functests/execassets.py +++ b/functests/execassets.py @@ -33,48 +33,12 @@ "some_custom_attribute": "value", } -SIMPLE_HASH = { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, -} MERKLE_LOG = { "proof_mechanism": ProofMechanism.MERKLE_LOG.name, } ASSET_NAME = "Telephone with 2 attachments - one bad or not scanned 2022-03-01" -REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH = { - "selector": [ - { - "attributes": [ - "arc_display_name", - "arc_namespace", - ] - }, - ], - "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - "attributes": { - "arc_description": "Traffic flow control light at A603 North East", - "arc_display_name": f"{ASSET_NAME} (SIMPLE_HASH)", - "arc_display_type": "Traffic light with violation camera", - "arc_firmware_version": "1.0", - "arc_namespace": getenv("DATATRAILS_UNIQUE_ID"), - "arc_serial_number": "vtl-x4-07", - "some_custom_attribute": "value", - }, - "attachments": [ - { - "filename": "functests/test_resources/telephone.jpg", - "content_type": "image/jpg", - "attachment": "telephone", - }, - { - "url": "https://secure.eicar.org/eicarcom2.zip", - "content_type": "application/zip", - "attachment": "zipfile", - }, - ], -} -REQUEST_EXISTS_ATTACHMENTS_MERKLE_LOG = { +REQUEST_EXISTS_ATTACHMENTS = { "selector": [ { "attributes": [ @@ -84,10 +48,9 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.MERKLE_LOG.name, "attributes": { "arc_description": "Traffic flow control light at A603 North East", - "arc_display_name": f"{ASSET_NAME} (MERKLE_LOG)", + "arc_display_name": f"{ASSET_NAME}", "arc_display_type": "Traffic light with violation camera", "arc_firmware_version": "1.0", "arc_namespace": getenv("DATATRAILS_UNIQUE_ID"), @@ -139,21 +102,15 @@ def tearDown(self): self.attrs = None self.traffic_light = None - def test_asset_create_simple_hash(self): + def test_asset_create(self): """ - Test asset creation uses simple hash proof mechanism + Test asset creation """ asset = self.arch.assets.create( attrs=self.traffic_light, confirm=True, - props={"proof_mechanism": ProofMechanism.SIMPLE_HASH.name}, ) LOGGER.debug("asset %s", json_dumps(asset, sort_keys=True, indent=4)) - self.assertEqual( - asset["proof_mechanism"], - ProofMechanism.SIMPLE_HASH.name, - msg="Incorrect asset proof mechanism", - ) tenancy = self.arch.tenancies.publicinfo(asset["tenant_identity"]) LOGGER.debug("tenancy %s", json_dumps(tenancy, sort_keys=True, indent=4)) @@ -175,20 +132,12 @@ def test_asset_create_merkle_log(self): tenancy = self.arch.tenancies.publicinfo(asset["tenant_identity"]) LOGGER.debug("tenancy %s", json_dumps(tenancy, sort_keys=True, indent=4)) - def test_asset_create_with_fixtures_simple_hash(self): + def test_asset_create_with_fixtures(self): """ Test creation with fixtures """ - # creates simple_hash endpoint - simple_hash = copy(self.arch) - simple_hash.fixtures = { - "assets": { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, - }, - } - - # create traffic lights endpoint from simple_hash - traffic_lights = copy(simple_hash) + # create traffic lights endpoint + traffic_lights = copy(self.arch) traffic_lights.fixtures = { "assets": { "attributes": { @@ -226,107 +175,12 @@ def test_asset_create_with_fixtures_simple_hash(self): msg="Incorrect number of fancy_traffic_lights", ) - def test_asset_create_with_fixtures_merkle_log(self): - """ - Test creation with fixtures - """ - # creates simple_hash endpoint - simple_hash = copy(self.arch) - simple_hash.fixtures = { - "assets": { - "proof_mechanism": ProofMechanism.MERKLE_LOG.name, - }, - } - - # create traffic lights endpoint from simple_hash - traffic_lights = copy(simple_hash) - traffic_lights.fixtures = { - "assets": { - "attributes": { - "arc_display_type": "Traffic light with violation camera (merkle_log)", - "arc_namespace": f"functests {uuid4()}", - }, - }, - } - traffic_lights.assets.create( - props=MERKLE_LOG, - attrs=self.attrs, - confirm=True, - ) - self.assertEqual( - traffic_lights.assets.count(), - 1, - msg="Incorrect number of traffic_lights", - ) - - # create fancy traffic lights endpoint from traffic lights - fancy_traffic_lights = copy(traffic_lights) - fancy_traffic_lights.fixtures = { - "assets": { - "attributes": { - "arc_namespace1": f"functests {uuid4()}", - }, - }, - } - fancy_traffic_lights.assets.create( - props=MERKLE_LOG, - attrs=self.attrs, - confirm=True, - ) - self.assertEqual( - fancy_traffic_lights.assets.count(), - 1, - msg="Incorrect number of fancy_traffic_lights", - ) - - def test_asset_create_event_merkle_log(self): - """ - Test list - """ - asset, existed = self.arch.assets.create_if_not_exists( - REQUEST_EXISTS_ATTACHMENTS_MERKLE_LOG, - confirm=True, - ) - identity = asset["identity"] - - # different behaviours are also different. - props = { - "operation": "Record", - # This event is used to record evidence. - "behaviour": "RecordEvidence", - # Optional Client-claimed time at which the maintenance was performed - "timestamp_declared": "2019-11-27T14:44:19Z", - # Optional Client-claimed identity of person performing the operation - "principal_declared": { - "issuer": "idp.synsation.io/1234", - "subject": "phil.b", - "email": "phil.b@synsation.io", - }, - } - attrs = { - # Required Details of the RecordEvidence request - "arc_description": "Safety conformance approved for version 1.6.", - # Required The evidence to be retained in the asset history - "arc_evidence": "DVA Conformance Report attached", - # Example Client can add any additional information in further attributes, - # including free text or attachments - "conformance_report": "blobs/e2a1d16c-03cd-45a1-8cd0-690831df1273", - } - - event = self.arch.events.create( - identity, props=props, attrs=attrs, confirm=True - ) - LOGGER.debug("event %s", json_dumps(event, sort_keys=True, indent=4)) - - tenancy = self.arch.tenancies.publicinfo(event["tenant_identity"]) - LOGGER.debug("tenancy %s", json_dumps(tenancy, sort_keys=True, indent=4)) - - def test_asset_create_event_simple_hash(self): + def test_asset_create_event(self): """ Test list """ asset, existed = self.arch.assets.create_if_not_exists( - REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH, + REQUEST_EXISTS_ATTACHMENTS, confirm=True, ) identity = asset["identity"] @@ -397,7 +251,7 @@ def test_asset_create_if_not_exists_with_bad_attachment(self): """ asset, existed = self.arch.assets.create_if_not_exists( - REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH, + REQUEST_EXISTS_ATTACHMENTS, confirm=True, ) LOGGER.debug("asset %s", json_dumps(asset, indent=4)) @@ -449,7 +303,7 @@ def test_asset_create_if_not_exists_with_bad_attachment_assetattachment(self): """ asset, existed = self.arch.assets.create_if_not_exists( - REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH, + REQUEST_EXISTS_ATTACHMENTS, confirm=True, ) LOGGER.debug("asset %s", json_dumps(asset, indent=4)) diff --git a/functests/execpublicassets.py b/functests/execpublicassets.py index eb4c0be3..abfa8490 100644 --- a/functests/execpublicassets.py +++ b/functests/execpublicassets.py @@ -10,7 +10,6 @@ from archivist import logger from archivist.archivist import Archivist from archivist.constants import ASSET_BEHAVIOURS -from archivist.proof_mechanism import ProofMechanism from archivist.timestamp import now_timestamp from archivist.utils import get_auth @@ -44,7 +43,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": getenv("DATATRAILS_UNIQUE_ID"), @@ -96,55 +94,18 @@ def tearDown(self): self.attrs = None self.traffic_light = None - def test_public_asset_create_simple_hash(self): + def test_public_asset_create(self): """ - Test public asset creation with the simple hash proof mechanism + Test public asset creation """ asset = self.arch.assets.create( attrs=self.traffic_light, props={ "public": True, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, }, confirm=True, ) LOGGER.debug("asset %s", json_dumps(asset, sort_keys=True, indent=4)) - self.assertEqual( - asset["proof_mechanism"], - ProofMechanism.SIMPLE_HASH.name, - msg="Incorrect asset proof mechanism", - ) - self.assertEqual( - asset["public"], - True, - msg="Asset is not public", - ) - asset_publicurl = self.arch.assets.publicurl(asset["identity"]) - LOGGER.debug("asset_publicurl %s", asset_publicurl) - public = self.arch.Public - count = public.events.count(asset_id=asset_publicurl) - LOGGER.debug("count %s", count) - events = public.events.list(asset_id=asset_publicurl) - LOGGER.debug("events %s", json_dumps(list(events), sort_keys=True, indent=4)) - - def test_public_asset_create_merkle_log(self): - """ - Test public asset creation with the merkle log proof mechanism - """ - asset = self.arch.assets.create( - attrs=self.traffic_light, - props={ - "public": True, - "proof_mechanism": ProofMechanism.MERKLE_LOG.name, - }, - confirm=True, - ) - LOGGER.debug("asset %s", json_dumps(asset, sort_keys=True, indent=4)) - self.assertEqual( - asset["proof_mechanism"], - ProofMechanism.MERKLE_LOG.name, - msg="Incorrect asset proof mechanism", - ) self.assertEqual( asset["public"], True, diff --git a/unittests/testaccess_policies.py b/unittests/testaccess_policies.py index 96e09827..301f2b46 100644 --- a/unittests/testaccess_policies.py +++ b/unittests/testaccess_policies.py @@ -17,7 +17,7 @@ from archivist.errors import ArchivistBadRequestError from .mock_response import MockResponse -from .testassets import RESPONSE_SIMPLE_HASH as ASSET +from .testassets import RESPONSE as ASSET # pylint: disable=missing-docstring # pylint: disable=protected-access diff --git a/unittests/testassets.py b/unittests/testassets.py index 67f8c2ae..29308c9c 100644 --- a/unittests/testassets.py +++ b/unittests/testassets.py @@ -22,16 +22,17 @@ FIXTURES, MERKLE_LOG, PRIMARY_IMAGE, - REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_ATTACHMENTS_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_LOCATION_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_SIMPLE_HASH, - REQUEST_EXISTS_LOCATION_IDENTITY_SIMPLE_HASH, - REQUEST_EXISTS_LOCATION_SIMPLE_HASH, - REQUEST_EXISTS_SIMPLE_HASH, - REQUEST_FIXTURES_KWARGS_SIMPLE_HASH, + REQUEST_EXISTS, + REQUEST_EXISTS_ATTACHMENTS, + REQUEST_EXISTS_KWARGS, + REQUEST_EXISTS_KWARGS_ATTACHMENTS, + REQUEST_EXISTS_KWARGS_LOCATION, + REQUEST_EXISTS_LOCATION, + REQUEST_EXISTS_LOCATION_IDENTITY, + REQUEST_FIXTURES_KWARGS, + REQUEST_KWARGS, REQUEST_KWARGS_MERKLE_LOG, - REQUEST_KWARGS_SIMPLE_HASH, + RESPONSE, RESPONSE_ATTACHMENTS, RESPONSE_EXISTS, RESPONSE_EXISTS_ATTACHMENTS, @@ -39,12 +40,9 @@ RESPONSE_FAILED, RESPONSE_FIXTURES, RESPONSE_LOCATION, - RESPONSE_MERKLE_LOG, - RESPONSE_MERKLE_LOG_UNEQUIVOCAL, RESPONSE_NO_CONFIRMATION, RESPONSE_PENDING, - RESPONSE_SIMPLE_HASH, - SIMPLE_HASH, + RESPONSE_UNEQUIVOCAL, SUBPATH, TestAssetsBase, TestAssetsBaseConfirm, @@ -86,11 +84,9 @@ def test_assets_create(self): Test asset creation """ with mock.patch.object(self.arch.session, "post", autospec=True) as mock_post: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) + mock_post.return_value = MockResponse(200, **RESPONSE) - asset = self.arch.assets.create( - props=SIMPLE_HASH, attrs=ATTRS, confirm=False - ) + asset = self.arch.assets.create(attrs=ATTRS, confirm=False) args, kwargs = mock_post.call_args self.assertEqual( args, @@ -99,12 +95,12 @@ def test_assets_create(self): ) self.assertEqual( kwargs, - REQUEST_KWARGS_SIMPLE_HASH, + REQUEST_KWARGS, msg="CREATE method kwargs called incorrectly", ) self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="CREATE incorrect response", ) self.assertEqual( @@ -120,10 +116,10 @@ def test_assets_create(self): def test_assets_create_merkle_log(self): """ - Test asset creation + Test asset creation specifying merkle log mechanism """ with mock.patch.object(self.arch.session, "post", autospec=True) as mock_post: - mock_post.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG) + mock_post.return_value = MockResponse(200, **RESPONSE) asset = self.arch.assets.create( props=MERKLE_LOG, attrs=ATTRS, confirm=False @@ -141,7 +137,7 @@ def test_assets_create_merkle_log(self): ) self.assertEqual( asset, - RESPONSE_MERKLE_LOG, + RESPONSE, msg="CREATE incorrect response", ) self.assertEqual( @@ -163,7 +159,7 @@ def test_assets_create_with_fixtures(self): arch.fixtures = FIXTURES with mock.patch.object(arch.session, "post", autospec=True) as mock_post: mock_post.return_value = MockResponse(200, **RESPONSE_FIXTURES) - asset = arch.assets.create(props=SIMPLE_HASH, attrs=ATTRS, confirm=False) + asset = arch.assets.create(attrs=ATTRS, confirm=False) args, kwargs = mock_post.call_args self.assertEqual( args, @@ -172,7 +168,7 @@ def test_assets_create_with_fixtures(self): ) self.assertEqual( kwargs, - REQUEST_FIXTURES_KWARGS_SIMPLE_HASH, + REQUEST_FIXTURES_KWARGS, msg="CREATE method kwargs called incorrectly", ) self.assertEqual( @@ -188,11 +184,11 @@ def test_assets_create_with_confirmation_no_confirmed_status(self): with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) + mock_post.return_value = MockResponse(200, **RESPONSE) mock_get.return_value = MockResponse(200, **RESPONSE_NO_CONFIRMATION) with self.assertRaises(ArchivistUnconfirmedError): - self.arch.assets.create(props=SIMPLE_HASH, attrs=ATTRS, confirm=True) + self.arch.assets.create(attrs=ATTRS, confirm=True) def test_assets_create_with_confirmation_failed_status(self): """ @@ -201,28 +197,13 @@ def test_assets_create_with_confirmation_failed_status(self): with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) + mock_post.return_value = MockResponse(200, **RESPONSE) mock_get.side_effect = [ MockResponse(200, **RESPONSE_PENDING), MockResponse(200, **RESPONSE_FAILED), ] with self.assertRaises(ArchivistUnconfirmedError): - self.arch.assets.create(props=SIMPLE_HASH, attrs=ATTRS, confirm=True) - - def test_assets_create_with_confirmation_failed_status_merkle_log(self): - """ - Test asset confirmation - """ - with mock.patch.object( - self.arch.session, "post" - ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG) - mock_get.side_effect = [ - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_FAILED), - ] - with self.assertRaises(ArchivistUnconfirmedError): - self.arch.assets.create(props=MERKLE_LOG, attrs=ATTRS, confirm=True) + self.arch.assets.create(attrs=ATTRS, confirm=True) def test_assets_create_with_confirmation_always_pending_status(self): """ @@ -231,27 +212,7 @@ def test_assets_create_with_confirmation_always_pending_status(self): with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) - mock_get.side_effect = [ - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_PENDING), - ] - with self.assertRaises(ArchivistUnconfirmedError): - self.arch.assets.create(props=SIMPLE_HASH, attrs=ATTRS, confirm=True) - - def test_assets_create_with_confirmation_always_pending_status_merkle_log(self): - """ - Test asset confirmation - """ - with mock.patch.object( - self.arch.session, "post" - ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG) + mock_post.return_value = MockResponse(200, **RESPONSE) mock_get.side_effect = [ MockResponse(200, **RESPONSE_PENDING), MockResponse(200, **RESPONSE_PENDING), @@ -262,7 +223,7 @@ def test_assets_create_with_confirmation_always_pending_status_merkle_log(self): MockResponse(200, **RESPONSE_PENDING), ] with self.assertRaises(ArchivistUnconfirmedError): - self.arch.assets.create(props=MERKLE_LOG, attrs=ATTRS, confirm=True) + self.arch.assets.create(attrs=ATTRS, confirm=True) class TestAssetsCreateConfirm(TestAssetsBaseConfirm): @@ -270,55 +231,35 @@ class TestAssetsCreateConfirm(TestAssetsBaseConfirm): Test Archivist Assets methods with expected confirmation """ - def test_assets_create_with_confirmation_simple_hash(self): + def test_assets_create_with_confirmation(self): """ Test asset creation """ with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) - mock_get.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) - asset = self.arch.assets.create( - props=SIMPLE_HASH, attrs=ATTRS, confirm=True - ) + mock_post.return_value = MockResponse(200, **RESPONSE) + mock_get.return_value = MockResponse(200, **RESPONSE) + asset = self.arch.assets.create(attrs=ATTRS, confirm=True) self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="CREATE method called incorrectly", ) - def test_assets_create_with_confirmation_merkle_log(self): + def test_assets_create_with_confirmation_unequivocal(self): """ Test asset creation """ with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG) - mock_get.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG) - asset = self.arch.assets.create(props=MERKLE_LOG, attrs=ATTRS, confirm=True) + mock_post.return_value = MockResponse(200, **RESPONSE_UNEQUIVOCAL) + mock_get.return_value = MockResponse(200, **RESPONSE_UNEQUIVOCAL) + asset = self.arch.assets.create(attrs=ATTRS, confirm=True) self.assertEqual( asset, - RESPONSE_MERKLE_LOG, - msg="CREATE method called incorrectly", - ) - - def test_assets_create_with_confirmation_merkle_log_unequivocal(self): - """ - Test asset creation - """ - with mock.patch.object( - self.arch.session, "post" - ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse( - 200, **RESPONSE_MERKLE_LOG_UNEQUIVOCAL - ) - mock_get.return_value = MockResponse(200, **RESPONSE_MERKLE_LOG_UNEQUIVOCAL) - asset = self.arch.assets.create(props=MERKLE_LOG, attrs=ATTRS, confirm=True) - self.assertEqual( - asset, - RESPONSE_MERKLE_LOG_UNEQUIVOCAL, + RESPONSE_UNEQUIVOCAL, msg="CREATE method called incorrectly", ) @@ -329,15 +270,13 @@ def test_assets_create_with_explicit_confirmation(self): with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) - mock_get.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) - asset = self.arch.assets.create( - props=SIMPLE_HASH, attrs=ATTRS, confirm=False - ) + mock_post.return_value = MockResponse(200, **RESPONSE) + mock_get.return_value = MockResponse(200, **RESPONSE) + asset = self.arch.assets.create(attrs=ATTRS, confirm=False) self.arch.assets.wait_for_confirmation(asset["identity"]) self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="CREATE method called incorrectly", ) @@ -348,17 +287,15 @@ def test_assets_create_with_confirmation_pending_status(self): with mock.patch.object( self.arch.session, "post" ) as mock_post, mock.patch.object(self.arch.session, "get") as mock_get: - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) + mock_post.return_value = MockResponse(200, **RESPONSE) mock_get.side_effect = [ MockResponse(200, **RESPONSE_PENDING), - MockResponse(200, **RESPONSE_SIMPLE_HASH), + MockResponse(200, **RESPONSE), ] - asset = self.arch.assets.create( - props=SIMPLE_HASH, attrs=ATTRS, confirm=True - ) + asset = self.arch.assets.create(attrs=ATTRS, confirm=True) self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="CREATE method called incorrectly", ) @@ -381,10 +318,10 @@ def test_assets_create_if_not_exists_existing_asset(self): RESPONSE_EXISTS, ], ) - mock_post.return_value = MockResponse(200, **RESPONSE_SIMPLE_HASH) + mock_post.return_value = MockResponse(200, **RESPONSE) asset, existed = self.arch.assets.create_if_not_exists( - data=REQUEST_EXISTS_SIMPLE_HASH, + data=REQUEST_EXISTS, confirm=False, ) mock_post.assert_not_called() @@ -506,8 +443,8 @@ def test_assets_create_if_not_exists_nonexistent_asset(self): Test asset creation """ self.common_assets_create_if_not_exists_nonexistent_asset( - REQUEST_EXISTS_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_SIMPLE_HASH, + REQUEST_EXISTS, + REQUEST_EXISTS_KWARGS, RESPONSE_EXISTS, ) @@ -516,8 +453,8 @@ def test_assets_create_if_not_exists_nonexistent_asset_location(self): Test asset creation """ self.common_assets_create_if_not_exists_nonexistent_asset( - REQUEST_EXISTS_LOCATION_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_LOCATION_SIMPLE_HASH, + REQUEST_EXISTS_LOCATION, + REQUEST_EXISTS_KWARGS_LOCATION, RESPONSE_EXISTS_LOCATION, loc_resp=RESPONSE_LOCATION, ) @@ -527,8 +464,8 @@ def test_assets_create_if_not_exists_nonexistent_asset_location_identity(self): Test asset creation """ self.common_assets_create_if_not_exists_nonexistent_asset( - REQUEST_EXISTS_LOCATION_IDENTITY_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_LOCATION_SIMPLE_HASH, + REQUEST_EXISTS_LOCATION_IDENTITY, + REQUEST_EXISTS_KWARGS_LOCATION, RESPONSE_EXISTS_LOCATION, ) @@ -537,8 +474,8 @@ def test_assets_create_if_not_exists_nonexistent_asset_attachments(self): Test asset creation """ self.common_assets_create_if_not_exists_nonexistent_asset( - REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH, - REQUEST_EXISTS_KWARGS_ATTACHMENTS_SIMPLE_HASH, + REQUEST_EXISTS_ATTACHMENTS, + REQUEST_EXISTS_KWARGS_ATTACHMENTS, RESPONSE_EXISTS_ATTACHMENTS, attachments_resp=RESPONSE_ATTACHMENTS, ) diff --git a/unittests/testassetsconstants.py b/unittests/testassetsconstants.py index 7cd371ce..54e28a93 100644 --- a/unittests/testassetsconstants.py +++ b/unittests/testassetsconstants.py @@ -76,13 +76,11 @@ ], } -# case 1 create -SIMPLE_HASH = { - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, -} MERKLE_LOG = { "proof_mechanism": ProofMechanism.MERKLE_LOG.name, } + +# case 1 create ATTRS = { "arc_firmware_version": "1.0", "arc_serial_number": "vtl-x4-07", @@ -96,9 +94,8 @@ PRIMARY_IMAGE, ], } -REQUEST_SIMPLE_HASH = { +REQUEST = { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_firmware_version": "1.0", "arc_serial_number": "vtl-x4-07", @@ -113,10 +110,9 @@ ], }, } -REQUEST_KWARGS_MERKLE_LOG = { +REQUEST_KWARGS = { "json": { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.MERKLE_LOG.name, "attributes": { "arc_firmware_version": "1.0", "arc_serial_number": "vtl-x4-07", @@ -135,10 +131,11 @@ "authorization": "Bearer authauthauth", }, } -REQUEST_KWARGS_SIMPLE_HASH = { + +REQUEST_KWARGS_MERKLE_LOG = { "json": { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, + "proof_mechanism": ProofMechanism.MERKLE_LOG.name, "attributes": { "arc_firmware_version": "1.0", "arc_serial_number": "vtl-x4-07", @@ -157,26 +154,8 @@ "authorization": "Bearer authauthauth", }, } -RESPONSE_SIMPLE_HASH = { - "identity": IDENTITY, - "behaviours": ASSET_BEHAVIOURS, - "attributes": { - "arc_firmware_version": "1.0", - "arc_serial_number": "vtl-x4-07", - "arc_description": "Traffic flow control light at A603 North East", - "arc_display_type": "Traffic light with violation camera", - "some_custom_attribute": "value", - "arc_display_name": ASSET_NAME, - "arc_attachments": [ - TERTIARY_IMAGE, - SECONDARY_IMAGE, - PRIMARY_IMAGE, - ], - }, - "confirmation_status": "CONFIRMED", -} -RESPONSE_MERKLE_LOG = { +RESPONSE = { "identity": IDENTITY, "behaviours": ASSET_BEHAVIOURS, "attributes": { @@ -195,7 +174,7 @@ "confirmation_status": "COMMITTED", } -RESPONSE_MERKLE_LOG_UNEQUIVOCAL = { +RESPONSE_UNEQUIVOCAL = { "identity": IDENTITY, "behaviours": ASSET_BEHAVIOURS, "attributes": { @@ -215,7 +194,7 @@ } # case 2 create if not exists -REQUEST_EXISTS_SIMPLE_HASH = { +REQUEST_EXISTS = { "selector": [ { "attributes": [ @@ -225,7 +204,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -236,10 +214,9 @@ "some_custom_attribute": "value", }, } -REQUEST_EXISTS_KWARGS_SIMPLE_HASH = { +REQUEST_EXISTS_KWARGS = { "json": { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -271,7 +248,7 @@ } # case 3 create if not exists with attachments -REQUEST_EXISTS_ATTACHMENTS_SIMPLE_HASH = { +REQUEST_EXISTS_ATTACHMENTS = { "selector": [ { "attributes": [ @@ -281,7 +258,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -303,10 +279,9 @@ }, ], } -REQUEST_EXISTS_KWARGS_ATTACHMENTS_SIMPLE_HASH = { +REQUEST_EXISTS_KWARGS_ATTACHMENTS = { "json": { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -377,7 +352,7 @@ } # case 4 create if not exists with location -REQUEST_EXISTS_LOCATION_SIMPLE_HASH = { +REQUEST_EXISTS_LOCATION = { "selector": [ { "attributes": [ @@ -387,7 +362,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -419,10 +393,9 @@ }, }, } -REQUEST_EXISTS_KWARGS_LOCATION_SIMPLE_HASH = { +REQUEST_EXISTS_KWARGS_LOCATION = { "json": { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -469,7 +442,7 @@ }, } # case 5 create if not exists with location identity -REQUEST_EXISTS_LOCATION_IDENTITY_SIMPLE_HASH = { +REQUEST_EXISTS_LOCATION_IDENTITY = { "selector": [ { "attributes": [ @@ -479,7 +452,6 @@ }, ], "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": { "arc_display_name": ASSET_NAME, "arc_namespace": "namespace", @@ -496,13 +468,12 @@ # --------------- -REQUEST_FIXTURES_SIMPLE_HASH = { +REQUEST_FIXTURES = { "behaviours": ASSET_BEHAVIOURS, - "proof_mechanism": ProofMechanism.SIMPLE_HASH.name, "attributes": ATTRS_FIXTURES, } -REQUEST_FIXTURES_KWARGS_SIMPLE_HASH = { - "json": REQUEST_FIXTURES_SIMPLE_HASH, +REQUEST_FIXTURES_KWARGS = { + "json": REQUEST_FIXTURES, "headers": { "authorization": "Bearer authauthauth", }, diff --git a/unittests/testassetslist.py b/unittests/testassetslist.py index f43069dc..f7d0ec7a 100644 --- a/unittests/testassetslist.py +++ b/unittests/testassetslist.py @@ -13,7 +13,7 @@ from .mock_response import MockResponse from .testassetsconstants import ( - RESPONSE_SIMPLE_HASH, + RESPONSE, SUBPATH, TestAssetsBase, ) @@ -41,7 +41,7 @@ def test_assets_list(self): mock_get.return_value = MockResponse( 200, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) @@ -54,7 +54,7 @@ def test_assets_list(self): for asset in assets: self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="Incorrect asset listed", ) @@ -81,7 +81,7 @@ def test_assets_list_with_params(self): mock_get.return_value = MockResponse( 200, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) @@ -101,7 +101,7 @@ def test_assets_list_with_params(self): for asset in assets: self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="Incorrect asset listed", ) @@ -131,14 +131,14 @@ def test_assets_read_by_signature(self): mock_get.return_value = MockResponse( 200, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) asset = self.arch.assets.read_by_signature() self.assertEqual( asset, - RESPONSE_SIMPLE_HASH, + RESPONSE, msg="Incorrect asset listed", ) diff --git a/unittests/testassetsread.py b/unittests/testassetsread.py index f347b585..5860c0c6 100644 --- a/unittests/testassetsread.py +++ b/unittests/testassetsread.py @@ -17,8 +17,8 @@ from .mock_response import MockResponse from .testassetsconstants import ( IDENTITY, + RESPONSE, RESPONSE_NO_ATTACHMENTS, - RESPONSE_SIMPLE_HASH, SUBPATH, TestAssetsBase, ) @@ -107,7 +107,7 @@ def test_assets_count(self): 200, headers={HEADERS_TOTAL_COUNT: 1}, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) @@ -141,7 +141,7 @@ def test_assets_count_with_props_params(self): 200, headers={HEADERS_TOTAL_COUNT: 1}, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) @@ -177,7 +177,7 @@ def test_assets_count_with_attrs_params(self): 200, headers={HEADERS_TOTAL_COUNT: 1}, assets=[ - RESPONSE_SIMPLE_HASH, + RESPONSE, ], ) diff --git a/unittests/testnotebooks.py b/unittests/testnotebooks.py index 51efd30b..6ae6ee8a 100644 --- a/unittests/testnotebooks.py +++ b/unittests/testnotebooks.py @@ -43,7 +43,6 @@ "owner": "0x5284e740A744F075E402f7fB0c4485532ddf4Af8", "at_time": "2023-01-06T17:41:26Z", "storage_integrity": "TENANT_STORAGE", - "proof_mechanism": "SIMPLE_HASH", "chain_id": "8275868384", "public": False, "tenant_identity": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1", diff --git a/unittests/testproof_mechanism.py b/unittests/testproof_mechanism.py index 8b590b91..a6bb1a1b 100644 --- a/unittests/testproof_mechanism.py +++ b/unittests/testproof_mechanism.py @@ -14,38 +14,38 @@ class TestProofMechanism(TestCase): Test proof mechanism for archivist """ - def test_proof_mechanism_simple_hash(self): + def test_proof_mechanism_merkle_log(self): """ Test proof_mechanism """ - self.assertEqual(ProofMechanism.SIMPLE_HASH.value, 2, msg="Incorrect value") + self.assertEqual(ProofMechanism.MERKLE_LOG.value, 3, msg="Incorrect value") self.assertEqual( - ProofMechanism.SIMPLE_HASH.name, - "SIMPLE_HASH", + ProofMechanism.MERKLE_LOG.name, + "MERKLE_LOG", msg="Incorrect value", ) - def test_proof_mechanism_metkle_log(self): + def test_proof_mechanism_reserved1(self): """ Test proof_mechanism """ - self.assertEqual(ProofMechanism.MERKLE_LOG.value, 3, msg="Incorrect value") + with self.assertRaises(AttributeError): + self.assertEqual(ProofMechanism.__RESERVED1.value, 1, msg="Incorrect value") - self.assertEqual( - ProofMechanism.MERKLE_LOG.name, - "MERKLE_LOG", - msg="Incorrect value", - ) + with self.assertRaises(AttributeError): + self.assertEqual( + ProofMechanism.__RESERVED1.name, "__RESERVED1", msg="Incorrect value" + ) - def test_proof_mechanism_reserved(self): + def test_proof_mechanism_reserved2(self): """ Test proof_mechanism """ with self.assertRaises(AttributeError): - self.assertEqual(ProofMechanism.__RESERVED.value, 1, msg="Incorrect value") + self.assertEqual(ProofMechanism.__RESERVED2.value, 2, msg="Incorrect value") with self.assertRaises(AttributeError): self.assertEqual( - ProofMechanism.__RESERVED.name, "__RESERVED", msg="Incorrect value" + ProofMechanism.__RESERVED2.name, "__RESERVED2", msg="Incorrect value" )