當前位置: 首頁>>代碼示例>>Python>>正文


Python Web3.toBytes方法代碼示例

本文整理匯總了Python中web3.Web3.toBytes方法的典型用法代碼示例。如果您正苦於以下問題:Python Web3.toBytes方法的具體用法?Python Web3.toBytes怎麽用?Python Web3.toBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在web3.Web3的用法示例。


在下文中一共展示了Web3.toBytes方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: bytes32

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def bytes32(val):
    if isinstance(val, int):
        result = Web3.toBytes(val)
    else:
        raise TypeError('val %r could not be converted to bytes')
    if len(result) < 32:
        return result.rjust(32, b'\0')
    else:
        return result
開發者ID:pipermerriam,項目名稱:web3.py,代碼行數:11,代碼來源:conftest.py

示例2: test_set_address

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def test_set_address(ens, name, full_name, namehash_hex):
    assert ens.address(name) is None
    owner = ens.owner('tester')

    ens.setup_address(name, TEST_ADDRESS)
    assert ens.address(name) == TEST_ADDRESS

    # check that .eth is only appended if guess_tld is True
    namehash = Web3.toBytes(hexstr=namehash_hex)
    normal_name = ens.nameprep(full_name)
    if ens.nameprep(name) == normal_name:
        assert ens.address(name, guess_tld=False) == TEST_ADDRESS
    else:
        assert ens.address(name, guess_tld=False) is None

    # check that the correct namehash is set:
    assert ens.resolver(normal_name).addr(namehash) == TEST_ADDRESS

    # check that the correct owner is set:
    assert ens.owner(name) == owner

    ens.setup_address(name, None)
    assert ens.address(name) is None
開發者ID:syngraph,項目名稱:web3.py,代碼行數:25,代碼來源:test_setup_address.py

示例3: test_setup_name

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def test_setup_name(ens, name, normalized_name, namehash_hex):
    address = ens.web3.eth.accounts[3]
    assert not ens.name(address)
    owner = ens.owner('tester')

    ens.setup_name(name, address)
    assert ens.name(address) == normalized_name

    # check that .eth is only appended if guess_tld is True
    if ens.nameprep(name) != normalized_name:
        assert ens.address(name, guess_tld=False) is None

    # check that the correct namehash is set:
    node = Web3.toBytes(hexstr=namehash_hex)
    assert ens.resolver(normalized_name).addr(node) == address

    # check that the correct owner is set:
    assert ens.owner(name) == owner

    ens.setup_name(None, address)
    ens.setup_address(name, None)
    assert not ens.name(address)
    assert not ens.address(name)
開發者ID:syngraph,項目名稱:web3.py,代碼行數:25,代碼來源:test_setup_name.py

示例4: test_to_bytes_text

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def test_to_bytes_text(val, expected):
    assert Web3.toBytes(text=val) == expected
開發者ID:miohtama,項目名稱:web3.py,代碼行數:4,代碼來源:test_conversions.py

示例5: test_to_bytes_hexstr

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def test_to_bytes_hexstr(val, expected):
    assert Web3.toBytes(hexstr=val) == expected
開發者ID:miohtama,項目名稱:web3.py,代碼行數:4,代碼來源:test_conversions.py

示例6: test_to_bytes_primitive

# 需要導入模塊: from web3 import Web3 [as 別名]
# 或者: from web3.Web3 import toBytes [as 別名]
def test_to_bytes_primitive(val, expected):
    assert Web3.toBytes(val) == expected
開發者ID:miohtama,項目名稱:web3.py,代碼行數:4,代碼來源:test_conversions.py


注:本文中的web3.Web3.toBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。