diff --git a/.coveragerc b/.coveragerc index cd12bbf..326685c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -7,4 +7,3 @@ omit = # omit tests tests/* branch = true - diff --git a/.env-example b/.env-example index 4acc5d1..360b8bb 100644 --- a/.env-example +++ b/.env-example @@ -1,3 +1,3 @@ WALLET_PRIVATE_KEY=YOUR-PRIVATE-WALLET-KEY RPC_PROVIDER_URL=YOUR_RPC_URL -ETHERSCAN_API_KEY=YOUR-ETHERSCAN-API-KEY-HERE \ No newline at end of file +ETHERSCAN_API_KEY=YOUR-ETHERSCAN-API-KEY-HERE diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e5b24e2..9a1d95f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,10 +6,10 @@ This pr adds user login function, includes: - 1. add user login page. - 2. ... -## Test Plan - -Example: +Example: - 1. Use different test accounts for login tests, including correct user names and passwords, and incorrect user names and passwords. - 2. ... @@ -21,4 +21,4 @@ Example: Issue #123 ## Notes -- Example: Links and navigation need to be added to the front-end interface \ No newline at end of file +- Example: Links and navigation need to be added to the front-end interface diff --git a/.gitignore b/.gitignore index 2eb8c78..71ae301 100644 --- a/.gitignore +++ b/.gitignore @@ -111,4 +111,4 @@ virtualenv/ web3py.md # AI Assistant Configuration -CLAUDE.md \ No newline at end of file +CLAUDE.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8cabf22..09a86a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: rev: v0.8.4 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes] \ No newline at end of file + args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes] diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 50172ab..de49561 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq \ No newline at end of file +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90a7039..722b6e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,4 +63,4 @@ To make it easier for your PR to receive reviews, consider the reviewers will ne [1]: https://github.com/storyprotocol/typescript-sdk/issues [2]: https://chris.beams.io/posts/git-commit/#seven-rules -[3]: https://google.github.io/styleguide/tsguide.html \ No newline at end of file +[3]: https://google.github.io/styleguide/tsguide.html diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 69eafac..f61ce87 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -217,4 +217,4 @@ Before submitting a pull request: 3. Update tests if adding new functionality 4. Follow the existing code style and patterns -See [CONTRIBUTING.md](CONTRIBUTING.md) for more details. \ No newline at end of file +See [CONTRIBUTING.md](CONTRIBUTING.md) for more details. diff --git a/MANIFEST.in b/MANIFEST.in index c30c6a9..2ace150 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,4 +3,4 @@ include LICENSE include requirements.txt recursive-include src *.py *.json recursive-include src/story_protocol_python_sdk/abi *.json -recursive-include src/story_protocol_python_sdk/scripts *.json \ No newline at end of file +recursive-include src/story_protocol_python_sdk/scripts *.json diff --git a/pytest.ini b/pytest.ini index e701bf5..9ccddb9 100644 --- a/pytest.ini +++ b/pytest.ini @@ -8,4 +8,6 @@ markers = addopts = -v -ra # ignore directories -norecursedirs = *.egg .git .* _darcs build dist venv \ No newline at end of file +norecursedirs = *.egg .git .* _darcs build dist venv + +pythonpath = tests/integration tests/integration/config tests/unit tests/demo diff --git a/setup.py b/setup.py index bf76f4f..eabcc7d 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup # python setup.py sdist # twine upload dist/* diff --git a/src/story_protocol_python_sdk/__init__.py b/src/story_protocol_python_sdk/__init__.py index 4530bff..8520c85 100644 --- a/src/story_protocol_python_sdk/__init__.py +++ b/src/story_protocol_python_sdk/__init__.py @@ -1,13 +1,12 @@ __version__ = "0.3.14" -from .story_client import StoryClient +from .resources.Dispute import Dispute +from .resources.IPAccount import IPAccount from .resources.IPAsset import IPAsset from .resources.License import License from .resources.Royalty import Royalty -from .resources.IPAccount import IPAccount -from .resources.Dispute import Dispute from .resources.WIP import WIP - +from .story_client import StoryClient __all__ = [ "StoryClient", diff --git a/src/story_protocol_python_sdk/abi/AccessController/AccessController_client.py b/src/story_protocol_python_sdk/abi/AccessController/AccessController_client.py index d1956b2..0b6118f 100644 --- a/src/story_protocol_python_sdk/abi/AccessController/AccessController_client.py +++ b/src/story_protocol_python_sdk/abi/AccessController/AccessController_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for AccessController not found in config.json" + "Contract address for AccessController not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/ArbitrationPolicyUMA/ArbitrationPolicyUMA_client.py b/src/story_protocol_python_sdk/abi/ArbitrationPolicyUMA/ArbitrationPolicyUMA_client.py index b20b96a..cb61a57 100644 --- a/src/story_protocol_python_sdk/abi/ArbitrationPolicyUMA/ArbitrationPolicyUMA_client.py +++ b/src/story_protocol_python_sdk/abi/ArbitrationPolicyUMA/ArbitrationPolicyUMA_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for ArbitrationPolicyUMA not found in config.json" + "Contract address for ArbitrationPolicyUMA not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/CoreMetadataModule/CoreMetadataModule_client.py b/src/story_protocol_python_sdk/abi/CoreMetadataModule/CoreMetadataModule_client.py index 4e90177..2b38b62 100644 --- a/src/story_protocol_python_sdk/abi/CoreMetadataModule/CoreMetadataModule_client.py +++ b/src/story_protocol_python_sdk/abi/CoreMetadataModule/CoreMetadataModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for CoreMetadataModule not found in config.json" + "Contract address for CoreMetadataModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/CoreMetadataViewModule/CoreMetadataViewModule_client.py b/src/story_protocol_python_sdk/abi/CoreMetadataViewModule/CoreMetadataViewModule_client.py index 2ac514e..8c14566 100644 --- a/src/story_protocol_python_sdk/abi/CoreMetadataViewModule/CoreMetadataViewModule_client.py +++ b/src/story_protocol_python_sdk/abi/CoreMetadataViewModule/CoreMetadataViewModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -22,7 +23,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for CoreMetadataViewModule not found in config.json" + "Contract address for CoreMetadataViewModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/DerivativeWorkflows/DerivativeWorkflows_client.py b/src/story_protocol_python_sdk/abi/DerivativeWorkflows/DerivativeWorkflows_client.py index bee3fb5..b1162b6 100644 --- a/src/story_protocol_python_sdk/abi/DerivativeWorkflows/DerivativeWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/DerivativeWorkflows/DerivativeWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for DerivativeWorkflows not found in config.json" + "Contract address for DerivativeWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/DisputeModule/DisputeModule_client.py b/src/story_protocol_python_sdk/abi/DisputeModule/DisputeModule_client.py index 0dbb24f..2b8ae2f 100644 --- a/src/story_protocol_python_sdk/abi/DisputeModule/DisputeModule_client.py +++ b/src/story_protocol_python_sdk/abi/DisputeModule/DisputeModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for DisputeModule not found in config.json" + "Contract address for DisputeModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "DisputeModule.json" diff --git a/src/story_protocol_python_sdk/abi/GroupingModule/GroupingModule_client.py b/src/story_protocol_python_sdk/abi/GroupingModule/GroupingModule_client.py index 0c988d6..ed8ffe1 100644 --- a/src/story_protocol_python_sdk/abi/GroupingModule/GroupingModule_client.py +++ b/src/story_protocol_python_sdk/abi/GroupingModule/GroupingModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for GroupingModule not found in config.json" + "Contract address for GroupingModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "GroupingModule.json" diff --git a/src/story_protocol_python_sdk/abi/GroupingWorkflows/GroupingWorkflows_client.py b/src/story_protocol_python_sdk/abi/GroupingWorkflows/GroupingWorkflows_client.py index 1c1b0bb..24dcf45 100644 --- a/src/story_protocol_python_sdk/abi/GroupingWorkflows/GroupingWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/GroupingWorkflows/GroupingWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for GroupingWorkflows not found in config.json" + "Contract address for GroupingWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/IPAccountImpl/IPAccountImpl_client.py b/src/story_protocol_python_sdk/abi/IPAccountImpl/IPAccountImpl_client.py index d676f41..de9809b 100644 --- a/src/story_protocol_python_sdk/abi/IPAccountImpl/IPAccountImpl_client.py +++ b/src/story_protocol_python_sdk/abi/IPAccountImpl/IPAccountImpl_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 diff --git a/src/story_protocol_python_sdk/abi/IPAssetRegistry/IPAssetRegistry_client.py b/src/story_protocol_python_sdk/abi/IPAssetRegistry/IPAssetRegistry_client.py index eb1a457..9d753c6 100644 --- a/src/story_protocol_python_sdk/abi/IPAssetRegistry/IPAssetRegistry_client.py +++ b/src/story_protocol_python_sdk/abi/IPAssetRegistry/IPAssetRegistry_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for IPAssetRegistry not found in config.json" + "Contract address for IPAssetRegistry not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/IpRoyaltyVaultImpl/IpRoyaltyVaultImpl_client.py b/src/story_protocol_python_sdk/abi/IpRoyaltyVaultImpl/IpRoyaltyVaultImpl_client.py index 4fff409..2fb66d3 100644 --- a/src/story_protocol_python_sdk/abi/IpRoyaltyVaultImpl/IpRoyaltyVaultImpl_client.py +++ b/src/story_protocol_python_sdk/abi/IpRoyaltyVaultImpl/IpRoyaltyVaultImpl_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 diff --git a/src/story_protocol_python_sdk/abi/LicenseAttachmentWorkflows/LicenseAttachmentWorkflows_client.py b/src/story_protocol_python_sdk/abi/LicenseAttachmentWorkflows/LicenseAttachmentWorkflows_client.py index 3bbe154..92d509a 100644 --- a/src/story_protocol_python_sdk/abi/LicenseAttachmentWorkflows/LicenseAttachmentWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/LicenseAttachmentWorkflows/LicenseAttachmentWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for LicenseAttachmentWorkflows not found in config.json" + "Contract address for LicenseAttachmentWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/LicenseRegistry/LicenseRegistry_client.py b/src/story_protocol_python_sdk/abi/LicenseRegistry/LicenseRegistry_client.py index 824a47e..12e9eb7 100644 --- a/src/story_protocol_python_sdk/abi/LicenseRegistry/LicenseRegistry_client.py +++ b/src/story_protocol_python_sdk/abi/LicenseRegistry/LicenseRegistry_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for LicenseRegistry not found in config.json" + "Contract address for LicenseRegistry not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/LicenseToken/LicenseToken_client.py b/src/story_protocol_python_sdk/abi/LicenseToken/LicenseToken_client.py index 1720e0a..aa542e6 100644 --- a/src/story_protocol_python_sdk/abi/LicenseToken/LicenseToken_client.py +++ b/src/story_protocol_python_sdk/abi/LicenseToken/LicenseToken_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for LicenseToken not found in config.json" + "Contract address for LicenseToken not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "LicenseToken.json" diff --git a/src/story_protocol_python_sdk/abi/LicensingModule/LicensingModule_client.py b/src/story_protocol_python_sdk/abi/LicensingModule/LicensingModule_client.py index cf01b15..cfeb624 100644 --- a/src/story_protocol_python_sdk/abi/LicensingModule/LicensingModule_client.py +++ b/src/story_protocol_python_sdk/abi/LicensingModule/LicensingModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for LicensingModule not found in config.json" + "Contract address for LicensingModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/MockERC20/MockERC20_client.py b/src/story_protocol_python_sdk/abi/MockERC20/MockERC20_client.py index a51a7d4..14c11bd 100644 --- a/src/story_protocol_python_sdk/abi/MockERC20/MockERC20_client.py +++ b/src/story_protocol_python_sdk/abi/MockERC20/MockERC20_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -20,7 +21,7 @@ def __init__(self, web3: Web3): contract_address = contract["contract_address"] break if not contract_address: - raise ValueError(f"Contract address for MockERC20 not found in config.json") + raise ValueError("Contract address for MockERC20 not found in config.json") abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "MockERC20.json" ) diff --git a/src/story_protocol_python_sdk/abi/ModuleRegistry/ModuleRegistry_client.py b/src/story_protocol_python_sdk/abi/ModuleRegistry/ModuleRegistry_client.py index bfcc1b6..757dde0 100644 --- a/src/story_protocol_python_sdk/abi/ModuleRegistry/ModuleRegistry_client.py +++ b/src/story_protocol_python_sdk/abi/ModuleRegistry/ModuleRegistry_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for ModuleRegistry not found in config.json" + "Contract address for ModuleRegistry not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "ModuleRegistry.json" diff --git a/src/story_protocol_python_sdk/abi/PILicenseTemplate/PILicenseTemplate_client.py b/src/story_protocol_python_sdk/abi/PILicenseTemplate/PILicenseTemplate_client.py index 9b5b8e8..d83a232 100644 --- a/src/story_protocol_python_sdk/abi/PILicenseTemplate/PILicenseTemplate_client.py +++ b/src/story_protocol_python_sdk/abi/PILicenseTemplate/PILicenseTemplate_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for PILicenseTemplate not found in config.json" + "Contract address for PILicenseTemplate not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/RegistrationWorkflows/RegistrationWorkflows_client.py b/src/story_protocol_python_sdk/abi/RegistrationWorkflows/RegistrationWorkflows_client.py index 76c0298..25323f0 100644 --- a/src/story_protocol_python_sdk/abi/RegistrationWorkflows/RegistrationWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/RegistrationWorkflows/RegistrationWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RegistrationWorkflows not found in config.json" + "Contract address for RegistrationWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/RoyaltyModule/RoyaltyModule_client.py b/src/story_protocol_python_sdk/abi/RoyaltyModule/RoyaltyModule_client.py index 1907130..bf15287 100644 --- a/src/story_protocol_python_sdk/abi/RoyaltyModule/RoyaltyModule_client.py +++ b/src/story_protocol_python_sdk/abi/RoyaltyModule/RoyaltyModule_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RoyaltyModule not found in config.json" + "Contract address for RoyaltyModule not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "RoyaltyModule.json" diff --git a/src/story_protocol_python_sdk/abi/RoyaltyPolicyLAP/RoyaltyPolicyLAP_client.py b/src/story_protocol_python_sdk/abi/RoyaltyPolicyLAP/RoyaltyPolicyLAP_client.py index f553857..e01bfd3 100644 --- a/src/story_protocol_python_sdk/abi/RoyaltyPolicyLAP/RoyaltyPolicyLAP_client.py +++ b/src/story_protocol_python_sdk/abi/RoyaltyPolicyLAP/RoyaltyPolicyLAP_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RoyaltyPolicyLAP not found in config.json" + "Contract address for RoyaltyPolicyLAP not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/RoyaltyPolicyLRP/RoyaltyPolicyLRP_client.py b/src/story_protocol_python_sdk/abi/RoyaltyPolicyLRP/RoyaltyPolicyLRP_client.py index 62ad2f7..8fb93a2 100644 --- a/src/story_protocol_python_sdk/abi/RoyaltyPolicyLRP/RoyaltyPolicyLRP_client.py +++ b/src/story_protocol_python_sdk/abi/RoyaltyPolicyLRP/RoyaltyPolicyLRP_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RoyaltyPolicyLRP not found in config.json" + "Contract address for RoyaltyPolicyLRP not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/RoyaltyTokenDistributionWorkflows/RoyaltyTokenDistributionWorkflows_client.py b/src/story_protocol_python_sdk/abi/RoyaltyTokenDistributionWorkflows/RoyaltyTokenDistributionWorkflows_client.py index 407cb80..651e3bb 100644 --- a/src/story_protocol_python_sdk/abi/RoyaltyTokenDistributionWorkflows/RoyaltyTokenDistributionWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/RoyaltyTokenDistributionWorkflows/RoyaltyTokenDistributionWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RoyaltyTokenDistributionWorkflows not found in config.json" + "Contract address for RoyaltyTokenDistributionWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/RoyaltyWorkflows/RoyaltyWorkflows_client.py b/src/story_protocol_python_sdk/abi/RoyaltyWorkflows/RoyaltyWorkflows_client.py index 91884c3..1a8270b 100644 --- a/src/story_protocol_python_sdk/abi/RoyaltyWorkflows/RoyaltyWorkflows_client.py +++ b/src/story_protocol_python_sdk/abi/RoyaltyWorkflows/RoyaltyWorkflows_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -21,7 +22,7 @@ def __init__(self, web3: Web3): break if not contract_address: raise ValueError( - f"Contract address for RoyaltyWorkflows not found in config.json" + "Contract address for RoyaltyWorkflows not found in config.json" ) abi_path = os.path.join( os.path.dirname(__file__), diff --git a/src/story_protocol_python_sdk/abi/SPGNFTImpl/SPGNFTImpl_client.py b/src/story_protocol_python_sdk/abi/SPGNFTImpl/SPGNFTImpl_client.py index f19a684..4490654 100644 --- a/src/story_protocol_python_sdk/abi/SPGNFTImpl/SPGNFTImpl_client.py +++ b/src/story_protocol_python_sdk/abi/SPGNFTImpl/SPGNFTImpl_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 diff --git a/src/story_protocol_python_sdk/abi/WIP/WIP_client.py b/src/story_protocol_python_sdk/abi/WIP/WIP_client.py index 0587c65..d3229c9 100644 --- a/src/story_protocol_python_sdk/abi/WIP/WIP_client.py +++ b/src/story_protocol_python_sdk/abi/WIP/WIP_client.py @@ -1,5 +1,6 @@ import json import os + from web3 import Web3 @@ -20,7 +21,7 @@ def __init__(self, web3: Web3): contract_address = contract["contract_address"] break if not contract_address: - raise ValueError(f"Contract address for WIP not found in config.json") + raise ValueError("Contract address for WIP not found in config.json") abi_path = os.path.join( os.path.dirname(__file__), "..", "..", "abi", "jsons", "WIP.json" ) diff --git a/src/story_protocol_python_sdk/abi/jsons/AccessController.json b/src/story_protocol_python_sdk/abi/jsons/AccessController.json index 72ebaac..85f0230 100644 --- a/src/story_protocol_python_sdk/abi/jsons/AccessController.json +++ b/src/story_protocol_python_sdk/abi/jsons/AccessController.json @@ -865,4 +865,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/ArbitrationPolicyUMA.json b/src/story_protocol_python_sdk/abi/jsons/ArbitrationPolicyUMA.json index 08c0da1..a665035 100644 --- a/src/story_protocol_python_sdk/abi/jsons/ArbitrationPolicyUMA.json +++ b/src/story_protocol_python_sdk/abi/jsons/ArbitrationPolicyUMA.json @@ -936,4 +936,4 @@ "stateMutability": "payable", "type": "function" } - ] \ No newline at end of file + ] diff --git a/src/story_protocol_python_sdk/abi/jsons/CoreMetadataModule.json b/src/story_protocol_python_sdk/abi/jsons/CoreMetadataModule.json index 2f71ec6..ba76b87 100644 --- a/src/story_protocol_python_sdk/abi/jsons/CoreMetadataModule.json +++ b/src/story_protocol_python_sdk/abi/jsons/CoreMetadataModule.json @@ -494,4 +494,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/GroupingModule.json b/src/story_protocol_python_sdk/abi/jsons/GroupingModule.json index 3de9243..b80ab61 100644 --- a/src/story_protocol_python_sdk/abi/jsons/GroupingModule.json +++ b/src/story_protocol_python_sdk/abi/jsons/GroupingModule.json @@ -1048,4 +1048,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/GroupingWorkflows.json b/src/story_protocol_python_sdk/abi/jsons/GroupingWorkflows.json index 18d56b7..24f0158 100644 --- a/src/story_protocol_python_sdk/abi/jsons/GroupingWorkflows.json +++ b/src/story_protocol_python_sdk/abi/jsons/GroupingWorkflows.json @@ -1313,4 +1313,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/LicensingModule.json b/src/story_protocol_python_sdk/abi/jsons/LicensingModule.json index 2742686..d0078fe 100644 --- a/src/story_protocol_python_sdk/abi/jsons/LicensingModule.json +++ b/src/story_protocol_python_sdk/abi/jsons/LicensingModule.json @@ -1354,4 +1354,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/MockERC20.json b/src/story_protocol_python_sdk/abi/jsons/MockERC20.json index db82bcf..e466ba0 100644 --- a/src/story_protocol_python_sdk/abi/jsons/MockERC20.json +++ b/src/story_protocol_python_sdk/abi/jsons/MockERC20.json @@ -348,4 +348,4 @@ "stateMutability": "nonpayable", "type": "function" } - ] \ No newline at end of file + ] diff --git a/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLAP.json b/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLAP.json index 8ff970d..bfd28b0 100644 --- a/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLAP.json +++ b/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLAP.json @@ -648,4 +648,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLRP.json b/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLRP.json index 30795e4..77719f5 100644 --- a/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLRP.json +++ b/src/story_protocol_python_sdk/abi/jsons/RoyaltyPolicyLRP.json @@ -671,4 +671,4 @@ "stateMutability": "payable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/story_protocol_python_sdk/abi/jsons/SPGNFTImpl.json b/src/story_protocol_python_sdk/abi/jsons/SPGNFTImpl.json index 74820d5..a8aa782 100644 --- a/src/story_protocol_python_sdk/abi/jsons/SPGNFTImpl.json +++ b/src/story_protocol_python_sdk/abi/jsons/SPGNFTImpl.json @@ -1232,4 +1232,4 @@ "stateMutability": "nonpayable", "type": "function" } - ] \ No newline at end of file + ] diff --git a/src/story_protocol_python_sdk/abi/jsons/WIP.json b/src/story_protocol_python_sdk/abi/jsons/WIP.json index 4d2b58a..b20ca3f 100644 --- a/src/story_protocol_python_sdk/abi/jsons/WIP.json +++ b/src/story_protocol_python_sdk/abi/jsons/WIP.json @@ -425,4 +425,4 @@ "stateMutability": "payable", "type": "receive" } - ] \ No newline at end of file + ] diff --git a/src/story_protocol_python_sdk/resources/Dispute.py b/src/story_protocol_python_sdk/resources/Dispute.py index e9fd344..0fc7355 100644 --- a/src/story_protocol_python_sdk/resources/Dispute.py +++ b/src/story_protocol_python_sdk/resources/Dispute.py @@ -1,22 +1,20 @@ -from web3 import Web3 from eth_abi.abi import encode +from web3 import Web3 -from story_protocol_python_sdk.resources.WIP import WIP -from story_protocol_python_sdk.abi.DisputeModule.DisputeModule_client import ( - DisputeModuleClient, -) from story_protocol_python_sdk.abi.ArbitrationPolicyUMA.ArbitrationPolicyUMA_client import ( ArbitrationPolicyUMAClient, ) +from story_protocol_python_sdk.abi.DisputeModule.DisputeModule_client import ( + DisputeModuleClient, +) from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( IPAccountImplClient, ) from story_protocol_python_sdk.abi.WIP.WIP_client import WIPClient - -from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction +from story_protocol_python_sdk.resources.WIP import WIP from story_protocol_python_sdk.utils.ipfs import convert_cid_to_hash_ipfs -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS from story_protocol_python_sdk.utils.oov3 import get_assertion_bond +from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction class Dispute: @@ -101,7 +99,7 @@ def raise_dispute( if bond > max_bonds: raise ValueError(f"Bond must be less than {max_bonds}.") - deposit_response = self.wip.deposit(amount=bond) + self.wip.deposit(amount=bond) # Convert CID to IPFS hash dispute_evidence_hash = convert_cid_to_hash_ipfs(cid) @@ -297,7 +295,7 @@ def dispute_assertion( # Approve IP Account to transfer WrappedIP tokens if needed if allowance < bond: - approve_tx = self.wip.approve( + self.wip.approve( spender=ip_account.contract.address, amount=2**256 - 1 # maxUint256 ) diff --git a/src/story_protocol_python_sdk/resources/Group.py b/src/story_protocol_python_sdk/resources/Group.py index 079c7ad..dba882e 100644 --- a/src/story_protocol_python_sdk/resources/Group.py +++ b/src/story_protocol_python_sdk/resources/Group.py @@ -2,35 +2,34 @@ from web3 import Web3 +from story_protocol_python_sdk.abi.CoreMetadataModule.CoreMetadataModule_client import ( + CoreMetadataModuleClient, +) from story_protocol_python_sdk.abi.GroupingModule.GroupingModule_client import ( GroupingModuleClient, ) from story_protocol_python_sdk.abi.GroupingWorkflows.GroupingWorkflows_client import ( GroupingWorkflowsClient, ) +from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( + IPAccountImplClient, +) from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( IPAssetRegistryClient, ) -from story_protocol_python_sdk.abi.CoreMetadataModule.CoreMetadataModule_client import ( - CoreMetadataModuleClient, +from story_protocol_python_sdk.abi.LicenseRegistry.LicenseRegistry_client import ( + LicenseRegistryClient, ) from story_protocol_python_sdk.abi.LicensingModule.LicensingModule_client import ( LicensingModuleClient, ) -from story_protocol_python_sdk.abi.LicenseRegistry.LicenseRegistry_client import ( - LicenseRegistryClient, -) from story_protocol_python_sdk.abi.PILicenseTemplate.PILicenseTemplate_client import ( PILicenseTemplateClient, ) -from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( - IPAccountImplClient, -) - +from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH from story_protocol_python_sdk.utils.license_terms import LicenseTerms -from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction from story_protocol_python_sdk.utils.sign import Sign -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH +from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction class Group: diff --git a/src/story_protocol_python_sdk/resources/IPAccount.py b/src/story_protocol_python_sdk/resources/IPAccount.py index 32fada8..facab3c 100644 --- a/src/story_protocol_python_sdk/resources/IPAccount.py +++ b/src/story_protocol_python_sdk/resources/IPAccount.py @@ -2,20 +2,19 @@ from web3 import Web3 -from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( - IPAccountImplClient, -) -from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( - IPAssetRegistryClient, -) from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( AccessControllerClient, ) from story_protocol_python_sdk.abi.CoreMetadataModule.CoreMetadataModule_client import ( CoreMetadataModuleClient, ) +from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( + IPAccountImplClient, +) +from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( + IPAssetRegistryClient, +) from story_protocol_python_sdk.abi.MockERC20.MockERC20_client import MockERC20Client - from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction diff --git a/src/story_protocol_python_sdk/resources/IPAsset.py b/src/story_protocol_python_sdk/resources/IPAsset.py index 0278649..11eb3ca 100644 --- a/src/story_protocol_python_sdk/resources/IPAsset.py +++ b/src/story_protocol_python_sdk/resources/IPAsset.py @@ -2,43 +2,41 @@ from web3 import Web3 -from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( - IPAssetRegistryClient, -) -from story_protocol_python_sdk.abi.LicensingModule.LicensingModule_client import ( - LicensingModuleClient, +from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( + AccessControllerClient, ) -from story_protocol_python_sdk.abi.LicenseToken.LicenseToken_client import ( - LicenseTokenClient, +from story_protocol_python_sdk.abi.CoreMetadataModule.CoreMetadataModule_client import ( + CoreMetadataModuleClient, ) -from story_protocol_python_sdk.abi.LicenseRegistry.LicenseRegistry_client import ( - LicenseRegistryClient, +from story_protocol_python_sdk.abi.DerivativeWorkflows.DerivativeWorkflows_client import ( + DerivativeWorkflowsClient, ) -from story_protocol_python_sdk.abi.RegistrationWorkflows.RegistrationWorkflows_client import ( - RegistrationWorkflowsClient, +from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( + IPAssetRegistryClient, ) from story_protocol_python_sdk.abi.LicenseAttachmentWorkflows.LicenseAttachmentWorkflows_client import ( LicenseAttachmentWorkflowsClient, ) -from story_protocol_python_sdk.abi.DerivativeWorkflows.DerivativeWorkflows_client import ( - DerivativeWorkflowsClient, +from story_protocol_python_sdk.abi.LicenseRegistry.LicenseRegistry_client import ( + LicenseRegistryClient, ) -from story_protocol_python_sdk.abi.CoreMetadataModule.CoreMetadataModule_client import ( - CoreMetadataModuleClient, +from story_protocol_python_sdk.abi.LicenseToken.LicenseToken_client import ( + LicenseTokenClient, ) -from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( - AccessControllerClient, +from story_protocol_python_sdk.abi.LicensingModule.LicensingModule_client import ( + LicensingModuleClient, ) from story_protocol_python_sdk.abi.PILicenseTemplate.PILicenseTemplate_client import ( PILicenseTemplateClient, ) - +from story_protocol_python_sdk.abi.RegistrationWorkflows.RegistrationWorkflows_client import ( + RegistrationWorkflowsClient, +) +from story_protocol_python_sdk.abi.SPGNFTImpl.SPGNFTImpl_client import SPGNFTImplClient +from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH from story_protocol_python_sdk.utils.license_terms import LicenseTerms -from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction from story_protocol_python_sdk.utils.sign import Sign -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH - -from story_protocol_python_sdk.abi.SPGNFTImpl.SPGNFTImpl_client import SPGNFTImplClient +from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction class IPAsset: @@ -403,9 +401,7 @@ def mint_and_register_ip_asset_with_pil_terms( license_terms = [] for term in terms: - validated_term = self.license_terms_util.validate_license_terms( - term["terms"] - ) + self.license_terms_util.validate_license_terms(term["terms"]) validated_licensing_config = ( self.license_terms_util.validate_licensing_config( term["licensing_config"] @@ -632,9 +628,7 @@ def register_ip_and_attach_pil_terms( license_terms = [] for term in license_terms_data: - validated_term = self.license_terms_util.validate_license_terms( - term["terms"] - ) + self.license_terms_util.validate_license_terms(term["terms"]) validated_licensing_config = ( self.license_terms_util.validate_licensing_config( term["licensing_config"] diff --git a/src/story_protocol_python_sdk/resources/License.py b/src/story_protocol_python_sdk/resources/License.py index 65869b9..2381680 100644 --- a/src/story_protocol_python_sdk/resources/License.py +++ b/src/story_protocol_python_sdk/resources/License.py @@ -2,8 +2,8 @@ from web3 import Web3 -from story_protocol_python_sdk.abi.PILicenseTemplate.PILicenseTemplate_client import ( - PILicenseTemplateClient, +from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( + IPAssetRegistryClient, ) from story_protocol_python_sdk.abi.LicenseRegistry.LicenseRegistry_client import ( LicenseRegistryClient, @@ -11,16 +11,15 @@ from story_protocol_python_sdk.abi.LicensingModule.LicensingModule_client import ( LicensingModuleClient, ) -from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( - IPAssetRegistryClient, -) from story_protocol_python_sdk.abi.ModuleRegistry.ModuleRegistry_client import ( ModuleRegistryClient, ) - +from story_protocol_python_sdk.abi.PILicenseTemplate.PILicenseTemplate_client import ( + PILicenseTemplateClient, +) +from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS from story_protocol_python_sdk.utils.license_terms import LicenseTerms from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS class License: diff --git a/src/story_protocol_python_sdk/resources/NFTClient.py b/src/story_protocol_python_sdk/resources/NFTClient.py index 05d064d..41a7217 100644 --- a/src/story_protocol_python_sdk/resources/NFTClient.py +++ b/src/story_protocol_python_sdk/resources/NFTClient.py @@ -6,9 +6,8 @@ RegistrationWorkflowsClient, ) from story_protocol_python_sdk.abi.SPGNFTImpl.SPGNFTImpl_client import SPGNFTImplClient - +from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ZERO_HASH class NFTClient: diff --git a/src/story_protocol_python_sdk/resources/Permission.py b/src/story_protocol_python_sdk/resources/Permission.py index bec23be..3bcc992 100644 --- a/src/story_protocol_python_sdk/resources/Permission.py +++ b/src/story_protocol_python_sdk/resources/Permission.py @@ -1,22 +1,21 @@ # src/story_protcol_python_sdk/resources/Permission.py + from web3 import Web3 -import os, json +from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( + AccessControllerClient, +) from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( IPAccountImplClient, ) from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( IPAssetRegistryClient, ) -from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( - AccessControllerClient, -) from story_protocol_python_sdk.resources.IPAccount import IPAccount -from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction -from story_protocol_python_sdk.utils.validation import validate_address from story_protocol_python_sdk.utils.constants import DEFAULT_FUNCTION_SELECTOR from story_protocol_python_sdk.utils.sign import Sign +from story_protocol_python_sdk.utils.validation import validate_address class Permission: @@ -181,7 +180,7 @@ def create_set_permission_signature( # Get state and calculate deadline state = ip_account_client.state() - block_timestamp = self.web3.eth.get_block("latest").timestamp + self.web3.eth.get_block("latest").timestamp calculated_deadline = self.sign_util.get_deadline(deadline) # Get permission signature diff --git a/src/story_protocol_python_sdk/resources/Royalty.py b/src/story_protocol_python_sdk/resources/Royalty.py index a09f302..100965f 100644 --- a/src/story_protocol_python_sdk/resources/Royalty.py +++ b/src/story_protocol_python_sdk/resources/Royalty.py @@ -2,29 +2,28 @@ from web3 import Web3 +from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( + IPAccountImplClient, +) from story_protocol_python_sdk.abi.IPAssetRegistry.IPAssetRegistry_client import ( IPAssetRegistryClient, ) from story_protocol_python_sdk.abi.IpRoyaltyVaultImpl.IpRoyaltyVaultImpl_client import ( IpRoyaltyVaultImplClient, ) -from story_protocol_python_sdk.abi.RoyaltyPolicyLAP.RoyaltyPolicyLAP_client import ( - RoyaltyPolicyLAPClient, -) +from story_protocol_python_sdk.abi.MockERC20.MockERC20_client import MockERC20Client from story_protocol_python_sdk.abi.RoyaltyModule.RoyaltyModule_client import ( RoyaltyModuleClient, ) -from story_protocol_python_sdk.abi.RoyaltyWorkflows.RoyaltyWorkflows_client import ( - RoyaltyWorkflowsClient, -) -from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( - IPAccountImplClient, +from story_protocol_python_sdk.abi.RoyaltyPolicyLAP.RoyaltyPolicyLAP_client import ( + RoyaltyPolicyLAPClient, ) -from story_protocol_python_sdk.abi.MockERC20.MockERC20_client import MockERC20Client from story_protocol_python_sdk.abi.RoyaltyPolicyLRP.RoyaltyPolicyLRP_client import ( RoyaltyPolicyLRPClient, ) - +from story_protocol_python_sdk.abi.RoyaltyWorkflows.RoyaltyWorkflows_client import ( + RoyaltyWorkflowsClient, +) from story_protocol_python_sdk.utils.transaction_utils import build_and_send_transaction diff --git a/src/story_protocol_python_sdk/scripts/archive/generate_client.py b/src/story_protocol_python_sdk/scripts/archive/generate_client.py index ccc4b84..b4edcfa 100644 --- a/src/story_protocol_python_sdk/scripts/archive/generate_client.py +++ b/src/story_protocol_python_sdk/scripts/archive/generate_client.py @@ -1,12 +1,13 @@ # scripts/generate_client.py -import requests import json import os -from jinja2 import Template -from dotenv import load_dotenv import time +import requests +from dotenv import load_dotenv +from jinja2 import Template + # Load environment variables from .env file load_dotenv(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".env")) @@ -103,7 +104,7 @@ def {{ function.name }}(self, {% if function.inputs %}{{ function.inputs | join( return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.name }}_transaction(self, {% if function.inputs %}{{ function.inputs | join(', ') }}, {% endif %}tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} diff --git a/src/story_protocol_python_sdk/scripts/archive/generate_client_from_abi.py b/src/story_protocol_python_sdk/scripts/archive/generate_client_from_abi.py index 8985670..989bf93 100644 --- a/src/story_protocol_python_sdk/scripts/archive/generate_client_from_abi.py +++ b/src/story_protocol_python_sdk/scripts/archive/generate_client_from_abi.py @@ -1,5 +1,6 @@ import json import os + from jinja2 import Template # Load ABIs from the correct jsons folder @@ -35,7 +36,7 @@ def {{ function.name }}(self, {% if function.inputs %}{{ function.inputs | join( return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.name }}_transaction(self, {% if function.inputs %}{{ function.inputs | join(', ') }}, {% endif %}tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} diff --git a/src/story_protocol_python_sdk/scripts/archive/generate_client_impl.py b/src/story_protocol_python_sdk/scripts/archive/generate_client_impl.py index eb13de0..4da3d07 100644 --- a/src/story_protocol_python_sdk/scripts/archive/generate_client_impl.py +++ b/src/story_protocol_python_sdk/scripts/archive/generate_client_impl.py @@ -1,10 +1,11 @@ -import requests import json import os -from jinja2 import Template -from dotenv import load_dotenv import time +import requests +from dotenv import load_dotenv +from jinja2 import Template + # Load environment variables from .env file load_dotenv(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".env")) @@ -51,7 +52,7 @@ def {{ function.name }}(self, {% if function.inputs %}{{ function.inputs | join( return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.name }}_transaction(self, {% if function.inputs %}{{ function.inputs | join(', ') }}, {% endif %}tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} diff --git a/src/story_protocol_python_sdk/scripts/archive/generate_client_impl_from_abi.py b/src/story_protocol_python_sdk/scripts/archive/generate_client_impl_from_abi.py index 501bcb4..bd7575e 100644 --- a/src/story_protocol_python_sdk/scripts/archive/generate_client_impl_from_abi.py +++ b/src/story_protocol_python_sdk/scripts/archive/generate_client_impl_from_abi.py @@ -1,5 +1,6 @@ import json import os + from jinja2 import Template # Define the folder containing the ABI JSON files @@ -24,7 +25,7 @@ def {{ function.name }}(self, {% if function.inputs %}{{ function.inputs | join( return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.name }}_transaction(self, {% if function.inputs %}{{ function.inputs | join(', ') }}, {% endif %}tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} diff --git a/src/story_protocol_python_sdk/scripts/config.json b/src/story_protocol_python_sdk/scripts/config.json index df8ee59..ed90911 100644 --- a/src/story_protocol_python_sdk/scripts/config.json +++ b/src/story_protocol_python_sdk/scripts/config.json @@ -5,7 +5,7 @@ "contract_address": "0xcCF37d0a503Ee1D4C11208672e622ed3DFB2275a", "functions": [ "PermissionSet", - "setPermission", + "setPermission", "setAllPermissions", "setBatchPermissions", "setTransientPermission", @@ -17,7 +17,7 @@ "contract_address": "0x9b7A9c70AFF961C799110954fc06F3093aeb94C5", "functions": [ "DisputeCancelled", - "DisputeRaised", + "DisputeRaised", "DisputeResolved", "cancelDispute", "raiseDispute", @@ -43,7 +43,7 @@ "functions": [ "IPRegistered", "ipId", - "isRegistered", + "isRegistered", "register", "IPAccountRegistered" ] @@ -210,7 +210,7 @@ "functions": ["transferToVault"] }, { - "contract_name": "ArbitrationPolicyUMA", + "contract_name": "ArbitrationPolicyUMA", "contract_address": "0xfFD98c3877B8789124f02C7E8239A4b0Ef11E936", "functions": [ "minLiveness", diff --git a/src/story_protocol_python_sdk/scripts/generate_clients.py b/src/story_protocol_python_sdk/scripts/generate_clients.py index 5eb14a2..132f828 100644 --- a/src/story_protocol_python_sdk/scripts/generate_clients.py +++ b/src/story_protocol_python_sdk/scripts/generate_clients.py @@ -1,5 +1,6 @@ import json import os + from jinja2 import Template # Define the folder containing the ABI JSON files @@ -36,7 +37,7 @@ def {{ function.python_name }}(self{% if function.inputs %}, {{ function.inputs return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.python_name }}_transaction(self{% if function.inputs %}, {{ function.inputs | join(', ') }}{% endif %}, tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} @@ -64,7 +65,7 @@ def {{ function.python_name }}(self{% if function.inputs %}, {{ function.inputs return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).call() {% else %} return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).transact() - + def build_{{ function.python_name }}_transaction(self{% if function.inputs %}, {{ function.inputs | join(', ') }}{% endif %}, tx_params): return self.contract.functions.{{ function.name }}({% if function.inputs %}{{ function.inputs | join(', ') }}{% endif %}).build_transaction(tx_params) {% endif %} diff --git a/src/story_protocol_python_sdk/story_client.py b/src/story_protocol_python_sdk/story_client.py index 410881c..652ce1f 100644 --- a/src/story_protocol_python_sdk/story_client.py +++ b/src/story_protocol_python_sdk/story_client.py @@ -3,22 +3,22 @@ import os import sys +from story_protocol_python_sdk.resources.Dispute import Dispute +from story_protocol_python_sdk.resources.Group import Group +from story_protocol_python_sdk.resources.IPAccount import IPAccount +from story_protocol_python_sdk.resources.IPAsset import IPAsset +from story_protocol_python_sdk.resources.License import License +from story_protocol_python_sdk.resources.NFTClient import NFTClient +from story_protocol_python_sdk.resources.Permission import Permission +from story_protocol_python_sdk.resources.Royalty import Royalty +from story_protocol_python_sdk.resources.WIP import WIP + # Ensure the src directory is in the Python path current_dir = os.path.dirname(__file__) src_path = os.path.abspath(os.path.join(current_dir, "..")) if src_path not in sys.path: sys.path.append(src_path) -from story_protocol_python_sdk.resources.IPAsset import IPAsset -from story_protocol_python_sdk.resources.License import License -from story_protocol_python_sdk.resources.Royalty import Royalty -from story_protocol_python_sdk.resources.IPAccount import IPAccount -from story_protocol_python_sdk.resources.Permission import Permission -from story_protocol_python_sdk.resources.NFTClient import NFTClient -from story_protocol_python_sdk.resources.Dispute import Dispute -from story_protocol_python_sdk.resources.WIP import WIP -from story_protocol_python_sdk.resources.Group import Group - class StoryClient: """ diff --git a/src/story_protocol_python_sdk/utils/ipfs.py b/src/story_protocol_python_sdk/utils/ipfs.py index 8914d93..0318db3 100644 --- a/src/story_protocol_python_sdk/utils/ipfs.py +++ b/src/story_protocol_python_sdk/utils/ipfs.py @@ -1,5 +1,4 @@ import base58 -from typing import Union V0_PREFIX = "1220" @@ -15,7 +14,7 @@ def convert_cid_to_hash_ipfs(cid: str) -> str: Hex string starting with '0x' """ # Check if CID is v0 (starts with "Qm") - is_v0 = cid.startswith("Qm") + cid.startswith("Qm") # Decode base58 CID bytes_array = base58.b58decode(cid) diff --git a/src/story_protocol_python_sdk/utils/license_terms.py b/src/story_protocol_python_sdk/utils/license_terms.py index cef571f..5597e55 100644 --- a/src/story_protocol_python_sdk/utils/license_terms.py +++ b/src/story_protocol_python_sdk/utils/license_terms.py @@ -5,7 +5,7 @@ from story_protocol_python_sdk.abi.RoyaltyModule.RoyaltyModule_client import ( RoyaltyModuleClient, ) -from story_protocol_python_sdk.utils.constants import ZERO_ADDRESS, ROYALTY_POLICY +from story_protocol_python_sdk.utils.constants import ROYALTY_POLICY, ZERO_ADDRESS class LicenseTerms: diff --git a/src/story_protocol_python_sdk/utils/oov3.py b/src/story_protocol_python_sdk/utils/oov3.py index 5900212..ee5b3b7 100644 --- a/src/story_protocol_python_sdk/utils/oov3.py +++ b/src/story_protocol_python_sdk/utils/oov3.py @@ -2,7 +2,9 @@ # Load the ABI from the JSON file import json import os + from web3 import Web3 + from story_protocol_python_sdk.abi.ArbitrationPolicyUMA.ArbitrationPolicyUMA_client import ( ArbitrationPolicyUMAClient, ) diff --git a/src/story_protocol_python_sdk/utils/sign.py b/src/story_protocol_python_sdk/utils/sign.py index 88bcc4d..0fe266c 100644 --- a/src/story_protocol_python_sdk/utils/sign.py +++ b/src/story_protocol_python_sdk/utils/sign.py @@ -1,19 +1,18 @@ # src/story_protcol_python_sdk/utils/sign.py -from web3 import Web3 +from datetime import datetime + +from eth_abi.abi import encode from eth_account import Account from eth_account.messages import encode_typed_data -from eth_abi.abi import encode -from datetime import datetime +from web3 import Web3 -from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( - IPAccountImplClient, -) from story_protocol_python_sdk.abi.AccessController.AccessController_client import ( AccessControllerClient, ) - -from story_protocol_python_sdk.utils.constants import ZERO_FUNC +from story_protocol_python_sdk.abi.IPAccountImpl.IPAccountImpl_client import ( + IPAccountImplClient, +) class Sign: diff --git a/tests/demo/demo.py b/tests/demo/demo.py index 28f1557..e126c1c 100644 --- a/tests/demo/demo.py +++ b/tests/demo/demo.py @@ -1,17 +1,17 @@ import os -from dotenv import load_dotenv -from web3 import Web3 -from story_protocol_python_sdk import StoryClient from demo_utils import ( - get_token_id, - MockERC721, + PIL_LICENSE_TEMPLATE, + ROYALTY_POLICY, MockERC20, + MockERC721, + get_token_id, mint_tokens, - ROYALTY_POLICY, - ROYALTY_MODULE, - PIL_LICENSE_TEMPLATE, ) +from dotenv import load_dotenv +from web3 import Web3 + +from story_protocol_python_sdk import StoryClient def main(): @@ -69,13 +69,13 @@ def main(): print( f"Attached License Terms to IP at transaction hash {attach_license_terms_response['txHash']}" ) - except Exception as e: + except Exception: print( f"License Terms ID {register_pil_terms_response['licenseTermsId']} already attached to this IPA." ) # Before you mint make sure you have enough ERC20 tokens according to the minting fee above - token_ids = mint_tokens(MockERC20, web3, account, account.address, 10000) + mint_tokens(MockERC20, web3, account, account.address, 10000) # 5. Mint License mint_license_response = story_client.License.mintLicenseTokens( diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..c66b545 --- /dev/null +++ b/tests/integration/__init__.py @@ -0,0 +1,2 @@ +# This file makes tests/integration a Python package +# Now modules can be imported directly from the package diff --git a/tests/integration/config/__init__.py b/tests/integration/config/__init__.py new file mode 100644 index 0000000..4f51ab5 --- /dev/null +++ b/tests/integration/config/__init__.py @@ -0,0 +1 @@ +# This file makes tests/integration/config a Python package diff --git a/tests/integration/config/test_config.py b/tests/integration/config/test_config.py new file mode 100644 index 0000000..8b3248d --- /dev/null +++ b/tests/integration/config/test_config.py @@ -0,0 +1,37 @@ +import os + +from dotenv import load_dotenv +from web3 import Web3 + +# Load environment variables +load_dotenv(override=True) +private_key = os.getenv("WALLET_PRIVATE_KEY") +private_key_2 = os.getenv("WALLET_PRIVATE_KEY_2") +rpc_url = os.getenv("RPC_PROVIDER_URL") +wallet_address = os.getenv("WALLET_ADDRESS") +wallet_address_2 = os.getenv("WALLET_ADDRESS_2") + +if not private_key: + raise ValueError("WALLET_PRIVATE_KEY environment variable is not set") +if not rpc_url: + raise ValueError("RPC_PROVIDER_URL environment variable is not set") + +# Initialize Web3 +web3 = Web3(Web3.HTTPProvider(rpc_url)) +if not web3.is_connected(): + raise Exception("Failed to connect to Web3 provider") + +# Set up the account with the private key +account = web3.eth.account.from_key(private_key) +account_2 = web3.eth.account.from_key(private_key_2) + +# Export all configuration +__all__ = [ + "web3", + "account", + "account_2", + "wallet_address", + "wallet_address_2", + "private_key", + "private_key_2", +] diff --git a/tests/integration/utils.py b/tests/integration/config/utils.py similarity index 92% rename from tests/integration/utils.py rename to tests/integration/config/utils.py index 24eef74..7464803 100644 --- a/tests/integration/utils.py +++ b/tests/integration/config/utils.py @@ -1,9 +1,11 @@ -from web3 import Web3 -from dotenv import load_dotenv -from src.story_protocol_python_sdk.story_client import StoryClient -import os import hashlib +import os + import base58 +from dotenv import load_dotenv +from web3 import Web3 + +from story_protocol_python_sdk.story_client import StoryClient load_dotenv() @@ -24,23 +26,8 @@ CORE_METADATA_MODULE = "0x6E81a25C99C6e8430aeC7353325EB138aFE5DC16" -def get_story_client_in_sepolia(web3: Web3, account) -> StoryClient: - chain_id = 11155111 # Sepolia chain ID - return StoryClient(web3, account, chain_id) - - -def get_story_client_in_iliad(web3: Web3, account) -> StoryClient: - chain_id = 1513 # Sepolia chain ID - return StoryClient(web3, account, chain_id) - - -def get_story_client_in_odyssey(web3: Web3, account) -> StoryClient: - chain_id = 1516 # Odyssey chain ID - return StoryClient(web3, account, chain_id) - - -def get_story_client_in_devnet(web3: Web3, account) -> StoryClient: - chain_id = 1315 # Devnet chain ID +def get_story_client(web3: Web3, account) -> StoryClient: + chain_id = 1315 # aeneid chain ID return StoryClient(web3, account, chain_id) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 0000000..9ed11c2 --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,17 @@ +import pytest + +from story_protocol_python_sdk.story_client import StoryClient +from tests.integration.config.test_config import account, account_2, web3 +from tests.integration.config.utils import get_story_client + + +@pytest.fixture(scope="session") +def story_client() -> StoryClient: + """Fixture to provide the main story client""" + return get_story_client(web3, account) + + +@pytest.fixture(scope="session") +def story_client_2() -> StoryClient: + """Fixture to provide the secondary story client""" + return get_story_client(web3, account_2) diff --git a/tests/integration/setup_for_integration.py b/tests/integration/setup_for_integration.py index 3aecdce..c25f05e 100644 --- a/tests/integration/setup_for_integration.py +++ b/tests/integration/setup_for_integration.py @@ -1,78 +1,48 @@ -import os -import sys -import pytest -from dotenv import load_dotenv -from web3 import Web3 - -# Ensure the src directory is in the Python path -current_dir = os.path.dirname(__file__) -src_path = os.path.abspath(os.path.join(current_dir, "..", "..")) -if src_path not in sys.path: - sys.path.append(src_path) +# Import configuration from test_config +from tests.integration.config.test_config import ( + account, + account_2, + private_key, + private_key_2, + wallet_address, + wallet_address_2, + web3, +) -# Import everything from utils -from utils import ( - get_story_client_in_devnet, - get_token_id, - mint_tokens, - approve, - get_block_timestamp, - check_event_in_tx, - MockERC721, - MockERC20, - ZERO_ADDRESS, - ROYALTY_POLICY, - ROYALTY_MODULE, - PIL_LICENSE_TEMPLATE, +# Import utilities +from tests.integration.config.utils import ( ARBITRATION_POLICY_UMA, - generate_cid, - WIP_TOKEN_ADDRESS, - setup_royalty_vault, + CORE_METADATA_MODULE, EVEN_SPLIT_GROUP_POOL, + PIL_LICENSE_TEMPLATE, + ROYALTY_MODULE, + ROYALTY_POLICY, ROYALTY_POLICY_LRP, - CORE_METADATA_MODULE, + WIP_TOKEN_ADDRESS, + ZERO_ADDRESS, + MockERC20, + MockERC721, + approve, + check_event_in_tx, + generate_cid, + get_block_timestamp, + get_story_client, + get_token_id, mint_by_spg, + mint_tokens, + setup_royalty_vault, ) -# Load environment variables -load_dotenv(override=True) -private_key = os.getenv("WALLET_PRIVATE_KEY") -private_key_2 = os.getenv("WALLET_PRIVATE_KEY_2") -rpc_url = os.getenv("RPC_PROVIDER_URL") -wallet_address = os.getenv("WALLET_ADDRESS") -wallet_address_2 = os.getenv("WALLET_ADDRESS_2") - -if not private_key: - raise ValueError("WALLET_PRIVATE_KEY environment variable is not set") -if not rpc_url: - raise ValueError("RPC_PROVIDER_URL environment variable is not set") - -# Initialize Web3 -web3 = Web3(Web3.HTTPProvider(rpc_url)) -if not web3.is_connected(): - raise Exception("Failed to connect to Web3 provider") - -# Set up the account with the private key -account = web3.eth.account.from_key(private_key) -account_2 = web3.eth.account.from_key(private_key_2) - - -@pytest.fixture(scope="session") -def story_client(): - return get_story_client_in_devnet(web3, account) - - -@pytest.fixture(scope="session") -def story_client_2(): - return get_story_client_in_devnet(web3, account_2) - - -# Export everything needed by test files +# Export all shared configuration __all__ = [ "web3", "account", "account_2", - "story_client", + "wallet_address", + "wallet_address_2", + "private_key", + "private_key_2", + "get_story_client", "get_token_id", "mint_tokens", "approve", @@ -81,19 +51,15 @@ def story_client_2(): "MockERC721", "MockERC20", "ZERO_ADDRESS", - "ROYALTY_POLICY" "ROYALTY_MODULE", + "ROYALTY_POLICY", + "ROYALTY_MODULE", "PIL_LICENSE_TEMPLATE", "ARBITRATION_POLICY_UMA", - "account_2", - "story_client_2", "generate_cid", "setup_royalty_vault", "WIP_TOKEN_ADDRESS", - "wallet_address", - "wallet_address_2", - "private_key", - "private_key_2", "EVEN_SPLIT_GROUP_POOL", "ROYALTY_POLICY_LRP", "mint_by_spg", + "CORE_METADATA_MODULE", ] diff --git a/tests/integration/test_integration_dispute.py b/tests/integration/test_integration_dispute.py index d489697..fa3207a 100644 --- a/tests/integration/test_integration_dispute.py +++ b/tests/integration/test_integration_dispute.py @@ -1,23 +1,15 @@ # tests/integration/test_integration_dispute.py import pytest -from web3 import Web3 -from setup_for_integration import ( - web3, - account, - account_2, - story_client, - story_client_2, - generate_cid, - approve, - wallet_address, -) +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import account, generate_cid, web3 class TestDispute: @pytest.fixture(scope="module") - def target_ip_id(self, story_client, story_client_2): + def target_ip_id(self, story_client: StoryClient, story_client_2: StoryClient): """Create an IP to be disputed""" txData = story_client.NFTClient.create_nft_collection( name="test-collection", @@ -47,7 +39,7 @@ def target_ip_id(self, story_client, story_client_2): return response["ip_id"] @pytest.fixture(scope="module") - def dispute_id(self, story_client, target_ip_id): + def dispute_id(self, story_client: StoryClient, target_ip_id): cid = generate_cid() bond_amount = 1000000000000000000 # 1 ETH in wei @@ -68,12 +60,16 @@ def dispute_id(self, story_client, target_ip_id): return response["dispute_id"] - def test_raise_dispute(self, story_client, dispute_id): + def test_raise_dispute(self, story_client: StoryClient, dispute_id): """Test raising a dispute""" assert dispute_id is not None def test_counter_dispute( - self, story_client_2, story_client, target_ip_id, dispute_id + self, + story_client_2: StoryClient, + story_client: StoryClient, + target_ip_id, + dispute_id, ): """Test countering a dispute""" # Get the assertion ID from the dispute ID @@ -82,9 +78,7 @@ def test_counter_dispute( # Generate a CID for counter evidence counter_evidence_cid = generate_cid() - deposit_response_2 = story_client_2.WIP.deposit( - amount=Web3.to_wei(1, "ether") # 1 IP - ) + story_client_2.WIP.deposit(amount=web3.to_wei(1, "ether")) # 1 IP # Counter the dispute assertion with story_client_2 (the IP owner) response = story_client_2.Dispute.dispute_assertion( diff --git a/tests/integration/test_integration_group.py b/tests/integration/test_integration_group.py index a838e63..a60f790 100644 --- a/tests/integration/test_integration_group.py +++ b/tests/integration/test_integration_group.py @@ -1,20 +1,17 @@ # tests/integration/test_integration_group.py -import pytest -from web3 import Web3 import copy -from setup_for_integration import ( - web3, - account, - story_client, - get_token_id, - MockERC721, - MockERC20, - ZERO_ADDRESS, - PIL_LICENSE_TEMPLATE, +import pytest + +from .setup_for_integration import ( EVEN_SPLIT_GROUP_POOL, + PIL_LICENSE_TEMPLATE, ROYALTY_POLICY_LRP, + ZERO_ADDRESS, + MockERC20, + account, + web3, ) # class TestGroupBasicOperations: diff --git a/tests/integration/test_integration_ip_account.py b/tests/integration/test_integration_ip_account.py index 1cc13a7..4dca5c9 100644 --- a/tests/integration/test_integration_ip_account.py +++ b/tests/integration/test_integration_ip_account.py @@ -1,28 +1,28 @@ # tests/integration/test_integration_ip_account.py import pytest -from web3 import Web3 +from eth_abi.abi import encode from eth_account import Account from eth_account.messages import encode_typed_data -from eth_abi.abi import encode - from setup_for_integration import ( - web3, + MockERC20, + MockERC721, account, - story_client, + get_block_timestamp, get_token_id, mint_tokens, - get_block_timestamp, - MockERC721, - MockERC20, private_key, + web3, ) +from web3 import Web3 + +from story_protocol_python_sdk.story_client import StoryClient class TestBasicIPAccountOperations: """Basic IP Account operations like execute and nonce retrieval""" - def test_execute(self, story_client): + def test_execute(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( nft_contract=MockERC721, token_id=token_id @@ -34,7 +34,7 @@ def test_execute(self, story_client): response["ip_id"], account.address, "0x89630Ccf23277417FBdfd3076C702F5248267e78", - Web3.keccak(text="function setAll(address,string,bytes32,bytes32)")[:4], + web3.keccak(text="function setAll(address,string,bytes32,bytes32)")[:4], 1, ], ) @@ -54,7 +54,7 @@ def test_execute(self, story_client): assert isinstance(response["tx_hash"], str), "'tx_hash' is not a string." assert len(response["tx_hash"]) > 0, "'tx_hash' is empty." - def test_get_ip_account_nonce(self, story_client): + def test_get_ip_account_nonce(self, story_client: StoryClient): """Test getting IP Account nonce.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -67,7 +67,7 @@ def test_get_ip_account_nonce(self, story_client): assert state is not None assert isinstance(state, bytes) - def test_execute_with_encoded_data(self, story_client): + def test_execute_with_encoded_data(self, story_client: StoryClient): """Test execute with pre-encoded function data.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -81,7 +81,7 @@ def test_execute_with_encoded_data(self, story_client): ip_id, account.address, "0x89630Ccf23277417FBdfd3076C702F5248267e78", - Web3.keccak(text="function execute(address,uint256,bytes,uint8)")[:4], + web3.keccak(text="function execute(address,uint256,bytes,uint8)")[:4], 1, ], ) @@ -102,7 +102,7 @@ def test_execute_with_encoded_data(self, story_client): class TestSignatureOperations: """Tests for operations involving signatures""" - def test_execute_with_sig(self, story_client): + def test_execute_with_sig(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( nft_contract=MockERC721, token_id=token_id @@ -118,7 +118,7 @@ def test_execute_with_sig(self, story_client): ip_id, account.address, "0x6E81a25C99C6e8430aeC7353325EB138aFE5DC16", - Web3.keccak(text="function setAll(address,string,bytes32,bytes32)")[:4], + web3.keccak(text="function setAll(address,string,bytes32,bytes32)")[:4], 1, ], ) @@ -132,8 +132,8 @@ def test_execute_with_sig(self, story_client): ], ) - expected_state = Web3.keccak( - encode(["bytes32", "bytes"], [state, Web3.to_bytes(hexstr=execute_data)]) + expected_state = web3.keccak( + encode(["bytes32", "bytes"], [state, web3.to_bytes(hexstr=execute_data)]) ) domain_data = { @@ -179,7 +179,7 @@ def test_execute_with_sig(self, story_client): assert isinstance(response["tx_hash"], str) assert len(response["tx_hash"]) > 0 - def test_execute_with_sig_multiple_permissions(self, story_client): + def test_execute_with_sig_multiple_permissions(self, story_client: StoryClient): """Test execute_with_sig setting multiple permissions.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -278,7 +278,7 @@ def test_execute_with_sig_multiple_permissions(self, story_client): class TestErrorCases: """Tests for error cases and validation""" - def test_execute_invalid_address(self, story_client): + def test_execute_invalid_address(self, story_client: StoryClient): """Test execute with invalid address should raise error.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -296,7 +296,7 @@ def test_execute_invalid_address(self, story_client): assert "is not a valid address" in str(exc_info.value) - def test_execute_unregistered_ip(self, story_client): + def test_execute_unregistered_ip(self, story_client: StoryClient): """Test execute with unregistered IP should raise error.""" unregistered_ip = "0x1234567890123456789012345678901234567890" data = "0x" @@ -311,7 +311,7 @@ def test_execute_unregistered_ip(self, story_client): assert "is not registered" in str(exc_info.value) - def test_execute_with_sig_wrong_signer(self, story_client): + def test_execute_with_sig_wrong_signer(self, story_client: StoryClient): """Test execute_with_sig with a valid signature but wrong signer address.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -385,7 +385,7 @@ def test_execute_with_sig_wrong_signer(self, story_client): class TestSetIpMetadata: """Tests for setting IP metadata""" - def test_set_ip_metadata(self, story_client): + def test_set_ip_metadata(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( nft_contract=MockERC721, token_id=token_id @@ -409,7 +409,7 @@ def test_set_ip_metadata(self, story_client): class Testtransfer_erc20: """Tests for transferring ERC20 tokens""" - def test_transfer_erc20(self, story_client): + def test_transfer_erc20(self, story_client: StoryClient): """Test transferring ERC20 tokens""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( @@ -433,7 +433,7 @@ def test_transfer_erc20(self, story_client): # 2. Transfer ERC20 tokens to the IP account amount_to_mint = 2000000 # Equivalent to 0.002 ether in wei - mint_receipt = mint_tokens( + mint_tokens( erc20_contract_address=MockERC20, web3=story_client.web3, account=story_client.account, @@ -443,7 +443,7 @@ def test_transfer_erc20(self, story_client): # 3. Transfer WIP to the IP account # First deposit (wrap) IP to WIP - deposit_response = story_client.WIP.deposit(amount=1) + story_client.WIP.deposit(amount=1) # Then transfer WIP to the IP account response = story_client.WIP.transfer(to=ip_id, amount=1) @@ -493,7 +493,7 @@ def test_transfer_erc20(self, story_client): assert final_wip_balance_of_wallet == initial_wip_balance_of_wallet + 1 @pytest.mark.skip(reason="contract allows empty calls") - def test_transfer_erc20_empty_tokens(self, story_client): + def test_transfer_erc20_empty_tokens(self, story_client: StoryClient): """Test transfer_erc20 with empty tokens list.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( @@ -502,12 +502,12 @@ def test_transfer_erc20_empty_tokens(self, story_client): ip_id = register_response["ip_id"] # Try to transfer with empty tokens list - with pytest.raises(Exception) as exc_info: + with pytest.raises(Exception): story_client.IPAccount.transfer_erc20( ip_id=ip_id, tokens=[] # Empty tokens list ) - def test_transfer_erc20_invalid_token_params(self, story_client): + def test_transfer_erc20_invalid_token_params(self, story_client: StoryClient): """Test transfer_erc20 with invalid token parameters.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) register_response = story_client.IPAsset.register( diff --git a/tests/integration/test_integration_ip_asset.py b/tests/integration/test_integration_ip_asset.py index b92def1..ff9a5a0 100644 --- a/tests/integration/test_integration_ip_asset.py +++ b/tests/integration/test_integration_ip_asset.py @@ -1,26 +1,26 @@ # tests/integration/test_integration_ip_asset.py import pytest -from web3 import Web3 -from setup_for_integration import ( - web3, - account, - story_client, - get_token_id, - MockERC721, - MockERC20, - ZERO_ADDRESS, - ROYALTY_POLICY, +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import ( PIL_LICENSE_TEMPLATE, + ROYALTY_POLICY, WIP_TOKEN_ADDRESS, + ZERO_ADDRESS, + MockERC20, + MockERC721, + account, + get_token_id, mint_by_spg, + web3, ) class TestIPAssetRegistration: @pytest.fixture(scope="module") - def child_ip_id(self, story_client): + def child_ip_id(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( @@ -35,10 +35,10 @@ def child_ip_id(self, story_client): assert response["ip_id"] is not None return response["ip_id"] - def test_register_ip_asset(self, story_client, child_ip_id): + def test_register_ip_asset(self, story_client: StoryClient, child_ip_id): assert child_ip_id is not None - def test_register_ip_asset_with_metadata(self, story_client): + def test_register_ip_asset_with_metadata(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) metadata = { "ip_metadata_uri": "test-uri", @@ -67,7 +67,7 @@ def test_register_ip_asset_with_metadata(self, story_client): class TestIPAssetDerivatives: @pytest.fixture(scope="module") - def child_ip_id(self, story_client): + def child_ip_id(self, story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( @@ -83,7 +83,7 @@ def child_ip_id(self, story_client): return response["ip_id"] @pytest.fixture(scope="module") - def non_commercial_license(self, story_client): + def non_commercial_license(self, story_client: StoryClient): license_register_response = ( story_client.License.register_non_com_social_remixing_pil() ) @@ -91,20 +91,24 @@ def non_commercial_license(self, story_client): return no_commercial_license_terms_id @pytest.fixture(scope="module") - def parent_ip_id(self, story_client, non_commercial_license): + def parent_ip_id(self, story_client: StoryClient, non_commercial_license): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( nft_contract=MockERC721, token_id=token_id ) - attach_license_response = story_client.License.attach_license_terms( + story_client.License.attach_license_terms( response["ip_id"], PIL_LICENSE_TEMPLATE, non_commercial_license ) return response["ip_id"] def test_register_derivative( - self, story_client, child_ip_id, parent_ip_id, non_commercial_license + self, + story_client: StoryClient, + child_ip_id, + parent_ip_id, + non_commercial_license, ): response = story_client.IPAsset.register_derivative( child_ip_id=child_ip_id, @@ -122,7 +126,7 @@ def test_register_derivative( assert len(response["tx_hash"]) > 0 def test_register_derivative_with_license_tokens( - self, story_client, parent_ip_id, non_commercial_license + self, story_client: StoryClient, parent_ip_id, non_commercial_license ): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) child_response = story_client.IPAsset.register( @@ -156,7 +160,7 @@ def test_register_derivative_with_license_tokens( class TestIPAssetMinting: @pytest.fixture(scope="module") - def nft_collection(self, story_client): + def nft_collection(self, story_client: StoryClient): tx_data = story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -168,7 +172,9 @@ def nft_collection(self, story_client): ) return tx_data["nft_contract"] - def test_mint_register_attach_terms(self, story_client, nft_collection): + def test_mint_register_attach_terms( + self, story_client: StoryClient, nft_collection + ): metadata = { "ip_metadata_uri": "test-uri", "ip_metadata_hash": web3.to_hex(web3.keccak(text="test-metadata-hash")), @@ -230,7 +236,7 @@ def test_mint_register_attach_terms(self, story_client, nft_collection): assert isinstance(response["license_terms_ids"], list) assert all(isinstance(id, int) for id in response["license_terms_ids"]) - def test_mint_register_ip(self, story_client, nft_collection): + def test_mint_register_ip(self, story_client: StoryClient, nft_collection): metadata = { "ip_metadata_uri": "test-uri", "ip_metadata_hash": web3.to_hex(web3.keccak(text="test-metadata-hash")), @@ -240,14 +246,14 @@ def test_mint_register_ip(self, story_client, nft_collection): ), } - response = story_client.IPAsset.mint_and_register_ip( + story_client.IPAsset.mint_and_register_ip( spg_nft_contract=nft_collection, ip_metadata=metadata ) class TestSPGNFTOperations: @pytest.fixture(scope="module") - def nft_collection(self, story_client): + def nft_collection(self, story_client: StoryClient): tx_data = story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -260,7 +266,7 @@ def nft_collection(self, story_client): return tx_data["nft_contract"] @pytest.fixture(scope="module") - def parent_ip_and_license_terms(self, story_client, nft_collection): + def parent_ip_and_license_terms(self, story_client: StoryClient, nft_collection): response = story_client.IPAsset.mint_and_register_ip_asset_with_pil_terms( spg_nft_contract=nft_collection, terms=[ @@ -342,7 +348,7 @@ def parent_ip_and_license_terms(self, story_client, nft_collection): # assert isinstance(result['ip_id'], str) and result['ip_id'] def test_register_ip_and_attach_pil_terms( - self, story_client, nft_collection, parent_ip_and_license_terms + self, story_client: StoryClient, nft_collection, parent_ip_and_license_terms ): token_id = mint_by_spg(nft_collection, story_client.web3, story_client.account) @@ -430,7 +436,7 @@ def test_register_ip_and_attach_pil_terms( class TestIPAssetMint: @pytest.fixture(scope="module") - def nft_collection(self, story_client): + def nft_collection(self, story_client: StoryClient): tx_data = story_client.NFTClient.create_nft_collection( name="test-mint-collection", symbol="MINT", @@ -442,7 +448,7 @@ def nft_collection(self, story_client): ) return tx_data["nft_contract"] - def test_mint_basic(self, story_client, nft_collection): + def test_mint_basic(self, story_client: StoryClient, nft_collection): """Test basic minting functionality""" metadata_uri = "https://example.com/metadata/1.json" metadata_hash = web3.keccak(text="test-metadata-content") @@ -464,7 +470,9 @@ def test_mint_basic(self, story_client, nft_collection): receipt = story_client.web3.eth.wait_for_transaction_receipt(response) assert receipt.status == 1 - def test_mint_with_duplicates_allowed(self, story_client, nft_collection): + def test_mint_with_duplicates_allowed( + self, story_client: StoryClient, nft_collection + ): """Test minting with duplicate metadata allowed""" metadata_uri = "https://example.com/metadata/duplicate.json" metadata_hash = web3.keccak(text="duplicate-metadata-content") @@ -498,7 +506,7 @@ def test_mint_with_duplicates_allowed(self, story_client, nft_collection): # Verify different transaction hashes assert response1 != response2 - def test_mint_to_different_address(self, story_client, nft_collection): + def test_mint_to_different_address(self, story_client: StoryClient, nft_collection): """Test minting to a different recipient address""" # Create a different recipient address for testing different_account = story_client.web3.eth.account.create() @@ -519,7 +527,9 @@ def test_mint_to_different_address(self, story_client, nft_collection): receipt = story_client.web3.eth.wait_for_transaction_receipt(response) assert receipt.status == 1 - def test_mint_with_various_metadata_formats(self, story_client, nft_collection): + def test_mint_with_various_metadata_formats( + self, story_client: StoryClient, nft_collection + ): """Test minting with different metadata URI formats""" test_cases = [ { @@ -549,7 +559,7 @@ def test_mint_with_various_metadata_formats(self, story_client, nft_collection): receipt = story_client.web3.eth.wait_for_transaction_receipt(response) assert receipt.status == 1 - def test_mint_with_zero_hash(self, story_client, nft_collection): + def test_mint_with_zero_hash(self, story_client: StoryClient, nft_collection): """Test minting with zero hash""" metadata_uri = "https://example.com/metadata/zero-hash.json" zero_hash = b"\x00" * 32 # 32 bytes of zeros @@ -566,7 +576,7 @@ def test_mint_with_zero_hash(self, story_client, nft_collection): receipt = story_client.web3.eth.wait_for_transaction_receipt(response) assert receipt.status == 1 - def test_mint_error_cases(self, story_client, nft_collection): + def test_mint_error_cases(self, story_client: StoryClient, nft_collection): """Test various error cases for minting""" metadata_uri = "https://example.com/metadata/error-test.json" metadata_hash = web3.keccak(text="error-test-metadata") @@ -602,7 +612,7 @@ def test_mint_error_cases(self, story_client, nft_collection): ) def test_mint_with_existing_metadata_hash_no_duplicates( - self, story_client, nft_collection + self, story_client: StoryClient, nft_collection ): """Test that minting with existing metadata hash fails when duplicates not allowed""" metadata_uri = "https://example.com/metadata/no-duplicates.json" diff --git a/tests/integration/test_integration_license.py b/tests/integration/test_integration_license.py index 5f1c104..bcc5be9 100644 --- a/tests/integration/test_integration_license.py +++ b/tests/integration/test_integration_license.py @@ -1,25 +1,24 @@ # tests/integration/test_integration_license.py import pytest -from web3 import Web3 -from setup_for_integration import ( - web3, +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import ( + PIL_LICENSE_TEMPLATE, + ROYALTY_MODULE, + ROYALTY_POLICY, + MockERC20, + MockERC721, account, - story_client, + approve, get_token_id, mint_tokens, - approve, - MockERC721, - MockERC20, - ZERO_ADDRESS, - ROYALTY_POLICY, - ROYALTY_MODULE, - PIL_LICENSE_TEMPLATE, + web3, ) -def test_register_pil_terms(story_client): +def test_register_pil_terms(story_client: StoryClient): response = story_client.License.register_pil_terms( transferable=False, royalty_policy=story_client.web3.to_checksum_address( @@ -50,7 +49,7 @@ def test_register_pil_terms(story_client): assert isinstance(response["license_terms_id"], int) -def test_register_non_com_social_remixing_pil(story_client): +def test_register_non_com_social_remixing_pil(story_client: StoryClient): response = story_client.License.register_non_com_social_remixing_pil() assert response is not None @@ -60,7 +59,7 @@ def test_register_non_com_social_remixing_pil(story_client): @pytest.fixture(scope="module") -def register_commercial_use_pil(story_client): +def register_commercial_use_pil(story_client: StoryClient): response = story_client.License.register_commercial_use_pil( default_minting_fee=11, currency=MockERC20, royalty_policy=ROYALTY_POLICY ) @@ -79,12 +78,14 @@ def register_commercial_use_pil(story_client): return response["license_terms_id"] -def test_register_commercial_use_pil(story_client, register_commercial_use_pil): +def test_register_commercial_use_pil( + story_client: StoryClient, register_commercial_use_pil +): assert register_commercial_use_pil is not None @pytest.fixture(scope="module") -def register_commercial_remix_pil(story_client): +def register_commercial_remix_pil(story_client: StoryClient): response = story_client.License.register_commercial_remix_pil( default_minting_fee=1, currency=MockERC20, @@ -106,17 +107,19 @@ def register_commercial_remix_pil(story_client): return response["license_terms_id"] -def test_register_commercial_remix_pil(story_client, register_commercial_remix_pil): +def test_register_commercial_remix_pil( + story_client: StoryClient, register_commercial_remix_pil +): assert register_commercial_remix_pil is not None @pytest.fixture(scope="module") -def ip_id(story_client): +def ip_id(story_client: StoryClient): token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register(nft_contract=MockERC721, token_id=token_id) - token_ids = mint_tokens( + mint_tokens( erc20_contract_address=MockERC20, web3=web3, account=account, @@ -124,7 +127,7 @@ def ip_id(story_client): amount=100000 * 10**6, ) - receipt = approve( + approve( erc20_contract_address=MockERC20, web3=web3, account=account, @@ -139,7 +142,9 @@ def ip_id(story_client): return response["ip_id"] -def test_attach_license_terms(story_client, ip_id, register_commercial_use_pil): +def test_attach_license_terms( + story_client: StoryClient, ip_id, register_commercial_use_pil +): license_terms_id = register_commercial_use_pil response = story_client.License.attach_license_terms( @@ -155,7 +160,9 @@ def test_attach_license_terms(story_client, ip_id, register_commercial_use_pil): assert len(response["tx_hash"]) > 0, "'tx_hash' is empty." -def test_mint_license_tokens(story_client, ip_id, register_commercial_use_pil): +def test_mint_license_tokens( + story_client: StoryClient, ip_id, register_commercial_use_pil +): response = story_client.License.mint_license_tokens( licensor_ip_id=ip_id, license_template=PIL_LICENSE_TEMPLATE, @@ -183,7 +190,7 @@ def test_mint_license_tokens(story_client, ip_id, register_commercial_use_pil): ), "Not all elements in 'license_token_ids' are integers." -def test_get_license_terms(story_client): +def test_get_license_terms(story_client: StoryClient): selectedLicenseTermsId = 3 response = story_client.License.get_license_terms(selectedLicenseTermsId) @@ -191,7 +198,9 @@ def test_get_license_terms(story_client): assert response is not None, "Response is None, indicating the call failed." -def test_predict_minting_license_fee(story_client, ip_id, register_commercial_use_pil): +def test_predict_minting_license_fee( + story_client: StoryClient, ip_id, register_commercial_use_pil +): response = story_client.License.predict_minting_license_fee( licensor_ip_id=ip_id, license_terms_id=register_commercial_use_pil, amount=1 ) @@ -208,7 +217,9 @@ def test_predict_minting_license_fee(story_client, ip_id, register_commercial_us assert isinstance(response["amount"], int), "'amount' is not an integer." -def test_set_licensing_config(story_client, ip_id, register_commercial_remix_pil): +def test_set_licensing_config( + story_client: StoryClient, ip_id, register_commercial_remix_pil +): licensing_config = { "mintingFee": 1, "isSet": True, @@ -238,7 +249,7 @@ def test_set_licensing_config(story_client, ip_id, register_commercial_remix_pil assert response["success"] is True, "'success' is not True" -def test_register_pil_terms_with_no_minting_fee(story_client): +def test_register_pil_terms_with_no_minting_fee(story_client: StoryClient): """Test registering PIL terms with no minting fee.""" response = story_client.License.register_pil_terms( transferable=False, @@ -270,7 +281,7 @@ def test_register_pil_terms_with_no_minting_fee(story_client): assert isinstance(response["license_terms_id"], int) -def test_register_commercial_use_pil_without_royalty_policy(story_client): +def test_register_commercial_use_pil_without_royalty_policy(story_client: StoryClient): """Test registering commercial use PIL without specifying royalty policy.""" response = story_client.License.register_commercial_use_pil( default_minting_fee=1, currency=MockERC20 @@ -283,7 +294,7 @@ def test_register_commercial_use_pil_without_royalty_policy(story_client): @pytest.fixture(scope="module") -def setup_license_terms(story_client, ip_id): +def setup_license_terms(story_client: StoryClient, ip_id): """Fixture to set up license terms for testing.""" response = story_client.License.register_commercial_remix_pil( default_minting_fee=1, @@ -301,7 +312,7 @@ def setup_license_terms(story_client, ip_id): return license_id -def test_multi_token_minting(story_client, ip_id, setup_license_terms): +def test_multi_token_minting(story_client: StoryClient, ip_id, setup_license_terms): """Test minting multiple license tokens at once.""" response = story_client.License.mint_license_tokens( licensor_ip_id=ip_id, @@ -322,7 +333,7 @@ def test_multi_token_minting(story_client, ip_id, setup_license_terms): def test_set_licensing_config_with_hooks( - story_client, ip_id, register_commercial_remix_pil + story_client: StoryClient, ip_id, register_commercial_remix_pil ): """Test setting licensing configuration with hooks enabled.""" licensing_config = { @@ -353,7 +364,7 @@ def test_set_licensing_config_with_hooks( def test_predict_minting_fee_with_multiple_tokens( - story_client, ip_id, setup_license_terms + story_client: StoryClient, ip_id, setup_license_terms ): """Test predicting minting fee for multiple tokens.""" response = story_client.License.predict_minting_license_fee( diff --git a/tests/integration/test_integration_nft_client.py b/tests/integration/test_integration_nft_client.py index 2c2fa26..e68b1c0 100644 --- a/tests/integration/test_integration_nft_client.py +++ b/tests/integration/test_integration_nft_client.py @@ -3,17 +3,15 @@ import pytest from web3 import Web3 -from setup_for_integration import ( - story_client, - MockERC721, - MockERC20, -) +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import MockERC20 class TestNFTCollectionOperations: """Tests for NFT collection creation and management""" - def test_create_basic_collection(self, story_client): + def test_create_basic_collection(self, story_client: StoryClient): """Test creating a basic NFT collection with minimum parameters""" response = story_client.NFTClient.create_nft_collection( name="test-collection", @@ -31,7 +29,7 @@ def test_create_basic_collection(self, story_client): assert "nft_contract" in response assert Web3.is_address(response["nft_contract"]) - def test_create_collection_with_supply(self, story_client): + def test_create_collection_with_supply(self, story_client: StoryClient): """Test creating collection with max supply""" response = story_client.NFTClient.create_nft_collection( name="test-collection", @@ -47,7 +45,7 @@ def test_create_collection_with_supply(self, story_client): assert "nft_contract" in response assert Web3.is_address(response["nft_contract"]) - def test_create_collection_with_mint_fee(self, story_client): + def test_create_collection_with_mint_fee(self, story_client: StoryClient): """Test creating collection with mint fee configuration""" response = story_client.NFTClient.create_nft_collection( name="test-collection", @@ -64,7 +62,7 @@ def test_create_collection_with_mint_fee(self, story_client): assert "nft_contract" in response assert Web3.is_address(response["nft_contract"]) - def test_create_collection_with_base_uri(self, story_client): + def test_create_collection_with_base_uri(self, story_client: StoryClient): """Test creating collection with base URI""" response = story_client.NFTClient.create_nft_collection( name="test-collection", @@ -84,7 +82,7 @@ def test_create_collection_with_base_uri(self, story_client): class TestErrorCases: """Tests for error handling in NFT collection creation""" - def test_invalid_mint_fee_configuration(self, story_client): + def test_invalid_mint_fee_configuration(self, story_client: StoryClient): """Test error when mint fee is set but token address is invalid""" with pytest.raises(ValueError) as exc_info: story_client.NFTClient.create_nft_collection( @@ -99,7 +97,7 @@ def test_invalid_mint_fee_configuration(self, story_client): ) assert "Invalid mint fee token address" in str(exc_info.value) - def test_invalid_recipient_address(self, story_client): + def test_invalid_recipient_address(self, story_client: StoryClient): """Test error when mint fee recipient address is invalid""" with pytest.raises(ValueError) as exc_info: story_client.NFTClient.create_nft_collection( @@ -115,7 +113,7 @@ def test_invalid_recipient_address(self, story_client): in str(exc_info.value).lower() ) - def test_invalid_mint_fee_values(self, story_client): + def test_invalid_mint_fee_values(self, story_client: StoryClient): """Test with invalid mint fee values""" with pytest.raises(ValueError) as exc_info: story_client.NFTClient.create_nft_collection( @@ -150,10 +148,10 @@ def test_invalid_mint_fee_values(self, story_client): or "invalid" in str(e).lower() ) - def test_parameter_omission(self, story_client): + def test_parameter_omission(self, story_client: StoryClient): """Test omitting required parameters""" - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( # name is omitted symbol="TEST", @@ -163,7 +161,7 @@ def test_parameter_omission(self, story_client): mint_fee_recipient=story_client.account.address, ) - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( name="test-collection", # symbol is omitted @@ -173,7 +171,7 @@ def test_parameter_omission(self, story_client): mint_fee_recipient=story_client.account.address, ) - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -183,7 +181,7 @@ def test_parameter_omission(self, story_client): mint_fee_recipient=story_client.account.address, ) - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -193,7 +191,7 @@ def test_parameter_omission(self, story_client): mint_fee_recipient=story_client.account.address, ) - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -203,7 +201,7 @@ def test_parameter_omission(self, story_client): mint_fee_recipient=story_client.account.address, ) - with pytest.raises(TypeError) as exc_info: + with pytest.raises(TypeError): story_client.NFTClient.create_nft_collection( name="test-collection", symbol="TEST", @@ -213,7 +211,7 @@ def test_parameter_omission(self, story_client): # mint_fee_recipient is omitted ) - def test_authorization_errors(self, story_client): + def test_authorization_errors(self, story_client: StoryClient): """Test unauthorized operations""" different_owner = "0x1234567890123456789012345678901234567890" @@ -237,7 +235,7 @@ class TestMintFee: """Tests for mint fee functionality in NFT collections""" @pytest.fixture(scope="module") - def nft_contract(self, story_client): + def nft_contract(self, story_client: StoryClient): response = story_client.NFTClient.create_nft_collection( name="paid-collection", symbol="PAID", @@ -252,12 +250,12 @@ def nft_contract(self, story_client): return response["nft_contract"] - def test_get_mint_fee_token(self, story_client, nft_contract): + def test_get_mint_fee_token(self, story_client: StoryClient, nft_contract): """Test successfully getting mint fee token""" mint_fee_token = story_client.NFTClient.get_mint_fee_token(nft_contract) assert mint_fee_token == MockERC20 - def test_get_mint_fee(self, story_client, nft_contract): + def test_get_mint_fee(self, story_client: StoryClient, nft_contract): """Test successfully getting mint fee""" mint_fee = story_client.NFTClient.get_mint_fee(nft_contract) assert mint_fee == 1000 diff --git a/tests/integration/test_integration_permission.py b/tests/integration/test_integration_permission.py index a82aa4d..ae0e06e 100644 --- a/tests/integration/test_integration_permission.py +++ b/tests/integration/test_integration_permission.py @@ -1,21 +1,21 @@ # tests/integration/test_integration_permission.py import pytest -from web3 import Web3 -from setup_for_integration import ( - web3, +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import ( + CORE_METADATA_MODULE, + MockERC721, account, - story_client, get_token_id, - MockERC721, - CORE_METADATA_MODULE, + web3, ) class TestPermissions: @pytest.fixture(scope="class") - def ip_id(self, story_client): + def ip_id(self, story_client: StoryClient): """Fixture to create an IP for testing permissions.""" token_id = get_token_id(MockERC721, story_client.web3, story_client.account) response = story_client.IPAsset.register( @@ -24,7 +24,7 @@ def ip_id(self, story_client): assert "ip_id" in response, "Failed to register IP" return response["ip_id"] - def test_set_permission(self, story_client, ip_id): + def test_set_permission(self, story_client: StoryClient, ip_id): """Test setting permission successfully.""" response = story_client.Permission.set_permission( ip_id=ip_id, @@ -39,7 +39,7 @@ def test_set_permission(self, story_client, ip_id): assert isinstance(response["tx_hash"], str) assert len(response["tx_hash"]) > 0 - def test_set_all_permissions(self, story_client, ip_id): + def test_set_all_permissions(self, story_client: StoryClient, ip_id): """Test setting all permissions successfully.""" response = story_client.Permission.set_all_permissions( ip_id=ip_id, signer=account.address, permission=1 # ALLOW @@ -50,7 +50,7 @@ def test_set_all_permissions(self, story_client, ip_id): assert isinstance(response["tx_hash"], str) assert len(response["tx_hash"]) > 0 - def test_create_set_permission_signature(self, story_client, ip_id): + def test_create_set_permission_signature(self, story_client: StoryClient, ip_id): """Test creating set permission signature.""" deadline = web3.eth.get_block("latest")["timestamp"] + 60000 @@ -68,7 +68,7 @@ def test_create_set_permission_signature(self, story_client, ip_id): assert isinstance(response["tx_hash"], str) assert len(response["tx_hash"]) > 0 - def test_set_permission_invalid_ip(self, story_client): + def test_set_permission_invalid_ip(self, story_client: StoryClient): """Test setting permission for an unregistered IP.""" unregistered_ip = "0x1234567890123456789012345678901234567890" @@ -82,7 +82,7 @@ def test_set_permission_invalid_ip(self, story_client): assert f"IP id with {unregistered_ip} is not registered" in str(exc_info.value) - def test_set_permission_invalid_addresses(self, story_client, ip_id): + def test_set_permission_invalid_addresses(self, story_client: StoryClient, ip_id): """Test that set_permission raises proper exceptions for invalid addresses.""" invalid_signer = "0xinvalid_address" @@ -122,7 +122,7 @@ def test_set_permission_invalid_addresses(self, story_client, ip_id): f"set_permission should accept lowercase addresses, but raised: {e}" ) - def test_different_permission_levels(self, story_client, ip_id): + def test_different_permission_levels(self, story_client: StoryClient, ip_id): """Test setting and changing different permission levels.""" DISALLOW = 0 ALLOW = 1 @@ -177,7 +177,7 @@ def test_different_permission_levels(self, story_client, ip_id): assert response is not None assert "tx_hash" in response - def test_different_function_selectors(self, story_client, ip_id): + def test_different_function_selectors(self, story_client: StoryClient, ip_id): """Test setting permissions with different function selectors.""" ALLOW = 1 @@ -240,7 +240,9 @@ def test_different_function_selectors(self, story_client, ip_id): assert response is not None assert "tx_hash" in response - def test_permission_hierarchies_and_overrides(self, story_client, ip_id): + def test_permission_hierarchies_and_overrides( + self, story_client: StoryClient, ip_id + ): """Test permission hierarchies and how permissions override each other.""" DISALLOW = 0 ALLOW = 1 diff --git a/tests/integration/test_integration_royalty.py b/tests/integration/test_integration_royalty.py index 5cfdcfe..262f8ec 100644 --- a/tests/integration/test_integration_royalty.py +++ b/tests/integration/test_integration_royalty.py @@ -1,29 +1,30 @@ # tests/integration/test_integration_royalty.py -import pytest -from web3 import Web3 import copy -from setup_for_integration import ( - web3, +import pytest + +from story_protocol_python_sdk.story_client import StoryClient + +from .setup_for_integration import ( + PIL_LICENSE_TEMPLATE, + ROYALTY_MODULE, + ROYALTY_POLICY, + ZERO_ADDRESS, + MockERC20, + MockERC721, account, - story_client, + approve, get_token_id, mint_tokens, - approve, - MockERC721, - MockERC20, - ZERO_ADDRESS, - ROYALTY_POLICY, - ROYALTY_MODULE, - PIL_LICENSE_TEMPLATE, + web3, ) class TestRoyalty: @pytest.fixture(scope="module") - def setup_ips_and_licenses(self, story_client): + def setup_ips_and_licenses(self, story_client: StoryClient): """Setup parent and child IPs with proper license relationships""" parent_token_id = get_token_id( @@ -87,7 +88,9 @@ def setup_ips_and_licenses(self, story_client): "license_terms_id": license_terms_id, } - def test_pay_royalty_on_behalf(self, story_client, setup_ips_and_licenses): + def test_pay_royalty_on_behalf( + self, story_client: StoryClient, setup_ips_and_licenses + ): """Test paying royalty on behalf of a payer IP to a receiver IP""" parent_ip_id = setup_ips_and_licenses["parent_ip_id"] child_ip_id = setup_ips_and_licenses["child_ip_id"] @@ -102,7 +105,7 @@ def test_pay_royalty_on_behalf(self, story_client, setup_ips_and_licenses): assert response is not None assert response["tx_hash"] is not None and isinstance(response["tx_hash"], str) - def test_claimable_revenue(self, story_client, setup_ips_and_licenses): + def test_claimable_revenue(self, story_client: StoryClient, setup_ips_and_licenses): """Test checking claimable revenue""" parent_ip_id = setup_ips_and_licenses["parent_ip_id"] @@ -113,7 +116,7 @@ def test_claimable_revenue(self, story_client, setup_ips_and_licenses): assert isinstance(response, int) def test_pay_royalty_unregistered_receiver( - self, story_client, setup_ips_and_licenses + self, story_client: StoryClient, setup_ips_and_licenses ): """Test that paying royalty to unregistered IP fails appropriately""" child_ip_id = setup_ips_and_licenses["child_ip_id"] @@ -130,7 +133,9 @@ def test_pay_royalty_unregistered_receiver( amount=1000, ) - def test_pay_royalty_invalid_amount(self, story_client, setup_ips_and_licenses): + def test_pay_royalty_invalid_amount( + self, story_client: StoryClient, setup_ips_and_licenses + ): """Test that paying with invalid amount fails appropriately""" parent_ip_id = setup_ips_and_licenses["parent_ip_id"] child_ip_id = setup_ips_and_licenses["child_ip_id"] @@ -146,7 +151,7 @@ def test_pay_royalty_invalid_amount(self, story_client, setup_ips_and_licenses): class TestClaimAllRevenue: @pytest.fixture(scope="module") - def setup_claim_all_revenue(self, story_client): + def setup_claim_all_revenue(self, story_client: StoryClient): # Create NFT collection collection_response = story_client.NFTClient.create_nft_collection( name="free-collection", @@ -269,7 +274,9 @@ def setup_claim_all_revenue(self, story_client): return {"ip_a": ip_a, "ip_b": ip_b, "ip_c": ip_c, "ip_d": ip_d} - def test_claim_all_revenue(self, setup_claim_all_revenue, story_client): + def test_claim_all_revenue( + self, setup_claim_all_revenue, story_client: StoryClient + ): response = story_client.Royalty.claim_all_revenue( ancestor_ip_id=setup_claim_all_revenue["ip_a"], claimer=setup_claim_all_revenue["ip_a"], @@ -288,7 +295,7 @@ def test_claim_all_revenue(self, setup_claim_all_revenue, story_client): assert response["claimed_tokens"][0]["amount"] == 120 @pytest.fixture(scope="module") - def setup_claim_all_revenue_claim_options(self, story_client): + def setup_claim_all_revenue_claim_options(self, story_client: StoryClient): # Create NFT collection collection_response = story_client.NFTClient.create_nft_collection( name="free-collection", @@ -387,7 +394,7 @@ def setup_claim_all_revenue_claim_options(self, story_client): spg_nft_contract=spg_nft_contract, ip_metadata=metadata_b ) ip_b = ip_b_response["ip_id"] - ip_b_derivative_response = story_client.IPAsset.register_derivative( + story_client.IPAsset.register_derivative( child_ip_id=ip_b, parent_ip_ids=[ip_a], license_terms_ids=[license_terms_id] ) @@ -412,7 +419,7 @@ def setup_claim_all_revenue_claim_options(self, story_client): return {"ip_a": ip_a, "ip_b": ip_b, "ip_c": ip_c, "ip_d": ip_d} def test_claim_all_revenue_claim_options( - self, setup_claim_all_revenue_claim_options, story_client + self, setup_claim_all_revenue_claim_options, story_client: StoryClient ): """Test claiming all revenue with specific claim options""" response = story_client.Royalty.claim_all_revenue( diff --git a/tests/integration/test_integration_wip.py b/tests/integration/test_integration_wip.py index 51dae43..b6d12b8 100644 --- a/tests/integration/test_integration_wip.py +++ b/tests/integration/test_integration_wip.py @@ -1,15 +1,12 @@ -# tests/integration/test_integration_wip.py +from story_protocol_python_sdk.story_client import StoryClient -import pytest -from web3 import Web3 - -from setup_for_integration import web3, story_client, wallet_address, wallet_address_2 +from .setup_for_integration import wallet_address, wallet_address_2, web3 class TestWIPDeposit: - def test_deposit(self, story_client): + def test_deposit(self, story_client: StoryClient): """Test depositing IP to WIP""" - ip_amt = Web3.to_wei(1, "ether") # or Web3.to_wei("0.01", 'ether') + ip_amt = web3.to_wei(1, "ether") # or Web3.to_wei("0.01", 'ether') # Get balances before deposit balance_before = story_client.get_wallet_balance() @@ -39,9 +36,9 @@ def test_deposit(self, story_client): class TestWIPTransfer: - def test_transfer(self, story_client): + def test_transfer(self, story_client: StoryClient): """Test transferring WIP""" - transfer_amount = Web3.to_wei("0.01", "ether") + transfer_amount = web3.to_wei("0.01", "ether") # Get balances before transfer sender_wip_before = story_client.WIP.balance_of(wallet_address) @@ -71,7 +68,7 @@ def test_transfer(self, story_client): class TestWIPWithdraw: - def test_withdraw(self, story_client): + def test_withdraw(self, story_client: StoryClient): """Test withdrawing WIP to IP""" # Get balances before withdrawal balance_before = story_client.get_wallet_balance() diff --git a/tests/unit/fixtures/web3.py b/tests/unit/fixtures/web3.py index aa33b40..6817f8e 100644 --- a/tests/unit/fixtures/web3.py +++ b/tests/unit/fixtures/web3.py @@ -1,8 +1,8 @@ -from web3 import Web3 from unittest.mock import MagicMock, Mock -from tests.unit.fixtures.data import ADDRESS +from web3 import Web3 +from tests.unit.fixtures.data import ADDRESS mock_web3 = Mock(spec=Web3) mock_web3.to_checksum_address = MagicMock(return_value=ADDRESS) diff --git a/tests/unit/resources/test_ip_account.py b/tests/unit/resources/test_ip_account.py index 3317511..0c95e5b 100644 --- a/tests/unit/resources/test_ip_account.py +++ b/tests/unit/resources/test_ip_account.py @@ -1,18 +1,10 @@ -import os -import sys +from unittest.mock import MagicMock, patch + import pytest -from unittest.mock import patch, MagicMock -from web3 import Web3 -from web3.exceptions import InvalidAddress from eth_utils import is_address, to_checksum_address +from web3 import Web3 -# Ensure the src directory is in the Python path -current_dir = os.path.dirname(__file__) -src_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..")) -if src_path not in sys.path: - sys.path.append(src_path) - -from src.story_protocol_python_sdk.resources.IPAccount import IPAccount +from story_protocol_python_sdk.resources.IPAccount import IPAccount # Constants ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" diff --git a/tests/unit/resources/test_ip_asset.py b/tests/unit/resources/test_ip_asset.py index 7c041df..8fe3917 100644 --- a/tests/unit/resources/test_ip_asset.py +++ b/tests/unit/resources/test_ip_asset.py @@ -1,16 +1,10 @@ -import os -import sys +from unittest.mock import MagicMock, patch + import pytest -from unittest.mock import patch, MagicMock -from web3 import Web3 from eth_utils import is_address, to_checksum_address +from web3 import Web3 -current_dir = os.path.dirname(__file__) -src_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..")) -if src_path not in sys.path: - sys.path.append(src_path) - -from src.story_protocol_python_sdk.resources.IPAsset import IPAsset +from story_protocol_python_sdk.resources.IPAsset import IPAsset ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000" ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" diff --git a/tests/unit/resources/test_license.py b/tests/unit/resources/test_license.py index 259e43c..d2fdb50 100644 --- a/tests/unit/resources/test_license.py +++ b/tests/unit/resources/test_license.py @@ -1,17 +1,10 @@ -import logging +from unittest.mock import MagicMock, patch + import pytest -from unittest.mock import patch, MagicMock -from web3 import Web3 -import os -import sys from eth_utils import is_address, to_checksum_address +from web3 import Web3 -current_dir = os.path.dirname(__file__) -src_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..")) -if src_path not in sys.path: - sys.path.append(src_path) - -from src.story_protocol_python_sdk.resources.License import License +from story_protocol_python_sdk.resources.License import License ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" VALID_ADDRESS = "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c" diff --git a/tests/unit/resources/test_permission.py b/tests/unit/resources/test_permission.py index eb7b9c5..9b0687b 100644 --- a/tests/unit/resources/test_permission.py +++ b/tests/unit/resources/test_permission.py @@ -1,8 +1,9 @@ -import pytest from unittest.mock import Mock, patch +import pytest + from story_protocol_python_sdk.resources.Permission import Permission -from tests.unit.fixtures.data import CHAIN_ID, ADDRESS, CHAIN_ID, STATE, TX_HASH +from tests.unit.fixtures.data import ADDRESS, CHAIN_ID, STATE, TX_HASH from tests.unit.fixtures.web3 import mock_web3 diff --git a/tests/unit/resources/test_royalty.py b/tests/unit/resources/test_royalty.py index d4c901d..246db0d 100644 --- a/tests/unit/resources/test_royalty.py +++ b/tests/unit/resources/test_royalty.py @@ -1,31 +1,10 @@ -import pytest, os, sys -from unittest.mock import patch, MagicMock -from web3 import Web3 - -# Ensure the src directory is in the Python path -current_dir = os.path.dirname(__file__) -src_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..")) -if src_path not in sys.path: - sys.path.append(src_path) - -from src.story_protocol_python_sdk.resources.Royalty import Royalty - -# Load environment variables from .env file -from dotenv import load_dotenv +from unittest.mock import patch -load_dotenv() -private_key = os.getenv("WALLET_PRIVATE_KEY") -rpc_url = os.getenv("RPC_PROVIDER_URL") - -# Initialize Web3 -web3 = Web3(Web3.HTTPProvider(rpc_url)) - -# Check if connected -if not web3.is_connected(): - raise Exception("Failed to connect to Web3 provider") +import pytest +from web3 import Web3 -# Set up the account with the private key -account = web3.eth.account.from_key(private_key) +from story_protocol_python_sdk.resources.Royalty import Royalty +from tests.integration.config.test_config import account, web3 @pytest.fixture diff --git a/tests/unit/test_story_client.py b/tests/unit/test_story_client.py index afb0c23..f5205cd 100644 --- a/tests/unit/test_story_client.py +++ b/tests/unit/test_story_client.py @@ -1,38 +1,14 @@ -import os -import sys import pytest -from web3 import Web3 -from dotenv import load_dotenv -from story_protocol_python_sdk.story_client import StoryClient +from story_protocol_python_sdk.resources.IPAccount import IPAccount from story_protocol_python_sdk.resources.IPAsset import IPAsset from story_protocol_python_sdk.resources.License import License -from story_protocol_python_sdk.resources.Royalty import Royalty -from story_protocol_python_sdk.resources.IPAccount import IPAccount from story_protocol_python_sdk.resources.Permission import Permission +from story_protocol_python_sdk.resources.Royalty import Royalty +from story_protocol_python_sdk.story_client import StoryClient +from tests.integration.config.test_config import account, web3 from tests.unit.fixtures.data import CHAIN_ID -# Load environment variables from .env file -load_dotenv() -private_key = os.getenv("WALLET_PRIVATE_KEY") -rpc_url = os.getenv("RPC_PROVIDER_URL") - -# Ensure the environment variables are set -if not private_key or not rpc_url: - raise ValueError( - "Please set WALLET_PRIVATE_KEY and RPC_PROVIDER_URL in the .env file" - ) - -# Initialize Web3 -web3 = Web3(Web3.HTTPProvider(rpc_url)) - -# Check if connected -if not web3.is_connected(): - raise Exception("Failed to connect to Web3 provider") - -# Set up the account with the private key -account = web3.eth.account.from_key(private_key) - @pytest.fixture def story_client():