Skip to content

Commit 3e6bb3a

Browse files
committed
feat: Change update api to be an instance method
1 parent 7f4780d commit 3e6bb3a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Added
6+
7+
- Add support for registering, updating, and listing smart contracts that are
8+
deployed external to CDP.
9+
510
- Add `network_id` to `WalletData` so that it is saved with the seed data and surfaced via the export function
611

712
### [0.12.1] - 2024-12-10

cdp/smart_contract.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,15 @@ def read(
414414
)
415415
return cls._convert_solidity_value(model)
416416

417-
@classmethod
418417
def update(
419-
cls,
420-
contract_address: str,
421-
network_id: str,
418+
self,
422419
contract_name: str | None = None,
423420
abi: list[dict] | None = None,
424421
) -> "SmartContract":
425422
"""Update an existing SmartContract.
426423
427424
Args:
428-
network_id: The ID of the network.
429425
contract_name: The name of the smart contract.
430-
contract_address: The address of the smart contract.
431426
abi: The ABI of the smart contract.
432427
433428
Returns:
@@ -445,12 +440,13 @@ def update(
445440
)
446441

447442
model = Cdp.api_clients.smart_contracts.update_smart_contract(
448-
contract_address=contract_address,
449-
network_id=network_id,
443+
contract_address=self.contract_address,
444+
network_id=self.network_id,
450445
update_smart_contract_request=update_smart_contract_request,
451446
)
452447

453-
return cls(model)
448+
self._model = model
449+
return self
454450

455451
@classmethod
456452
def register(

tests/test_smart_contract.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,18 +1719,17 @@ def test_update_smart_contract(mock_api_clients, smart_contract_factory, all_rea
17191719
abi = '{"abi":"data2"}'
17201720
abi_json = json.loads(abi)
17211721

1722+
existing_smart_contract = smart_contract_factory()
17221723
expected_smart_contract = smart_contract_factory()._model
17231724
expected_smart_contract.contract_name = contract_name
17241725
expected_smart_contract.abi = abi
17251726
mock_updated_contract.return_value = expected_smart_contract
17261727
contract_address = expected_smart_contract.contract_address
17271728
network_id = expected_smart_contract.network_id
17281729

1729-
smart_contract = SmartContract.update(
1730+
smart_contract = existing_smart_contract.update(
17301731
abi=abi_json,
17311732
contract_name=contract_name,
1732-
contract_address=contract_address,
1733-
network_id=network_id,
17341733
)
17351734

17361735
assert isinstance(smart_contract, SmartContract)

0 commit comments

Comments
 (0)