Skip to content

Commit

Permalink
Add a doc section on enable_strict_bytes_type_checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Sep 19, 2019
1 parent 9cf57a4 commit 3bb9369
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ The following values will raise an error by default:
- String is not valid hex

However, you may want to be stricter with acceptable values for bytes types.
For this you can use the ``enable_strict_bytes_type_checking`` method,
For this you can use the :meth:`w3.enable_strict_bytes_type_checking()` method,
which is available on the web3 instance. A web3 instance which has had this method
invoked will enforce a stricter set of rules on which values are accepted.

Expand Down
32 changes: 32 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,38 @@ Cryptographic Hashing
>>> Web3.soliditySha3(['address'], ["ethereumfoundation.eth"])
HexBytes("0x913c99ea930c78868f1535d34cd705ab85929b2eaaf70fcd09677ecd6e5d75e9")
Check Encodability
~~~~~~~~~~~~~~~~~~~~

.. py:method:: w3.is_encodable(_type, value)
Returns ``True`` if a value can be encoded as the given type. Otherwise returns ``False``.

.. code-block:: python
>>> from web3.auto.gethdev import w3
>>> w3.is_encodable('bytes2', b'12')
True
>>> w3.is_encodable('bytes2', b'1')
True
>>> w3.is_encodable('bytes2', '0x1234')
True
>>> w3.is_encodable('bytes2', b'123')
False
.. py:method:: w3.enable_strict_bytes_type_checking()
Enables stricter bytes type checking. For more examples see :ref:`enable-strict-byte-check`

.. doctest::

>>> from web3.auto.gethdev import w3
>>> w3.enable_strict_bytes_type_checking()
>>> w3.is_encodable('bytes2', b'12')
True
>>> w3.is_encodable('bytes2', b'1')
False

Modules
-------

Expand Down

0 comments on commit 3bb9369

Please sign in to comment.