Skip to content

Commit e4de990

Browse files
Fix
1 parent 0b8922b commit e4de990

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

cdp/evm_call_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from web3.types import HexStr, Wei
66

77

8-
class EVMCallDict(BaseModel):
8+
class EncodedCall(BaseModel):
99
"""Represents an encoded call to a smart contract."""
1010

1111
to: HexAddress = Field(..., description="Target contract address")
1212
value: Wei | None = Field(None, description="Amount of native currency to send")
1313
data: HexStr | None = Field(None, description="Encoded call data")
1414

1515

16-
class EVMAbiCallDict(BaseModel):
16+
class FunctionCall(BaseModel):
1717
"""Represents a call to a smart contract that needs to be encoded using the ABI."""
1818

1919
to: HexAddress = Field(..., description="Target contract address")
@@ -23,4 +23,4 @@ class EVMAbiCallDict(BaseModel):
2323
args: list[Any] = Field(..., description="Arguments to pass to the function")
2424

2525

26-
EVMCall = EVMCallDict | EVMAbiCallDict
26+
ContractCall = EncodedCall | FunctionCall

cdp/smart_wallet.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from cdp.cdp import Cdp
55
from cdp.client.models.call import Call
66
from cdp.client.models.create_smart_wallet_request import CreateSmartWalletRequest
7-
from cdp.evm_call_types import EVMAbiCallDict, EVMCall
7+
from cdp.evm_call_types import ContractCall, FunctionCall
88
from cdp.network import Network
99
from cdp.user_operation import UserOperation
1010

@@ -79,7 +79,7 @@ def use_network(
7979
)
8080

8181
def send_user_operation(
82-
self, calls: list[EVMCall], chain_id: int, paymaster_url: str | None = None
82+
self, calls: list[ContractCall], chain_id: int, paymaster_url: str | None = None
8383
) -> UserOperation:
8484
"""Send a user operation.
8585
@@ -102,7 +102,7 @@ def send_user_operation(
102102

103103
encoded_calls = []
104104
for call in calls:
105-
if isinstance(call, EVMAbiCallDict):
105+
if isinstance(call, FunctionCall):
106106
contract = Web3().eth.contract(address=call.to, abi=call.abi)
107107
data = contract.encode_abi(call.function_name, args=call.args)
108108
value = "0" if call.value is None else str(call.value)
@@ -188,7 +188,7 @@ def paymaster_url(self) -> str | None:
188188

189189
def send_user_operation(
190190
self,
191-
calls: list[EVMCall],
191+
calls: list[ContractCall],
192192
) -> UserOperation:
193193
"""Send a user operation on the configured network.
194194

tests/test_evm_call_types.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest
22
from web3.types import Wei
33

4-
from cdp.evm_call_types import EVMAbiCallDict, EVMCall, EVMCallDict
4+
from cdp.evm_call_types import ContractCall, EncodedCall, FunctionCall
55

66

77
def test_evm_call_dict_valid():
88
"""Test that the EVMCallDict is valid."""
9-
call = EVMCallDict(to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
9+
call = EncodedCall(to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
1010
assert isinstance(call.to, str)
1111
assert call.value is None
1212
assert call.data is None
1313

14-
call = EVMCallDict(
14+
call = EncodedCall(
1515
to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
1616
value=Wei(1000000000000000000),
1717
data="0x095ea7b30000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e",
@@ -23,7 +23,7 @@ def test_evm_call_dict_valid():
2323

2424
def test_evm_abi_call_dict_valid():
2525
"""Test that the EVMAbiCallDict is valid."""
26-
call = EVMAbiCallDict(
26+
call = FunctionCall(
2727
to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
2828
abi=[
2929
{
@@ -43,7 +43,7 @@ def test_evm_abi_call_dict_valid():
4343
assert call.function_name == "totalSupply"
4444
assert call.args == []
4545

46-
call = EVMAbiCallDict(
46+
call = FunctionCall(
4747
to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
4848
value=Wei(1000000000000000000),
4949
abi=[
@@ -71,20 +71,18 @@ def test_evm_abi_call_dict_valid():
7171
def test_evm_abi_call_dict_invalid():
7272
"""Test that the EVMAbiCallDict is invalid."""
7373
with pytest.raises(ValueError):
74-
EVMAbiCallDict(
75-
to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e", function_name="test", args=[]
76-
)
74+
FunctionCall(to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e", function_name="test", args=[])
7775

7876

7977
def test_evm_call_union():
8078
"""Test that the EVMCall union is valid."""
81-
call_dict = EVMCallDict(to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
82-
abi_call_dict = EVMAbiCallDict(
79+
call_dict = EncodedCall(to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
80+
abi_call_dict = FunctionCall(
8381
to="0x742d35Cc6634C0532925a3b844Bc454e4438f44e", abi=[], function_name="test", args=[]
8482
)
8583

86-
call: EVMCall = call_dict
87-
assert isinstance(call, EVMCallDict)
84+
call: ContractCall = call_dict
85+
assert isinstance(call, EncodedCall)
8886

8987
call = abi_call_dict
90-
assert isinstance(call, EVMAbiCallDict)
88+
assert isinstance(call, FunctionCall)

tests/test_smart_wallet.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from cdp.client.models.call import Call
77
from cdp.client.models.create_smart_wallet_request import CreateSmartWalletRequest
8-
from cdp.evm_call_types import EVMAbiCallDict, EVMCallDict
8+
from cdp.evm_call_types import EncodedCall, FunctionCall
99
from cdp.smart_wallet import SmartWallet, to_smart_wallet
1010
from cdp.user_operation import UserOperation
1111

@@ -73,7 +73,7 @@ def test_smart_wallet_send_user_operation_with_encoded_call(
7373
mock_create_user_operation = Mock(return_value=mock_user_operation)
7474
mock_api_clients.smart_wallets.create_user_operation = mock_create_user_operation
7575

76-
calls = [EVMCallDict(to=account.address, value=1000000000000000000, data="0x")]
76+
calls = [EncodedCall(to=account.address, value=1000000000000000000, data="0x")]
7777

7878
user_operation = smart_wallet.send_user_operation(
7979
calls=calls, chain_id=84532, paymaster_url="https://paymaster.com"
@@ -111,7 +111,7 @@ def test_send_user_operation_with_abi_call(
111111
mock_create_user_operation = Mock(return_value=mock_user_operation)
112112
mock_api_clients.smart_wallets.create_user_operation = mock_create_user_operation
113113

114-
abi_call = EVMAbiCallDict(
114+
abi_call = FunctionCall(
115115
to=account.address,
116116
abi=[{"inputs": [], "name": "transfer", "type": "function"}],
117117
function_name="transfer",
@@ -140,9 +140,9 @@ def test_smart_wallet_multiple_calls(
140140
smart_wallet = smart_wallet_factory(smart_wallet_address, account)
141141

142142
calls = [
143-
EVMCallDict(to=account.address, value=1000000000000000000, data="0x"),
144-
EVMCallDict(to=account.address, value=0, data="0x123"),
145-
EVMCallDict(to=account.address, value=None, data=None),
143+
EncodedCall(to=account.address, value=1000000000000000000, data="0x"),
144+
EncodedCall(to=account.address, value=0, data="0x123"),
145+
EncodedCall(to=account.address, value=None, data=None),
146146
]
147147

148148
model_calls = [Call(to=c.to, value=str(c.value or 0), data=c.data or "0x") for c in calls]
@@ -207,7 +207,7 @@ def test_network_scoped_wallet_send_operation(
207207
mock_create_user_operation = Mock(return_value=mock_user_operation)
208208
mock_api_clients.smart_wallets.create_user_operation = mock_create_user_operation
209209

210-
calls = [EVMCallDict(to=account.address, value=1000000000000000000, data="0x")]
210+
calls = [EncodedCall(to=account.address, value=1000000000000000000, data="0x")]
211211
user_operation = network_wallet.send_user_operation(calls=calls)
212212

213213
assert user_operation.smart_wallet_address == smart_wallet_address

0 commit comments

Comments
 (0)