From 3e6bb3a58ee0f0819067f813ba5109886fbd6a35 Mon Sep 17 00:00:00 2001 From: Jianlun Zhong Date: Wed, 18 Dec 2024 10:52:40 -0800 Subject: [PATCH] feat: Change update api to be an instance method --- CHANGELOG.md | 5 +++++ cdp/smart_contract.py | 14 +++++--------- tests/test_smart_contract.py | 5 ++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bac05be..b9905b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Added + +- Add support for registering, updating, and listing smart contracts that are +deployed external to CDP. + - Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function ### [0.12.1] - 2024-12-10 diff --git a/cdp/smart_contract.py b/cdp/smart_contract.py index bd5689c..0b43462 100644 --- a/cdp/smart_contract.py +++ b/cdp/smart_contract.py @@ -414,20 +414,15 @@ def read( ) return cls._convert_solidity_value(model) - @classmethod def update( - cls, - contract_address: str, - network_id: str, + self, contract_name: str | None = None, abi: list[dict] | None = None, ) -> "SmartContract": """Update an existing SmartContract. Args: - network_id: The ID of the network. contract_name: The name of the smart contract. - contract_address: The address of the smart contract. abi: The ABI of the smart contract. Returns: @@ -445,12 +440,13 @@ def update( ) model = Cdp.api_clients.smart_contracts.update_smart_contract( - contract_address=contract_address, - network_id=network_id, + contract_address=self.contract_address, + network_id=self.network_id, update_smart_contract_request=update_smart_contract_request, ) - return cls(model) + self._model = model + return self @classmethod def register( diff --git a/tests/test_smart_contract.py b/tests/test_smart_contract.py index cf2a03a..2f2ea90 100644 --- a/tests/test_smart_contract.py +++ b/tests/test_smart_contract.py @@ -1719,6 +1719,7 @@ def test_update_smart_contract(mock_api_clients, smart_contract_factory, all_rea abi = '{"abi":"data2"}' abi_json = json.loads(abi) + existing_smart_contract = smart_contract_factory() expected_smart_contract = smart_contract_factory()._model expected_smart_contract.contract_name = contract_name expected_smart_contract.abi = abi @@ -1726,11 +1727,9 @@ def test_update_smart_contract(mock_api_clients, smart_contract_factory, all_rea contract_address = expected_smart_contract.contract_address network_id = expected_smart_contract.network_id - smart_contract = SmartContract.update( + smart_contract = existing_smart_contract.update( abi=abi_json, contract_name=contract_name, - contract_address=contract_address, - network_id=network_id, ) assert isinstance(smart_contract, SmartContract)