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


Python web3.Web3類代碼示例

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


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

示例1: test_soliditySha3_ens

    def test_soliditySha3_ens(self, web3, types, values, expected):
        with ens_addresses(web3, {
            'one.eth': "0x49EdDD3769c0712032808D86597B84ac5c2F5614",
            'two.eth': "0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5",
        }):
            # when called as class method, any name lookup attempt will fail
            with pytest.raises(InvalidAddress):
                Web3.soliditySha3(types, values)

            # when called as instance method method, ens lookups can succeed
            actual = web3.soliditySha3(types, values)
            assert actual == expected
開發者ID:syngraph,項目名稱:web3.py,代碼行數:12,代碼來源:web3_module.py

示例2: test_labelhash

def test_labelhash(ens, label, expected_hash):
    if isinstance(expected_hash, type):
        with pytest.raises(expected_hash):
            ens.labelhash(label)
    else:
        labelhash = ens.labelhash(label)
        assert isinstance(labelhash, bytes)
        hash_hex = Web3.toHex(labelhash)
        assert hash_hex == expected_hash
開發者ID:miohtama,項目名稱:web3.py,代碼行數:9,代碼來源:test_get_registry.py

示例3: hash_balance_data

def hash_balance_data(
        transferred_amount: typing.TokenAmount,
        locked_amount: typing.TokenAmount,
        locksroot: typing.Locksroot,
) -> str:
    return Web3.soliditySha3(
        ['uint256', 'uint256', 'bytes32'],
        [transferred_amount, locked_amount, locksroot],
    )
開發者ID:AlphaX-IBS,項目名稱:raiden,代碼行數:9,代碼來源:utils.py

示例4: bytes32

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,代碼行數:9,代碼來源:conftest.py

示例5: hash_balance_data

def hash_balance_data(
        transferred_amount: TokenAmount,
        locked_amount: TokenAmount,
        locksroot: Locksroot,
) -> bytes:
    assert locksroot != b''
    assert len(locksroot) == 32
    if transferred_amount == 0 and locked_amount == 0 and locksroot == EMPTY_HASH:
        return EMPTY_HASH

    return Web3.soliditySha3(  # pylint: disable=no-value-for-parameter
        ['uint256', 'uint256', 'bytes32'],
        [transferred_amount, locked_amount, locksroot],
    )
開發者ID:hackaugusto,項目名稱:raiden,代碼行數:14,代碼來源:utils.py

示例6: test_eth_account_sign_transaction_from_eth_test

def test_eth_account_sign_transaction_from_eth_test(acct, transaction_info):
    expected_raw_txn = transaction_info['signed']
    key = transaction_info['key']

    transaction = dissoc(transaction_info, 'signed', 'key', 'unsigned')

    # validate r, in order to validate the transaction hash
    # There is some ambiguity about whether `r` will always be deterministically
    # generated from the transaction hash and private key, mostly due to code
    # author's ignorance. The example test fixtures and implementations seem to agree, so far.
    # See ecdsa_raw_sign() in /eth_keys/backends/native/ecdsa.py
    signed = acct.signTransaction(transaction, key)
    assert signed.r == Web3.toInt(hexstr=expected_raw_txn[-130:-66])

    # confirm that signed transaction can be recovered to the sender
    expected_sender = acct.privateKeyToAccount(key).address
    assert acct.recoverTransaction(signed.rawTransaction) == expected_sender
開發者ID:miohtama,項目名稱:web3.py,代碼行數:17,代碼來源:test_accounts.py

示例7: test_set_address

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,代碼行數:23,代碼來源:test_setup_address.py

示例8: test_setup_name

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,代碼行數:23,代碼來源:test_setup_name.py

示例9: check_gas_reserve

def check_gas_reserve(raiden):
    """ Check periodically for gas reserve in the account """
    while True:
        has_enough_balance, estimated_required_balance = gas_reserve.has_enough_gas_reserve(
            raiden,
            channels_to_open=0,
        )
        estimated_required_balance_eth = Web3.fromWei(estimated_required_balance, 'ether')

        if not has_enough_balance:
            log.info('Missing gas reserve', required_wei=estimated_required_balance)
            click.secho(
                (
                    'WARNING\n'
                    "Your account's balance is below the estimated gas reserve of "
                    f'{estimated_required_balance_eth} eth. This may lead to a loss of '
                    'of funds because your account will be unable to perform on-chain '
                    'transactions. Please add funds to your account as soon as possible.'
                ),
                fg='red',
            )

        gevent.sleep(CHECK_GAS_RESERVE_INTERVAL)
開發者ID:hackaugusto,項目名稱:raiden,代碼行數:23,代碼來源:tasks.py

示例10: getBalance

 def getBalance(self):
     wei_balance = self.web3.eth.getBalance(self.address)
     ether_balance = Web3.fromWei(wei_balance, unit='ether')
     return ether_balance
開發者ID:nud3l,項目名稱:agent-local,代碼行數:4,代碼來源:ContractHandler.py

示例11: test_to_text_hexstr

def test_to_text_hexstr(val, expected):
    assert Web3.toText(hexstr=val) == expected
開發者ID:miohtama,項目名稱:web3.py,代碼行數:2,代碼來源:test_conversions.py

示例12: test_to_text

def test_to_text(val, expected):
    assert Web3.toText(val) == expected
開發者ID:miohtama,項目名稱:web3.py,代碼行數:2,代碼來源:test_conversions.py

示例13: test_to_text_identity

def test_to_text_identity():
    assert Web3.toText(text='pass-through') == 'pass-through'
開發者ID:miohtama,項目名稱:web3.py,代碼行數:2,代碼來源:test_conversions.py

示例14: test_sha3_primitive_invalid

def test_sha3_primitive_invalid(primitive, exception):
    with pytest.raises(exception):
        Web3.sha3(primitive)
開發者ID:syngraph,項目名稱:web3.py,代碼行數:3,代碼來源:test_sha3.py

示例15: test_sha3_primitive

def test_sha3_primitive(primitive, digest):
    assert Web3.sha3(primitive) == digest
開發者ID:syngraph,項目名稱:web3.py,代碼行數:2,代碼來源:test_sha3.py


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