Skip to content

Commit

Permalink
feat: Change update api to be an instance method (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianlunz-cb authored Dec 18, 2024
1 parent 7f4780d commit 75d7bc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions cdp/smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions tests/test_smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,18 +1719,17 @@ 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
mock_updated_contract.return_value = expected_smart_contract
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)
Expand Down

0 comments on commit 75d7bc4

Please sign in to comment.