Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change update api to be an instance method #67

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading