Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 6, 2024
1 parent a5f23fd commit c9d98c7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cdp/client/models/solidity_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class SolidityValue(BaseModel):
@field_validator('type')
def type_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(['uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint160', 'uint256', 'int8', 'int16', 'int24', 'int32', 'int64', 'int128', 'int256', 'address', 'bool', 'string', 'bytes', 'bytes1', 'bytes2', 'bytes3', 'bytes4', 'bytes5', 'bytes6', 'bytes7', 'bytes8', 'bytes9', 'bytes10', 'bytes11', 'bytes12', 'bytes13', 'bytes14', 'bytes15', 'bytes16', 'bytes17', 'bytes18', 'bytes19', 'bytes20', 'bytes21', 'bytes22', 'bytes23', 'bytes24', 'bytes25', 'bytes26', 'bytes27', 'bytes28', 'bytes29', 'bytes30', 'bytes31', 'bytes32', 'array', 'tuple']):
raise ValueError("must be one of enum values ('uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint160', 'uint256', 'int8', 'int16', 'int24', 'int32', 'int64', 'int128', 'int256', 'address', 'bool', 'string', 'bytes', 'bytes1', 'bytes2', 'bytes3', 'bytes4', 'bytes5', 'bytes6', 'bytes7', 'bytes8', 'bytes9', 'bytes10', 'bytes11', 'bytes12', 'bytes13', 'bytes14', 'bytes15', 'bytes16', 'bytes17', 'bytes18', 'bytes19', 'bytes20', 'bytes21', 'bytes22', 'bytes23', 'bytes24', 'bytes25', 'bytes26', 'bytes27', 'bytes28', 'bytes29', 'bytes30', 'bytes31', 'bytes32', 'array', 'tuple')")
if value not in set(['uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint160', 'uint256', 'int8', 'int16', 'int24', 'int32', 'int56', 'int64', 'int128', 'int256', 'address', 'bool', 'string', 'bytes', 'bytes1', 'bytes2', 'bytes3', 'bytes4', 'bytes5', 'bytes6', 'bytes7', 'bytes8', 'bytes9', 'bytes10', 'bytes11', 'bytes12', 'bytes13', 'bytes14', 'bytes15', 'bytes16', 'bytes17', 'bytes18', 'bytes19', 'bytes20', 'bytes21', 'bytes22', 'bytes23', 'bytes24', 'bytes25', 'bytes26', 'bytes27', 'bytes28', 'bytes29', 'bytes30', 'bytes31', 'bytes32', 'array', 'tuple']):
raise ValueError("must be one of enum values ('uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint160', 'uint256', 'int8', 'int16', 'int24', 'int32', 'int56', 'int64', 'int128', 'int256', 'address', 'bool', 'string', 'bytes', 'bytes1', 'bytes2', 'bytes3', 'bytes4', 'bytes5', 'bytes6', 'bytes7', 'bytes8', 'bytes9', 'bytes10', 'bytes11', 'bytes12', 'bytes13', 'bytes14', 'bytes15', 'bytes16', 'bytes17', 'bytes18', 'bytes19', 'bytes20', 'bytes21', 'bytes22', 'bytes23', 'bytes24', 'bytes25', 'bytes26', 'bytes27', 'bytes28', 'bytes29', 'bytes30', 'bytes31', 'bytes32', 'array', 'tuple')")
return value

model_config = ConfigDict(
Expand Down
1 change: 1 addition & 0 deletions cdp/smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def _convert_solidity_value(cls, solidity_value: SolidityValue) -> Any:
"int16",
"int24",
"int32",
"int56",
"int64",
"int128",
"int256",
Expand Down
13 changes: 13 additions & 0 deletions tests/factories/smart_contract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ def all_read_types_abi():
],
"stateMutability": "pure",
},
{
"type": "function",
"name": "pureInt56",
"inputs": [],
"outputs": [
{
"name": "",
"type": "int56",
"internalType": "int56",
},
],
"stateMutability": "pure",
},
{
"type": "function",
"name": "pureInt64",
Expand Down
22 changes: 22 additions & 0 deletions tests/test_smart_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,28 @@ def test_read_pure_int32(mock_api_clients, all_read_types_abi):
)


@patch("cdp.Cdp.api_clients")
def test_read_pure_int56(mock_api_clients, all_read_types_abi):
"""Test reading an int56 value from a pure function."""
mock_read_contract = Mock()
mock_read_contract.return_value = SolidityValue(type="int56", value="-72057594037927936")
mock_api_clients.smart_contracts.read_contract = mock_read_contract

result = SmartContract.read(
network_id="1",
contract_address="0x1234567890123456789012345678901234567890",
method="pureInt56",
abi=all_read_types_abi,
)

assert result == -72057594037927936
mock_read_contract.assert_called_once_with(
network_id="1",
contract_address="0x1234567890123456789012345678901234567890",
read_contract_request=ANY,
)


@patch("cdp.Cdp.api_clients")
def test_read_pure_int64(mock_api_clients, all_read_types_abi):
"""Test reading an int64 value from a pure function."""
Expand Down

0 comments on commit c9d98c7

Please sign in to comment.